/* ==========================================================================
   Hatchiko API - shared theme
   Teal palette, fluid layout, light + dark mode (dark is the default).
   Every colour is a token on :root so the two themes stay in sync.
   ========================================================================== */

/* --- Dark theme (default) ------------------------------------------------ */
:root {
    color-scheme: dark;

    --teal-300: #5eead4;
    --teal-400: #2dd4bf;
    --teal-500: #14b8a6;
    --teal-600: #0d9488;
    --teal-700: #0f766e;

    --bg:            #06211f;
    --bg-accent:     #072b28;
    --surface:       rgba(17, 46, 44, 0.82);
    --surface-solid: #0e2b29;
    --surface-2:     rgba(20, 184, 166, 0.07);
    --surface-hover: rgba(45, 212, 191, 0.10);
    --border:        rgba(45, 212, 191, 0.18);
    --border-strong: rgba(45, 212, 191, 0.32);

    --text:        #e6fffb;
    --text-muted:  #9ec9c3;
    --text-faint:  #6f9b96;

    --accent:        var(--teal-400);
    --accent-strong: var(--teal-300);
    --accent-ink:    #04201d;
    --accent-soft:   rgba(45, 212, 191, 0.14);

    --success:      #34d399;
    --success-soft: rgba(52, 211, 153, 0.15);
    --warning:      #fbbf24;
    --warning-soft: rgba(251, 191, 36, 0.15);
    --danger:       #f87171;
    --danger-soft:  rgba(248, 113, 113, 0.15);
    --info:         #38bdf8;
    --info-soft:    rgba(56, 189, 248, 0.15);

    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
    --shadow:    0 8px 28px rgba(0, 0, 0, 0.42);
    --shadow-lg: 0 24px 60px rgba(0, 0, 0, 0.55);

    --radius-sm: 8px;
    --radius:    14px;
    --radius-lg: 20px;

    /* Fluid scale - these interpolate smoothly as the window resizes, so the
       layout keeps moving between breakpoints instead of jumping at them. */
    --gap:       clamp(0.75rem, 1.6vw, 1.5rem);
    --pad-page:  clamp(1rem, 2.6vw, 2.5rem);
    --pad-card:  clamp(1rem, 1.8vw, 1.75rem);
    --fs-body:   clamp(0.875rem, 0.82rem + 0.18vw, 0.97rem);
    --fs-small:  clamp(0.75rem, 0.72rem + 0.1vw, 0.82rem);
    --fs-h2:     clamp(1.35rem, 1.05rem + 1.1vw, 2rem);
    --fs-stat:   clamp(1.5rem, 1.1rem + 1.5vw, 2.25rem);

    --sidebar-w: clamp(13rem, 17vw, 17.5rem);
    --header-bg: linear-gradient(135deg, rgba(13, 148, 136, 0.22), rgba(45, 212, 191, 0.07));
    --cal-invert: 1;
}

/* --- Light theme --------------------------------------------------------- */
[data-theme="light"] {
    color-scheme: light;

    --bg:            #eef7f6;
    --bg-accent:     #ffffff;
    --surface:       rgba(255, 255, 255, 0.92);
    --surface-solid: #ffffff;
    --surface-2:     rgba(13, 148, 136, 0.05);
    --surface-hover: rgba(13, 148, 136, 0.08);
    --border:        rgba(13, 148, 136, 0.18);
    --border-strong: rgba(13, 148, 136, 0.34);

    --text:        #0b2f2c;
    --text-muted:  #4b6f6b;
    --text-faint:  #7d9a97;

    --accent:        var(--teal-600);
    --accent-strong: var(--teal-700);
    --accent-ink:    #ffffff;
    --accent-soft:   rgba(13, 148, 136, 0.12);

    --success:      #047857;
    --success-soft: rgba(4, 120, 87, 0.12);
    --warning:      #b45309;
    --warning-soft: rgba(180, 83, 9, 0.12);
    --danger:       #b91c1c;
    --danger-soft:  rgba(185, 28, 28, 0.12);
    --info:         #0369a1;
    --info-soft:    rgba(3, 105, 161, 0.12);

    --shadow-sm: 0 1px 2px rgba(6, 60, 56, 0.08);
    --shadow:    0 8px 24px rgba(6, 60, 56, 0.10);
    --shadow-lg: 0 24px 56px rgba(6, 60, 56, 0.16);

    --header-bg: linear-gradient(135deg, rgba(13, 148, 136, 0.12), rgba(45, 212, 191, 0.04));
    --cal-invert: 0;
}

/* --- Base ---------------------------------------------------------------- */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    font-size: var(--fs-body);
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    background-image:
        radial-gradient(1100px 620px at 8% -8%, var(--accent-soft), transparent 60%),
        radial-gradient(900px 540px at 108% 4%, var(--accent-soft), transparent 55%);
    background-attachment: fixed;
    min-height: 100vh;
    overflow-x: hidden;
    transition: background-color .25s ease, color .25s ease;
}

a { color: var(--accent); }
::placeholder { color: var(--text-faint); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* --- App shell ----------------------------------------------------------- */
.portal-container {
    display: grid;
    grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
    min-height: 100vh;
}

.sidebar {
    background: var(--surface);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-right: 1px solid var(--border);
    padding: clamp(1.25rem, 2vw, 2rem) 0;
    position: sticky;
    top: 0;
    align-self: start;
    height: 100vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    z-index: 120;
}

.logo { text-align: center; padding: 0 1.25rem; }
.logo h1 {
    color: var(--accent);
    font-size: clamp(1.15rem, 0.9rem + 0.7vw, 1.6rem);
    font-weight: 700;
    letter-spacing: -0.02em;
}
.logo p { color: var(--text-muted); font-size: var(--fs-small); margin-top: 0.2rem; }

.nav-menu { list-style: none; display: flex; flex-direction: column; gap: 0.2rem; padding: 0 0.7rem; }
.nav-item { list-style: none; }

.nav-link {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.7rem 0.85rem;
    color: var(--text-muted);
    text-decoration: none;
    border-radius: var(--radius-sm);
    font-weight: 500;
    cursor: pointer;
    border-left: 3px solid transparent;
    transition: background-color .18s ease, color .18s ease, border-color .18s ease;
}
.nav-link:hover, .nav-link.active {
    background: var(--surface-hover);
    color: var(--accent);
    border-left-color: var(--accent);
}
.nav-icon { font-size: 1.05rem; line-height: 1; flex-shrink: 0; }

.main-content {
    padding: var(--pad-page);
    display: flex;
    flex-direction: column;
    gap: var(--gap);
    min-width: 0;
}

/* --- Page header --------------------------------------------------------- */
.header {
    background: var(--surface);
    background-image: var(--header-bg);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--pad-card);
    box-shadow: var(--shadow);
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.6rem var(--gap);
}
.header h2 {
    color: var(--accent);
    font-size: var(--fs-h2);
    font-weight: 700;
    letter-spacing: -0.02em;
    flex: 1 1 14rem;
    min-width: 0;
}
.header p { color: var(--text-muted); flex: 1 1 100%; margin-top: -0.3rem; }

.db-info, .admin-badge {
    font-size: var(--fs-small);
    padding: 0.35rem 0.75rem;
    border-radius: 99px;
    border: 1px solid var(--border-strong);
    background: var(--accent-soft);
    color: var(--accent);
    font-weight: 600;
    white-space: nowrap;
}
.admin-badge { letter-spacing: 0.06em; }

.user-info {
    flex: 1 1 100%;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding-top: 0.85rem;
    border-top: 1px solid var(--border);
}
.user-details { color: var(--text-muted); font-size: var(--fs-small); }
.user-details strong { color: var(--text); }

.logout-btn {
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--danger);
    color: var(--danger);
    background: transparent;
    text-decoration: none;
    font-weight: 600;
    font-size: var(--fs-small);
    transition: background-color .18s ease, color .18s ease;
}
.logout-btn:hover { background: var(--danger); color: #fff; }

/* --- Stat cards ---------------------------------------------------------- */
.stats-grid, .stats-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 11rem), 1fr));
    gap: var(--gap);
}

.stat-card {
    background: var(--surface);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: var(--pad-card);
    box-shadow: var(--shadow);
    text-align: center;
    position: relative;
    overflow: hidden;
    transition: transform .18s ease, border-color .18s ease;
}
.stat-card::before {
    content: '';
    position: absolute;
    inset: 0 0 auto 0;
    height: 3px;
    background: linear-gradient(90deg, var(--teal-600), var(--teal-300));
}
.stat-card:hover { transform: translateY(-2px); border-color: var(--border-strong); }

.stat-value {
    font-size: var(--fs-stat);
    font-weight: 700;
    color: var(--accent);
    line-height: 1.15;
    word-break: break-word;
}
.stat-label {
    color: var(--text-muted);
    font-size: var(--fs-small);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-top: 0.3rem;
}
.loading { color: var(--text-faint); animation: pulse 1.5s ease-in-out infinite; }

/* --- Panels / sections --------------------------------------------------- */
.export-section, .controls, .search-controls,
.members-table, .transactions-table, .transfers-table, .transactions-container {
    background: var(--surface);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
}
.export-section, .controls, .search-controls { padding: var(--pad-card); }

.export-section h3 { color: var(--accent); margin-bottom: 0.35rem; }
.export-section p { color: var(--text-muted); margin-bottom: 1rem; }

.controls-row, .refresh-controls, .search-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: center;
}
.controls-row + .refresh-controls { margin-top: 0.75rem; }

/* --- Form controls ------------------------------------------------------- */
.form-group { margin-bottom: 1rem; }
.form-group label {
    display: block;
    margin-bottom: 0.4rem;
    color: var(--text-muted);
    font-size: var(--fs-small);
    font-weight: 600;
}

.form-control, .search-box, .filter-select, select, input[type="text"],
input[type="password"], input[type="number"], input[type="date"] {
    width: 100%;
    padding: 0.65rem 0.85rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: inherit;
    font-size: var(--fs-body);
    transition: border-color .18s ease, box-shadow .18s ease, background-color .18s ease;
}
.form-control:focus, .search-box:focus, .filter-select:focus,
select:focus, input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
    background: var(--bg-accent);
}
input[type="date"]::-webkit-calendar-picker-indicator {
    filter: invert(var(--cal-invert));
    cursor: pointer;
}

/* Search grows to fill the row; the selects stay compact but can shrink. */
.search-box  { flex: 3 1 14rem; min-width: 0; }
.filter-select { flex: 1 1 9rem; min-width: 0; cursor: pointer; }
.filter-select option, select option { background: var(--surface-solid); color: var(--text); }

.checkbox-group { display: flex; align-items: center; gap: 0.55rem; margin: 0.85rem 0; }
.checkbox-group input[type="checkbox"] { width: 1.05rem; height: 1.05rem; accent-color: var(--accent); cursor: pointer; }
.checkbox-group label { margin: 0; color: var(--text); cursor: pointer; font-weight: 500; }

.date-info { margin-top: 0.5rem; }
.date-info small { color: var(--text-muted) !important; font-size: var(--fs-small); }

/* --- Buttons ------------------------------------------------------------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    padding: 0.65rem 1.15rem;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: var(--fs-body);
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    text-decoration: none;
    background: var(--surface-2);
    color: var(--text);
    transition: transform .14s ease, box-shadow .18s ease, background-color .18s ease, opacity .18s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }

.btn-primary {
    background: linear-gradient(135deg, var(--teal-600), var(--teal-400));
    color: var(--accent-ink);
    box-shadow: 0 4px 14px var(--accent-soft);
}
.btn-primary:hover { box-shadow: 0 8px 22px var(--accent-soft); }

.btn-secondary { background: var(--surface-2); color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover { background: var(--surface-hover); }

.btn-success { background: var(--success); color: var(--accent-ink); }
.btn-warning { background: var(--warning); color: #231a02; }
.btn-danger  { background: var(--danger);  color: #fff; }
.btn-danger:hover { filter: brightness(1.08); }

.btn-small { padding: 0.4rem 0.7rem; font-size: var(--fs-small); }

.action-buttons { display: flex; flex-wrap: wrap; gap: 0.4rem; }

/* --- Tables -------------------------------------------------------------- */
.table-header {
    padding: var(--pad-card);
    border-bottom: 1px solid var(--border);
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}
.table-header h3 { color: var(--accent); font-size: 1.05rem; }
.table-header p  { color: var(--text-muted); font-size: var(--fs-small); flex: 1 1 100%; }
.last-update { color: var(--text-muted); font-size: var(--fs-small); }

.table-scroll { overflow-x: auto; width: 100%; }

table { width: 100%; border-collapse: collapse; font-size: var(--fs-small); }

th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--surface-solid);
    color: var(--accent);
    text-align: left;
    font-weight: 700;
    font-size: var(--fs-small);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    white-space: nowrap;
    border-bottom: 1px solid var(--border-strong);
}
th, td { padding: 0.7rem 0.85rem; }
td { border-bottom: 1px solid var(--border); color: var(--text); vertical-align: middle; }
tbody tr { transition: background-color .14s ease; }
tr:hover { background: var(--surface-hover); }
tbody tr:last-child td { border-bottom: none; }

.transaction-id {
    font-family: ui-monospace, 'Cascadia Code', Consolas, monospace;
    font-size: 0.78em;
    color: var(--text-muted);
}

.amount-positive { color: var(--success); font-weight: 600; }
.amount-negative { color: var(--danger);  font-weight: 600; }
.wallet-balance  { color: var(--accent);  font-weight: 700; }
.api-balance     { color: var(--info);    font-weight: 600; }
.sales-amount    { font-weight: 600; }
.sales-today     { color: var(--success); }
.sales-yesterday { color: var(--text-muted); }

/* --- Badges -------------------------------------------------------------- */
.status-badge, .action-badge, .sms-status {
    display: inline-block;
    padding: 0.22rem 0.6rem;
    border-radius: 99px;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    white-space: nowrap;
    border: 1px solid transparent;
}
.status-success, .status-active, .action-add, .sms-sent {
    background: var(--success-soft); color: var(--success); border-color: var(--success);
}
.status-failed, .status-inactive, .action-deduct, .sms-failed {
    background: var(--danger-soft); color: var(--danger); border-color: var(--danger);
}
.sms-not-sent { background: var(--surface-2); color: var(--text-muted); border-color: var(--border-strong); }

/* --- Alerts -------------------------------------------------------------- */
.alert {
    padding: 0.75rem 1rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1rem;
    font-size: var(--fs-small);
    border: 1px solid transparent;
}
.error-message, .success-message {
    padding: 0.75rem 1rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1rem;
    font-size: var(--fs-small);
    border: 1px solid transparent;
}
.alert-success, .success-message { background: var(--success-soft); color: var(--success); border-color: var(--success); }
.alert-error, .error-message     { background: var(--danger-soft);  color: var(--danger);  border-color: var(--danger); }

.sms-info {
    padding: 0.6rem 0.85rem;
    border-radius: var(--radius-sm);
    font-size: var(--fs-small);
    background: var(--accent-soft);
    color: var(--accent);
}
.sms-info-error { background: var(--danger-soft); color: var(--danger); }

.no-results, .no-data {
    text-align: center;
    padding: clamp(1.5rem, 4vw, 3rem) 1rem !important;
    color: var(--text-muted);
}
.no-results h3 { color: var(--text); margin-bottom: 0.4rem; }

/* --- Pagination ---------------------------------------------------------- */
.pagination {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0;
}
.pagination button {
    padding: 0.55rem 1.1rem;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font-family: inherit;
    font-size: var(--fs-small);
    font-weight: 600;
    cursor: pointer;
    transition: background-color .18s ease, color .18s ease;
}
.pagination button:hover:not(:disabled) { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.pagination button:disabled { opacity: 0.45; cursor: not-allowed; }
.pagination .current-page, .pagination span { color: var(--text-muted); font-size: var(--fs-small); font-weight: 600; }

/* --- Modals -------------------------------------------------------------- */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 2000;
    background: rgba(2, 16, 15, 0.72);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    padding: clamp(0.75rem, 3vw, 2rem);
    overflow-y: auto;
}
/* The pages toggle these with style.display = 'block'. */
.modal[style*="block"] { display: flex !important; align-items: flex-start; justify-content: center; }

.modal-content {
    background: var(--surface-solid);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: var(--pad-card);
    width: min(100%, 34rem);
    margin: auto;
    animation: modal-in .2s ease;
}
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
    padding-bottom: 0.85rem;
    border-bottom: 1px solid var(--border);
}
.modal-header h3 { color: var(--accent); font-size: 1.05rem; min-width: 0; }

.close {
    color: var(--text-muted);
    font-size: 1.6rem;
    line-height: 1;
    font-weight: 300;
    cursor: pointer;
    background: none;
    border: none;
    padding: 0 0.25rem;
    transition: color .18s ease;
}
.close:hover { color: var(--danger); }

@keyframes modal-in { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: none; } }

/* --- Realtime widgets ---------------------------------------------------- */
.realtime-indicator {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.3rem 0.75rem;
    border-radius: 99px;
    background: var(--success-soft);
    border: 1px solid var(--success);
    color: var(--success);
    font-size: var(--fs-small);
    font-weight: 700;
    letter-spacing: 0.05em;
    white-space: nowrap;
}
.live-dot {
    width: 7px; height: 7px;
    border-radius: 50%;
    background: currentColor;
    animation: pulse 1.6s ease-in-out infinite;
    flex-shrink: 0;
}

/* Connection states: live_feed.php replaces the label's class on each change.
   The pill follows the label so the whole chip reads as one state, not just
   its text. Browsers without :has() keep the default green pill. */
.status-live       { color: var(--success); }
.status-paused     { color: var(--text-muted); }
.status-background { color: var(--info); }
.status-warning    { color: var(--warning); }
.status-error      { color: var(--danger); }

.realtime-indicator:has(.status-paused) {
    color: var(--text-muted); border-color: var(--border-strong); background: var(--surface-2);
}
.realtime-indicator:has(.status-background) {
    color: var(--info); border-color: var(--info); background: var(--info-soft);
}
.realtime-indicator:has(.status-warning) {
    color: var(--warning); border-color: var(--warning); background: var(--warning-soft);
}
.realtime-indicator:has(.status-error) {
    color: var(--danger); border-color: var(--danger); background: var(--danger-soft);
}
/* A stopped or failed feed should not keep pulsing as though it were live. */
.realtime-indicator:has(.status-paused) .live-dot,
.realtime-indicator:has(.status-error) .live-dot { animation: none; }

.toggle-switch {
    width: 42px; height: 23px;
    border-radius: 99px;
    background: var(--border-strong);
    position: relative;
    cursor: pointer;
    flex-shrink: 0;
    transition: background-color .22s ease;
}
.toggle-switch.active { background: var(--accent); }
.toggle-slider {
    position: absolute;
    top: 3px; left: 3px;
    width: 17px; height: 17px;
    border-radius: 50%;
    background: #fff;
    box-shadow: var(--shadow-sm);
    transition: transform .22s ease;
}
.toggle-switch.active .toggle-slider { transform: translateX(19px); }

.auto-refresh-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-size: var(--fs-small);
    color: var(--text-muted);
    white-space: nowrap;
}

.new-transaction { animation: highlight 2.6s ease-out; }
@keyframes highlight {
    0%   { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
    100% { background: transparent; box-shadow: inset 3px 0 0 transparent; }
}

.alert-banner {
    padding: 0.7rem 1rem;
    border-radius: var(--radius-sm);
    background: var(--accent-soft);
    border: 1px solid var(--accent);
    color: var(--accent);
    font-weight: 600;
    font-size: var(--fs-small);
    text-align: center;
}

/* --- Spinner ------------------------------------------------------------- */
.loading-spinner {
    display: inline-block;
    width: 15px; height: 15px;
    border: 2px solid var(--border-strong);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    vertical-align: -2px;
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.45; } }

/* --- Theme toggle + mobile nav button ------------------------------------ */
.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.3rem; height: 2.3rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-strong);
    background: var(--surface-2);
    color: var(--text);
    font-size: 1.05rem;
    line-height: 1;
    cursor: pointer;
    flex-shrink: 0;
    transition: background-color .18s ease, color .18s ease, transform .14s ease;
}
.icon-btn:hover { background: var(--accent-soft); color: var(--accent); transform: translateY(-1px); }

.sidebar-toggle { display: none; }
.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 110;
    background: rgba(2, 16, 15, 0.6);
    backdrop-filter: blur(2px);
}
.sidebar-backdrop.show { display: block; }

.theme-toggle .theme-icon-dark  { display: none; }
[data-theme="light"] .theme-toggle .theme-icon-dark  { display: inline; }
[data-theme="light"] .theme-toggle .theme-icon-light { display: none; }

/* --- Responsive ---------------------------------------------------------- */
@media (max-width: 1024px) {
    .portal-container { grid-template-columns: minmax(0, 1fr); }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        width: min(17rem, 82vw);
        height: 100dvh;
        transform: translateX(-100%);
        transition: transform .26s ease;
        box-shadow: var(--shadow-lg);
    }
    .sidebar.open { transform: translateX(0); }

    .sidebar-toggle { display: inline-flex; }
}

@media (max-width: 640px) {
    .header { border-radius: var(--radius); }
    .user-info { flex-direction: column; align-items: stretch; }
    .logout-btn { text-align: center; }
    .controls-row > .btn, .refresh-controls > .btn { flex: 1 1 8rem; }
    .search-box, .filter-select { flex: 1 1 100%; }
    th, td { padding: 0.6rem 0.65rem; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

@media print {
    .sidebar, .controls, .pagination, .theme-toggle, .sidebar-toggle { display: none !important; }
    body { background: #fff; }
}
