/* ── Ardi — Global Styles ─────────────────────────────────────────────────── */

:root {
    /* Brand palette derived from the Ardi logo: deep teal-charcoal text + three-tone leaf */
    --navy:      #001D21;   /* Arabic logotype — deep midnight teal */
    --navy-dark: #000F11;   /* darker step for hover/active sidebar */
    --navy-mid:  #0E3437;   /* sidebar mid + section accents */
    --accent:    #02814D;   /* leaf middle band — primary brand action */
    --accent-dk: #066238;   /* accent hover */
    --accent-lt: #E6F4EC;   /* accent tint for badges / soft backgrounds */
    --leaf:      #77BD65;   /* outer leaf highlight — celebratory accent */
    --leaf-dk:   #4FA63E;   /* leaf hover */
    --light:     #F4F7F2;   /* warm paper page bg */
    --white:     #ffffff;
    --text:      #0F2A2A;   /* teal-shifted body text */
    --text-muted:#5C7878;   /* warm muted */
    --border:    #D4DED7;   /* warm sage border */
    --success:   #3FA85C;   /* tuned to the leaf greens */
    --success-lt:#EAF7EC;
    --error:     #C62828;
    --error-lt:  #fdecea;
    --warning:   #E65100;
    --warning-lt:#fff3e0;
    --sidebar-w: 240px;
    --topbar-h:  56px;
    --radius:    8px;
    --shadow:    0 2px 8px rgba(0,29,33,.10);
    --shadow-md: 0 4px 16px rgba(0,29,33,.13);
}

*, *::before, *::after { box-sizing: border-box; }

html { font-size: 16px; }

body {
    margin: 0;
    font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
    background: var(--light);
    color: var(--text);
    line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── App layout ─────────────────────────────────────────────────────────────── */
.app-wrapper {
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
    min-height: 100vh;
}

/* ── Sidebar ────────────────────────────────────────────────────────────────── */
.sidebar {
    /* Subtle vertical gradient from deepest teal at the top, easing into the
       brand-mid teal at the bottom — gives the rail quiet depth without noise. */
    background: linear-gradient(180deg,
        var(--navy-dark) 0%,
        var(--navy)      55%,
        var(--navy-mid)  100%);
    box-shadow: inset -1px 0 0 rgba(119, 189, 101, .12),  /* whisper of leaf green at the seam */
                2px 0 24px -8px rgba(0, 0, 0, .25);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    z-index: 100;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 20px 18px 18px;
    border-bottom: 1px solid rgba(255,255,255,.08);
}

.brand-icon { font-size: 1.4rem; color: var(--accent); }
.brand-name { font-size: 1.15rem; font-weight: 700; color: var(--white); letter-spacing: .02em; }
.sidebar-brand-img {
    width: 36px;
    height: 36px;
    object-fit: contain;
    background: var(--white);
    border-radius: 8px;
    padding: 4px;
    flex-shrink: 0;
}

.sidebar-nav { flex: 1; padding: 12px 0; }

.nav-section { margin-bottom: 4px; }

.nav-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 18px 4px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .07em;
    color: rgba(255,255,255,.35);
    cursor: pointer;
    user-select: none;
    transition: color .15s;
}
.nav-label:hover { color: rgba(255,255,255,.7); }
.nav-label::after {
    content: '';
    width: 8px;
    height: 8px;
    border-right: 1.5px solid currentColor;
    border-bottom: 1.5px solid currentColor;
    transform: rotate(45deg);
    margin-right: 4px;
    transition: transform .2s;
}
.nav-section.collapsed .nav-label::after { transform: rotate(-45deg); }
.nav-section.collapsed .nav-link { display: none; }

.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 18px;
    color: rgba(255,255,255,.75);
    font-size: 0.875rem;
    font-weight: 500;
    transition: background .15s, color .15s;
    border-radius: 0;
    position: relative;
}

.nav-link:hover { background: rgba(119, 189, 101, .08); color: var(--white); text-decoration: none; }
.nav-link.active { background: rgba(2, 129, 77, .22); color: var(--white); }
.nav-link.active::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: linear-gradient(180deg, var(--leaf) 0%, var(--accent) 100%); }

.nav-link-sub { padding-left: 32px; font-size: 0.82rem; }

/* Sortable table headers */
.data-table.sortable th[data-sort] {
    cursor: pointer;
    user-select: none;
    position: relative;
    padding-right: 24px;
}
.data-table.sortable th[data-sort]:hover { color: var(--accent); }
.data-table.sortable th[data-sort]::after {
    content: '';
    position: absolute;
    right: 8px;
    top: 50%;
    margin-top: -7px;
    width: 0;
    height: 0;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 5px solid rgba(0,0,0,.2);
    border-bottom: 5px solid rgba(0,0,0,.2);
    border-top-width: 0;
    opacity: .45;
}
.data-table.sortable th.sort-asc::after {
    border-bottom: 5px solid var(--accent);
    border-top: 0;
    opacity: 1;
}
.data-table.sortable th.sort-desc::after {
    border-top: 5px solid var(--accent);
    border-bottom: 0;
    opacity: 1;
}

.nav-link.has-subs { padding-right: 36px; }
.nav-sub-toggle {
    position: absolute;
    right: 10px;
    top: 50%;
    width: 22px;
    height: 22px;
    margin-top: -11px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 0;
    color: rgba(255,255,255,.55);
    cursor: pointer;
    padding: 0;
    border-radius: 3px;
}
.nav-sub-toggle:hover { background: rgba(255,255,255,.1); color: #fff; }
.nav-sub-toggle::after {
    content: '';
    width: 6px;
    height: 6px;
    border-right: 1.5px solid currentColor;
    border-bottom: 1.5px solid currentColor;
    transform: rotate(45deg);
    margin-top: -2px;
    transition: transform .2s;
}
.nav-link.has-subs.subs-collapsed .nav-sub-toggle::after { transform: rotate(-45deg); }

.nav-icon { width: 18px; height: 18px; fill: currentColor; flex-shrink: 0; opacity: .8; }

.badge {
    margin-left: auto;
    background: var(--error);
    color: #fff;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 1px 6px;
    border-radius: 10px;
    min-width: 18px;
    text-align: center;
}

/* ── Sidebar user footer ────────────────────────────────────────────────────── */
.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    border-top: 1px solid rgba(255,255,255,.08);
}
.sidebar-user-link {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 0;
    text-decoration: none;
    border-radius: 6px;
    padding: 4px 6px;
    margin: -4px -6px;
    transition: background .15s;
}
.sidebar-user-link:hover { background: rgba(255,255,255,.08); text-decoration: none; }

.user-avatar {
    width: 32px; height: 32px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.85rem; font-weight: 700;
    flex-shrink: 0;
    overflow: hidden;
}
.user-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }

.user-info { flex: 1; min-width: 0; }
.user-name { display: block; font-size: 0.82rem; font-weight: 600; color: var(--white); truncate: ellipsis; white-space: nowrap; overflow: hidden; }
.user-role { display: block; font-size: 0.72rem; color: rgba(255,255,255,.45); }

.logout-btn { color: rgba(255,255,255,.45); display: flex; }
.logout-btn:hover { color: var(--white); text-decoration: none; }
.logout-btn svg { width: 18px; height: 18px; fill: currentColor; }

/* ── Main content area ──────────────────────────────────────────────────────── */
.main-content {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* ── Top bar ────────────────────────────────────────────────────────────────── */
.topbar {
    position: sticky; top: 0; z-index: 90;
    display: flex; align-items: center; gap: 16px;
    height: var(--topbar-h);
    padding: 0 24px;
    background: var(--white);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 1px 4px rgba(0,0,0,.05);
}

.sidebar-toggle {
    display: none;
    background: none; border: none; cursor: pointer; padding: 4px;
    color: var(--text);
}
.sidebar-toggle svg { width: 22px; height: 22px; fill: currentColor; }

.page-title { margin: 0; font-size: 1rem; font-weight: 600; flex: 1; }
.topbar-right { display: flex; align-items: center; gap: 12px; font-size: .85rem; color: var(--text-muted); }
.topbar-user { font-weight: 500; }

/* ── Content area ───────────────────────────────────────────────────────────── */
.content-area { padding: 24px; flex: 1; }

/* ── Section header ─────────────────────────────────────────────────────────── */
.section-header {
    display: flex; align-items: flex-start; justify-content: space-between;
    margin-bottom: 20px; gap: 16px; flex-wrap: wrap;
}
.section-title { margin: 0; font-size: 1.25rem; font-weight: 700; color: var(--navy); }
.section-desc { margin: 4px 0 0; font-size: 0.875rem; color: var(--text-muted); }

/* ── Cards ──────────────────────────────────────────────────────────────────── */
.card {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    margin-bottom: 20px;
    overflow: hidden;
}

.card-urgent { border-color: #f9a825; }

.card-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    background: #fafbfd;
}

.card-title { margin: 0; font-size: 0.95rem; font-weight: 600; }
.card-subtitle { font-size: 0.8rem; color: var(--text-muted); }
.card-header-actions { display: flex; align-items: center; gap: 8px; }

.card-body { padding: 20px; }

/* ── Stats cards ────────────────────────────────────────────────────────────── */
.stats-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}

.stat-card {
    background: var(--white);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    padding: 18px;
    display: flex;
    align-items: center;
    gap: 14px;
}

.stat-card-warning { border-color: #f9a825; background: #fffde7; }

.stat-icon {
    width: 44px; height: 44px; border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.stat-icon svg { width: 22px; height: 22px; fill: #fff; }
.stat-icon-blue   { background: var(--accent); }
.stat-icon-green  { background: var(--success); }
.stat-icon-orange { background: var(--warning); }
.stat-icon-purple { background: var(--navy-mid); }

.stat-body { min-width: 0; }
.stat-value { display: block; font-size: 1.6rem; font-weight: 700; line-height: 1.1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-label { display: block; font-size: 0.78rem; color: var(--text-muted); margin-top: 2px; }

/* ── Dashboard grid ─────────────────────────────────────────────────────────── */
.dashboard-grid { display: flex; flex-direction: column; gap: 0; }

.content-row {
    display: grid;
    grid-template-columns: 1fr 380px;
    gap: 20px;
    align-items: start;
}

/* ── Projects list ──────────────────────────────────────────────────────────── */
.project-list { display: flex; flex-direction: column; gap: 0; }
.project-item {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 0;
    border-bottom: 1px solid var(--border);
    gap: 16px;
}
.project-item:last-child { border-bottom: none; }
.project-info { flex: 1; min-width: 0; }
.project-name { margin: 0; font-size: 0.9rem; font-weight: 600; }
.project-desc { margin: 3px 0 0; font-size: 0.8rem; color: var(--text-muted); }
.project-actions { display: flex; gap: 8px; flex-shrink: 0; }

/* ── Activity feed ──────────────────────────────────────────────────────────── */
.activity-feed { list-style: none; margin: 0; padding: 0; }
.activity-item {
    display: flex; align-items: flex-start; gap: 10px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.84rem;
}
.activity-item:last-child { border-bottom: none; }
.activity-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex-shrink: 0; margin-top: 4px; }
.activity-text { flex: 1; }
.activity-action { font-weight: 600; }
.activity-detail { display: block; color: var(--text-muted); font-size: 0.8rem; }
.activity-time { font-size: 0.75rem; color: var(--text-muted); white-space: nowrap; }

/* ── Alerts ─────────────────────────────────────────────────────────────────── */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    font-size: 0.875rem;
    display: flex; align-items: center; gap: 8px;
}
.alert-error   { background: var(--error-lt); color: var(--error); border: 1px solid #f5c0c0; }
.alert-success { background: var(--success-lt); color: var(--success); border: 1px solid #b8e0bb; }
.alert-warning { background: var(--warning-lt); color: var(--warning); border: 1px solid #ffe0b2; }

/* ── Data tables ────────────────────────────────────────────────────────────── */
.data-table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.data-table th {
    text-align: left; padding: 10px 12px;
    background: #f7f8fb;
    border-bottom: 2px solid var(--border);
    font-size: 0.78rem; font-weight: 600;
    text-transform: uppercase; letter-spacing: .04em;
    color: var(--text-muted);
    white-space: nowrap;
}
.data-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--accent-lt); }

.filename-cell { display: flex; align-items: center; gap: 8px; }
.file-icon { width: 18px; height: 18px; fill: var(--accent); flex-shrink: 0; }
.action-cell { display: flex; gap: 6px; flex-wrap: wrap; }

/* ── Badges ─────────────────────────────────────────────────────────────────── */
.role-badge, .status-badge, .count-badge, .badge-orange {
    display: inline-flex; align-items: center;
    padding: 2px 8px; border-radius: 12px;
    font-size: 0.72rem; font-weight: 600;
}
.role-admin   { background: #EAE3EE; color: #5C2E78; }
.role-ngo_user { background: var(--accent-lt); color: var(--accent-dk); }
.status-active      { background: var(--success-lt); color: var(--success); }
.status-pending     { background: var(--warning-lt); color: var(--warning); }
.status-deactivated { background: #f5f5f5; color: #9e9e9e; }
.count-badge { background: var(--accent-lt); color: var(--accent-dk); }
.count-warn  { background: #fde0dc; color: #c62828; }
.badge-orange { background: var(--warning-lt); color: var(--warning); }

/* ── Buttons ────────────────────────────────────────────────────────────────── */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 16px; border-radius: 6px;
    font-size: 0.875rem; font-weight: 600;
    border: 1.5px solid transparent;
    cursor: pointer; text-decoration: none;
    transition: background .15s, border-color .15s, color .15s;
    line-height: 1.4;
    white-space: nowrap;
}
.btn:hover { text-decoration: none; }

.btn-primary  { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover {
    background: var(--accent-dk);
    border-color: var(--accent-dk);
    color: #fff;
    box-shadow: 0 6px 16px -6px rgba(2, 129, 77, .55);  /* soft emerald lift */
}

.btn-outline  { background: transparent; color: var(--accent); border-color: var(--accent); }
.btn-outline:hover { background: var(--accent-lt); }

.btn-success  { background: var(--success); color: #fff; border-color: var(--success); }
.btn-success:hover { background: var(--accent); border-color: var(--accent); }

.btn-danger         { background: var(--error); color: #fff; border-color: var(--error); }
.btn-danger:hover   { background: #8b0000; }
.btn-danger-outline { background: transparent; color: var(--error); border-color: var(--error); }
.btn-danger-outline:hover { background: #fff0f0; }

.btn-sm   { padding: 5px 12px; font-size: 0.8rem; }
.btn-xs   { padding: 3px 8px;  font-size: 0.72rem; border-radius: 4px; }
.btn-block { width: 100%; justify-content: center; }

.btn-icon { width: 16px; height: 16px; fill: currentColor; }
.disabled { opacity: .5; pointer-events: none; }

/* ── Form controls ──────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-group label {
    display: block; font-size: 0.83rem; font-weight: 600;
    margin-bottom: 5px; color: var(--text);
}
.form-control {
    display: block; width: 100%;
    padding: 9px 12px;
    border: 1.5px solid var(--border);
    border-radius: 6px;
    font-size: 0.875rem;
    color: var(--text);
    background: var(--white);
    transition: border-color .15s, box-shadow .15s;
    outline: none;
}
.form-control:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(2, 129, 77, .15); }
.form-control-sm { padding: 5px 10px; font-size: 0.8rem; }
.form-hint { display: block; font-size: 0.75rem; color: var(--text-muted); margin-top: 4px; }
.required { color: var(--error); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }

.input-group { position: relative; display: flex; align-items: center; }
.input-group .form-control { padding-right: 42px; }
.input-toggle-pw {
    position: absolute; right: 8px;
    background: none; border: none; cursor: pointer; padding: 4px;
    color: var(--text-muted);
    display: flex; align-items: center;
}
.input-toggle-pw svg { width: 18px; height: 18px; fill: currentColor; }

.checkbox-label { display: flex; align-items: center; gap: 8px; font-size: 0.85rem; cursor: pointer; }

.form-row-2col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }

/* ── Survey cards ───────────────────────────────────────────────────────────── */
.survey-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.survey-card { background: var(--white); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; transition: box-shadow .2s, border-color .2s; }
.survey-card:hover { box-shadow: var(--shadow-md); border-color: var(--accent); }
.survey-card-configured { border-left: 3px solid var(--accent); }
.survey-card-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--border); background: #fafbfd; }
.survey-form-id { font-size: 0.85rem; font-weight: 700; color: var(--navy); }
.survey-form-name { margin: 0 0 4px; font-size: 1rem; font-weight: 700; color: var(--navy); }
.survey-form-desc { margin: 0 0 8px; font-size: 0.82rem; color: var(--text-muted); }
.survey-badges { display: flex; gap: 6px; align-items: center; }
.badge-configured { color: var(--accent); font-size: 1rem; }
.survey-card-body { padding: 14px 16px; flex: 1; }
.survey-card-footer { padding: 12px 16px; border-top: 1px solid var(--border); display: flex; gap: 8px; flex-wrap: wrap; }
.survey-meta { font-size: 0.82rem; color: var(--text-muted); margin: 4px 0; }
.survey-meta-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; margin-top: 10px; }
.survey-meta-item { }
.meta-label { display: block; font-size: 0.7rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); }
.meta-value { display: block; font-size: 0.82rem; font-weight: 600; color: var(--text); }

.sync-status { display: inline-flex; align-items: center; gap: 4px; font-size: 0.72rem; font-weight: 600; padding: 2px 8px; border-radius: 12px; }
.sync-status svg { width: 14px; height: 14px; fill: currentColor; }
.sync-ok { background: var(--success-lt); color: var(--success); }
.sync-missing { background: #f5f5f5; color: #9e9e9e; }

.header-actions { display: flex; gap: 8px; align-items: flex-start; flex-wrap: wrap; }

/* ── Breadcrumb ─────────────────────────────────────────────────────────────── */
.breadcrumb { font-size: 0.82rem; margin-bottom: 6px; color: var(--text-muted); }
.breadcrumb a { color: var(--accent); }
.breadcrumb a:hover { text-decoration: underline; }
.bc-sep { margin: 0 6px; color: var(--border); }

/* ── Tabs ───────────────────────────────────────────────────────────────────── */
.tabs { display: flex; gap: 0; border-bottom: 2px solid var(--border); margin-bottom: 20px; }
.tab-btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 10px 18px; border: none; background: none;
    font-size: 0.875rem; font-weight: 600;
    color: var(--text-muted); cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px; transition: color .15s, border-color .15s;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-icon { width: 16px; height: 16px; fill: currentColor; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Table extras ───────────────────────────────────────────────────────────── */
.table-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.table-card { overflow: hidden; }
.table-responsive { overflow-x: auto; }
.inline-form { display: inline; }
.row-muted td { opacity: .45; }

/* ── Field key + type badges ────────────────────────────────────────────────── */
.field-key { font-size: 0.78rem; background: var(--accent-lt); color: var(--accent-dk); padding: 1px 6px; border-radius: 3px; }
.field-key-small { font-size: 0.7rem; color: var(--text-muted); }
.type-badge { display: inline-block; font-size: 0.7rem; font-weight: 600; padding: 1px 7px; border-radius: 10px; background: #f1f3f7; color: var(--text-muted); text-transform: uppercase; letter-spacing: .03em; }
/* Field-type badges — varied to keep types visually distinct, but anchored on the brand palette */
.type-text, .type-textarea, .type-email, .type-url, .type-phone { background: #E3ECEC; color: #0E3437; }
.type-number, .type-scale, .type-star, .type-range { background: var(--accent-lt); color: var(--accent-dk); }
.type-radio, .type-select { background: #fff3e0; color: #e65100; }
.type-checkbox { background: #EAE3EE; color: #5C2E78; }
.type-date, .type-time { background: #DDEAE6; color: #0E3437; }
.type-likert { background: #fce4ec; color: #c62828; }

/* ── Entry detail ───────────────────────────────────────────────────────────── */
.entry-meta-bar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 20px; }
.meta-chip { display: inline-flex; align-items: center; gap: 5px; background: var(--white); border: 1px solid var(--border); border-radius: 20px; padding: 4px 12px; font-size: 0.82rem; }
.meta-chip-label { font-weight: 600; color: var(--text-muted); font-size: 0.72rem; text-transform: uppercase; }
.field-label { font-weight: 600; font-size: 0.875rem; }
.entry-value { max-width: 500px; word-break: break-word; }
.value-long .value-full.hidden { display: none; }
.json-pre { font-size: 0.78rem; max-height: 500px; overflow: auto; white-space: pre-wrap; word-break: break-all; background: #f7f8fb; padding: 16px; border-radius: var(--radius); }
.raw-json-section { margin-top: 16px; }

/* ── Entry edit form ────────────────────────────────────────────────────────── */
.entry-fields { display: flex; flex-direction: column; gap: 14px; }
.entry-field-row {
    display: grid;
    grid-template-columns: 260px 1fr;
    gap: 18px;
    align-items: start;
    padding: 14px 0;
    border-bottom: 1px solid var(--border);
}
.entry-field-row:last-child { border-bottom: none; }
.entry-field-label label { font-weight: 600; font-size: 0.9rem; display: block; margin-bottom: 4px; }
.entry-field-meta { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.entry-field-desc { font-size: 0.78rem; color: var(--text-muted); margin: 6px 0 0; }
.entry-field-input { min-width: 0; }
.entry-field-input .form-control { width: 100%; max-width: 520px; }
.entry-field-input textarea.form-control { min-height: 90px; }
.radio-inline, .checkbox-inline {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-right: 16px;
    margin-bottom: 6px;
    font-size: 0.88rem;
    cursor: pointer;
}
.radio-inline input, .checkbox-inline input { margin: 0; cursor: pointer; }
@media (max-width: 720px) {
    .entry-field-row { grid-template-columns: 1fr; gap: 8px; }
}

/* ── Stats section ──────────────────────────────────────────────────────────── */
.stats-form { margin-top: 12px; }
.stats-form-row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.stat-result { margin-top: 16px; }
.stat-result-card { background: var(--accent-lt); border: 1px solid var(--accent); border-radius: var(--radius); padding: 16px 20px; display: inline-flex; flex-direction: column; gap: 4px; }
.stat-result-label { font-size: 0.78rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; }
.stat-result-value { font-size: 2rem; font-weight: 700; color: var(--navy); }

/* ── Analytics ──────────────────────────────────────────────────────────────── */
.analytics-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 24px; gap: 16px; flex-wrap: wrap; }
.analytics-section { margin-bottom: 28px; }
.analytics-section-title { font-size: 1rem; font-weight: 700; color: var(--navy); margin: 0 0 14px; border-bottom: 2px solid var(--accent-lt); padding-bottom: 6px; }

.chart-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }
.chart-card { background: var(--white); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.chart-card h4 { margin: 0 0 14px; font-size: 0.875rem; font-weight: 600; color: var(--text-muted); }
.chart-card-wide { grid-column: 1 / -1; }

.metric-row { display: flex; gap: 24px; flex-wrap: wrap; padding: 8px 0; }
.metric-box { text-align: center; }
.metric-val { display: block; font-size: 1.8rem; font-weight: 700; color: var(--navy); }
.metric-lbl { display: block; font-size: 0.78rem; color: var(--text-muted); margin-top: 4px; }

.confidence-gauge { text-align: center; padding: 10px 0; }
.gauge-value { font-size: 3rem; font-weight: 700; color: var(--navy); }
.gauge-max { font-size: 1.2rem; color: var(--text-muted); }
.gauge-bar { height: 10px; background: var(--border); border-radius: 5px; margin: 12px 0 8px; }
.gauge-fill { height: 100%; background: var(--accent); border-radius: 5px; transition: width .5s; }
.gauge-label { font-size: 0.8rem; color: var(--text-muted); }

/* ── Upload / Document hub ──────────────────────────────────────────────────── */
.drop-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 32px 24px;
    text-align: center;
    cursor: pointer;
    transition: border-color .15s, background .15s;
}
.drop-zone.drag-over { border-color: var(--accent); background: var(--accent-lt); }
.drop-icon { width: 40px; height: 40px; fill: var(--text-muted); }
.drop-text { margin: 8px 0 4px; font-size: 0.9rem; color: var(--text-muted); }
.drop-label { color: var(--accent); cursor: pointer; font-weight: 600; }
.drop-label:hover { text-decoration: underline; }
.drop-hint { font-size: 0.78rem; color: var(--text-muted); margin: 0; }

.upload-progress { margin-top: 16px; }
.progress-bar { height: 8px; background: var(--border); border-radius: 4px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--accent); width: 0%; transition: width .2s; }
.hidden { display: none !important; }

/* ── Pagination ─────────────────────────────────────────────────────────────── */
.pagination { display: flex; gap: 6px; margin-top: 16px; justify-content: center; }
.page-btn {
    padding: 5px 11px; border-radius: 5px;
    border: 1.5px solid var(--border);
    color: var(--text); font-size: 0.85rem; font-weight: 500;
    text-decoration: none;
}
.page-btn:hover { background: var(--accent-lt); border-color: var(--accent); }
.page-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ── Misc ───────────────────────────────────────────────────────────────────── */
.muted { color: var(--text-muted); font-size: 0.82rem; }
.empty-state { text-align: center; color: var(--text-muted); font-size: 0.9rem; padding: 24px 0; }
code { background: #f1f3f7; padding: 1px 5px; border-radius: 3px; font-size: .875em; }

/* Toast notifications */
#toast-container {
    position: fixed; bottom: 24px; right: 24px; z-index: 9999;
    display: flex; flex-direction: column; gap: 10px;
}
.toast {
    min-width: 240px; max-width: 360px;
    padding: 12px 16px; border-radius: var(--radius);
    font-size: 0.875rem; font-weight: 500;
    box-shadow: var(--shadow-md);
    animation: slideIn .25s ease;
}
.toast-success { background: var(--success); color: #fff; }
.toast-error   { background: var(--error); color: #fff; }
.toast-info    { background: var(--accent); color: #fff; }
@keyframes slideIn { from { transform: translateX(30px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* Loading spinner */
.spinner {
    width: 20px; height: 20px;
    border: 2px solid rgba(255,255,255,.4);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin .6s linear infinite;
    display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Responsive ─────────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
    .app-wrapper { grid-template-columns: 1fr; }
    .sidebar {
        position: fixed; left: 0; top: 0; bottom: 0; width: var(--sidebar-w);
        transform: translateX(-100%); transition: transform .25s;
    }
    .sidebar.open { transform: translateX(0); }
    .sidebar-toggle { display: flex; }
    .main-content { grid-column: 1; }
    .content-row { grid-template-columns: 1fr; }
    .form-row-2col { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
    .stats-row { grid-template-columns: 1fr 1fr; }
    .content-area { padding: 16px; }
    .data-table { font-size: 0.78rem; }
    .data-table th, .data-table td { padding: 7px 8px; }
}

/* ── Assignment Badge ───────────────────────────────────────────────────────── */
.assign-count-badge {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    background: var(--accent-lt);
    color: var(--accent);
    font-size: 0.75rem;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 12px;
}
.assign-count-badge .badge-icon {
    width: 14px;
    height: 14px;
    fill: var(--accent);
}

.btn-assign {
    border-color: var(--accent) !important;
    color: var(--accent) !important;
}
.btn-assign:hover {
    background: var(--accent) !important;
    color: var(--white) !important;
}
.btn-assign:hover .btn-icon { fill: var(--white); }

/* ── Modal ──────────────────────────────────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(0, 29, 33, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    animation: fadeIn 0.15s ease;
}
/* The HTML hidden attribute must win over the display:flex above. */
.modal-overlay[hidden] { display: none; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal-dialog {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    width: 100%;
    max-width: 480px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    animation: slideUp 0.2s ease;
}
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}
.modal-title { font-size: 1.1rem; font-weight: 600; color: var(--navy); margin: 0; }
.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-muted);
    cursor: pointer;
    line-height: 1;
    padding: 0 4px;
}
.modal-close:hover { color: var(--error); }

.modal-body {
    padding: 16px 20px;
    overflow-y: auto;
    flex: 1;
}
.modal-subtitle {
    font-weight: 600;
    color: var(--accent);
    margin: 0 0 4px;
}
.modal-hint {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin: 0 0 12px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 20px;
    border-top: 1px solid var(--border);
}

/* Lock background scroll while a modal is open */
body.modal-open { overflow: hidden; }

/* Rename modal specifics */
.rename-modal-label {
    display: block;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .04em;
    margin-bottom: 6px;
}
.rename-modal-input {
    width: 100%;
    font-size: 0.95rem;
}
.rename-modal-error {
    margin: 8px 0 0;
    font-size: 0.82rem;
    color: var(--error);
    background: var(--error-lt);
    border-left: 3px solid var(--error);
    padding: 6px 10px;
    border-radius: 4px;
}
.rename-modal-orig {
    margin: 14px 0 0;
    font-size: 0.8rem;
    color: var(--text-muted);
    display: flex;
    gap: 6px;
    align-items: baseline;
    flex-wrap: wrap;
}
.rename-modal-orig-label {
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    font-size: 0.7rem;
}
.rename-modal-orig-value {
    color: var(--navy);
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    word-break: break-all;
}

/* ── Assign User List ───────────────────────────────────────────────────────── */
.assign-user-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 300px;
    overflow-y: auto;
}
.assign-user-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}
.assign-user-item:hover {
    background: var(--light);
    border-color: var(--accent);
}
.assign-user-item:has(.assign-checkbox:checked) {
    background: var(--accent-lt);
    border-color: var(--accent);
}
.assign-checkbox {
    width: 18px;
    height: 18px;
    accent-color: var(--accent);
    flex-shrink: 0;
}
.assign-user-info {
    display: flex;
    flex-direction: column;
    gap: 1px;
    min-width: 0;
}
.assign-user-name {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text);
}
.assign-user-org {
    font-size: 0.78rem;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ── Assignments tab ────────────────────────────────────────────────────────── */
.assignment-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 10px;
    margin-top: 8px;
}
.assignment-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: background .15s;
}
.assignment-row:hover { background: var(--light); }
.assignment-row input[type="checkbox"] { margin: 0; flex-shrink: 0; }
.assignment-user { min-width: 0; }
.assignment-name { font-weight: 600; font-size: 0.9rem; }
.assignment-email { font-size: 0.78rem; }

/* ── Locations tab ──────────────────────────────────────────────────────────── */
.loc-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 14px;
}
.loc-card {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
}
.loc-head {
    display: flex; justify-content: space-between; align-items: baseline;
    margin-bottom: 6px;
}
.loc-name  { font-weight: 600; font-size: 0.95rem; }
.loc-count { font-size: 1.3rem; font-weight: 700; color: var(--navy); }
.loc-bar { height: 6px; background: var(--light); border-radius: 3px; overflow: hidden; }
.loc-bar-fill { height: 100%; background: var(--accent); border-radius: 3px; }
.loc-pct { font-size: 0.78rem; color: var(--text-muted); margin: 4px 0 8px; }
.loc-villages { list-style: none; padding: 0; margin: 6px 0 0; font-size: 0.82rem; }
.loc-villages li {
    display: flex; justify-content: space-between; gap: 8px;
    padding: 2px 0;
    border-top: 1px dashed var(--border);
}
.loc-villages li:first-child { border-top: none; }

/* ── Field Completion tab ───────────────────────────────────────────────────── */
.completion-list { display: flex; flex-direction: column; gap: 6px; }
.completion-row {
    display: grid;
    grid-template-columns: 260px 1fr 120px;
    gap: 12px;
    align-items: center;
    padding: 6px 0;
}
.completion-label {
    display: flex; align-items: center; gap: 8px; min-width: 0;
}
.completion-name {
    font-size: 0.88rem; font-weight: 500;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.completion-bar-wrap {
    position: relative;
    height: 10px;
    background: var(--light);
    border-radius: 5px;
    overflow: hidden;
}
.completion-bar {
    height: 100%;
    border-radius: 5px;
    transition: width .35s ease;
}
.completion-high .completion-bar { background: var(--success); }
.completion-mid  .completion-bar { background: var(--warning); }
.completion-low  .completion-bar { background: var(--error); }
.completion-stats { font-size: 0.82rem; text-align: right; }
.completion-stats strong { font-weight: 700; }
@media (max-width: 640px) {
    .completion-row { grid-template-columns: 1fr; gap: 4px; }
    .completion-stats { text-align: left; }
}

/* ── Duplicates tab ─────────────────────────────────────────────────────────── */
.duplicate-group {
    border: 1px solid var(--border);
    border-left: 4px solid #C62828;
    border-radius: var(--radius);
    padding: 12px 14px;
    margin-bottom: 12px;
    background: #fff9f8;
}
.duplicate-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    gap: 10px;
    flex-wrap: wrap;
}
.duplicate-table { background: var(--white); }

/* ── Activity tab ───────────────────────────────────────────────────────────── */
.action-badge {
    display: inline-block;
    font-size: 0.72rem; font-weight: 600;
    padding: 2px 8px;
    border-radius: 10px;
    background: var(--light); color: var(--text-muted);
    font-family: monospace;
}
.action-entryupdate, .action-entry_update { background: #E3ECEC; color: #0E3437; }
.action-entrydelete, .action-entry_delete { background: #fde0dc; color: #c62828; }
.action-entrycreate, .action-entry_create { background: var(--accent-lt); color: var(--accent-dk); }
.action-surveysync,  .action-survey_sync  { background: #fff3e0; color: #E65100; }
.action-surveyassign,.action-survey_assign{ background: #E3ECEC; color: var(--navy); }
