@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');
@import url('https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.0/css/all.min.css');

:root {
    --bg: #0f0f1a;
    --bg2: #13131f;
    --card: #1a1a2e;
    --card2: #1e1e35;
    --border: rgba(255,255,255,0.07);
    --border-hover: rgba(255,255,255,0.14);
    --text: #e8e8f0;
    --text-muted: #6b7280;
    --accent: #a78bfa;
    --accent2: #818cf8;
    --green: #34d399;
    --green-dim: rgba(52,211,153,0.12);
    --yellow: #fbbf24;
    --pink: #f472b6;
    --pink2: #ec4899;
    --danger: #f87171;
    --danger-dim: rgba(248,113,113,0.12);
    --info: #60a5fa;
    --radius: 18px;
    --radius-sm: 12px;
    --radius-xs: 8px;
    --touch: 48px;
    --shadow: 0 20px 60px rgba(0,0,0,0.4);
    --shadow-sm: 0 8px 24px rgba(0,0,0,0.25);
    --shadow-glow: 0 0 30px rgba(167,139,250,0.15);
    --content-max: 1000px;
    --nav-h: 64px;
    --bottom-nav-h: 72px;
    --transition: 0.2s cubic-bezier(0.4,0,0.2,1);
    color-scheme: dark;
}

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

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

html,body { margin: 0; padding: 0; }

body {
    font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    background-image:
        radial-gradient(ellipse 80% 50% at 20% -10%, rgba(167,139,250,0.08) 0%, transparent 60%),
        radial-gradient(ellipse 60% 40% at 80% 100%, rgba(244,114,182,0.06) 0%, transparent 50%);
    color: var(--text);
    min-height: 100vh;
    min-height: 100dvh;
    line-height: 1.5;
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
}

.app {
    max-width: var(--content-max);
    margin: 0 auto;
    padding: max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 28px max(16px, env(safe-area-inset-left));
}

body.logged-in {
    padding-bottom: calc(var(--bottom-nav-h) + 8px + env(safe-area-inset-bottom));
}

/* ——— Skip link ——— */
.skip-link {
    position: absolute;
    left: -9999px;
    top: 0;
    z-index: 10000;
    padding: 12px 16px;
    background: var(--accent);
    color: #0f0f1a;
    font-weight: 700;
    border-radius: 0 0 8px 8px;
}
.skip-link:focus { left: 12px; }

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0,0,0,0);
    white-space: nowrap;
    border: 0;
}

/* ——— Topbar ——— */
.topbar {
    position: sticky;
    top: 0;
    z-index: 40;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 10px 0 14px;
    margin-bottom: 8px;
    background: linear-gradient(to bottom, rgba(15,15,26,0.97) 80%, transparent);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.topbar-row {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
    justify-content: space-between;
    width: 100%;
}

.brand {
    display: flex;
    gap: 12px;
    align-items: center;
    min-width: 0;
}

.brand-link {
    text-decoration: none;
    color: inherit;
    border-radius: 12px;
    padding: 4px 8px 4px 0;
    margin: -4px 0;
    transition: opacity var(--transition);
}
.brand-link:active { opacity: 0.8; }

.brand-icon {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--accent), var(--pink));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(167,139,250,0.3);
}

.brand strong {
    display: block;
    font-size: clamp(1rem, 2.5vw, 1.1rem);
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: min(220px, 55vw);
    letter-spacing: -0.01em;
}

.brand small {
    display: block;
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 500;
}

.nav-top {
    display: none;
    gap: 6px;
    flex-wrap: wrap;
    align-items: center;
}

.nav-top a,
.bottom-nav-link {
    color: var(--text);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.875rem;
    transition: all var(--transition);
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.nav-top a {
    padding: 9px 16px;
    border-radius: 999px;
    background: rgba(255,255,255,0.05);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 6px;
}

.nav-top a:hover {
    background: rgba(255,255,255,0.09);
    border-color: var(--border-hover);
}

.nav-top a.active,
.bottom-nav-link.active {
    background: rgba(167,139,250,0.18);
    border-color: rgba(167,139,250,0.35);
    color: #fff;
}

.nav-top a.muted { color: var(--text-muted); }

/* ——— Mobile tabs ——— */
.mobile-tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    width: 100%;
    padding: 4px 0 2px;
}

.mobile-tab {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: var(--touch);
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    text-decoration: none;
    color: var(--text);
    font-weight: 700;
    font-size: 0.9rem;
    background: rgba(255,255,255,0.05);
    border: 1px solid var(--border);
    touch-action: manipulation;
    cursor: pointer;
    transition: all var(--transition);
}

.mobile-tab-ico { font-size: 1rem; }

.mobile-tab.is-active {
    background: rgba(167,139,250,0.2);
    border-color: rgba(167,139,250,0.4);
    box-shadow: 0 0 16px rgba(167,139,250,0.15);
}

.mobile-tab:active { transform: scale(0.97); }

/* ——— Bottom nav ——— */
.bottom-nav {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 2147483640;
    display: flex;
    justify-content: space-around;
    align-items: stretch;
    min-height: var(--bottom-nav-h);
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    background: rgba(15,15,26,0.97);
    border-top: 1px solid rgba(255,255,255,0.1);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    box-shadow: 0 -12px 40px rgba(0,0,0,0.5);
}

.bottom-nav-link {
    position: relative;
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 8px 4px;
    min-height: 52px;
    border-radius: 12px;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    max-width: 140px;
    margin: 0 auto;
    color: var(--text-muted);
    transition: all var(--transition);
}

.bottom-nav-link.active { color: var(--accent); }

.bottom-nav-link.active::before {
    content: '';
    position: absolute;
    top: 4px;
    left: 25%; right: 25%;
    height: 3px;
    border-radius: 4px;
    background: var(--accent);
}

.bottom-nav-link .nav-ico {
    font-size: 1.25rem;
    line-height: 1;
}

.bottom-nav-link:active {
    transform: scale(0.93);
    background: rgba(255,255,255,0.05);
}

.bottom-nav-link-muted { opacity: 0.7; }

@media (min-width: 768px) {
    .nav-top { display: flex; }
    .mobile-tabs { display: none; }
    .bottom-nav { display: none !important; }
    body.logged-in { padding-bottom: 0; }
    .app { padding-bottom: 36px; }
}

@media (min-width: 1024px) {
    .app { padding-left: 24px; padding-right: 24px; }
    .stats { grid-template-columns: repeat(3, 1fr); }
    .extract-layout {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 18px;
        align-items: start;
    }
}

/* ——— Cards ——— */
.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: clamp(18px, 3vw, 26px);
    margin-bottom: 16px;
    box-shadow: var(--shadow-sm);
    transition: border-color var(--transition), box-shadow var(--transition);
}

.card:hover { border-color: var(--border-hover); }

.card-accent {
    border-color: rgba(167,139,250,0.2);
    background: linear-gradient(145deg, rgba(26,26,46,1) 0%, rgba(22,22,40,1) 100%);
    box-shadow: var(--shadow-sm), 0 0 0 1px rgba(167,139,250,0.05) inset;
    position: relative;
    overflow: hidden;
}

.card-accent::before {
    content: '';
    position: absolute;
    top: -60px; right: -60px;
    width: 180px; height: 180px;
    background: radial-gradient(circle, rgba(167,139,250,0.1) 0%, transparent 70%);
    pointer-events: none;
}

.card h1 {
    margin: 0 0 8px;
    font-size: clamp(1.3rem, 4vw, 1.65rem);
    font-weight: 800;
    letter-spacing: -0.02em;
    line-height: 1.2;
}

.card h2 {
    margin: 0 0 10px;
    font-size: clamp(1.05rem, 3vw, 1.25rem);
    font-weight: 700;
    letter-spacing: -0.01em;
}

.card p.sub {
    margin: 0 0 20px;
    color: var(--text-muted);
    font-size: 0.9rem;
    line-height: 1.6;
}

.card code {
    font-size: 0.82em;
    word-break: break-all;
    background: rgba(255,255,255,0.05);
    padding: 2px 6px;
    border-radius: 4px;
}

/* ——— Stats ——— */
.stats {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
}

@media (min-width: 480px) {
    .stats { grid-template-columns: repeat(2, 1fr); }
}

.stat {
    background: rgba(0,0,0,0.25);
    border: 1px solid rgba(255,255,255,0.05);
    border-radius: var(--radius-sm);
    padding: 16px 18px;
    position: relative;
    overflow: hidden;
    transition: border-color var(--transition);
}

.stat:hover { border-color: rgba(255,255,255,0.1); }

.stat label {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text-muted);
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 8px;
}

.stat strong {
    font-size: clamp(1.5rem, 5vw, 1.85rem);
    font-weight: 800;
    letter-spacing: -0.03em;
    font-variant-numeric: tabular-nums;
    line-height: 1;
}

.stat-available strong { color: var(--green); }
.stat-history strong { color: var(--accent); }
.stat-today strong { color: var(--yellow); }

.stat-available { border-color: rgba(52,211,153,0.1); }
.stat-history { border-color: rgba(167,139,250,0.1); }
.stat-today { border-color: rgba(251,191,36,0.1); }

/* Skeleton loader */
.stat.skeleton strong {
    display: block;
    background: linear-gradient(90deg, rgba(255,255,255,0.05) 25%, rgba(255,255,255,0.1) 50%, rgba(255,255,255,0.05) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: 6px;
    height: 1.85rem;
    width: 60%;
    color: transparent;
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ——— Forms ——— */
form.inline-grid { display: grid; gap: 16px; }

.field-label {
    display: grid;
    gap: 8px;
    font-weight: 600;
    font-size: 0.875rem;
}

.field-label > span {
    color: var(--text-muted);
    font-weight: 500;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.amount-block { display: grid; gap: 14px; }

.amount-row { display: grid; grid-template-columns: 1fr; gap: 10px; }

@media (min-width: 480px) {
    .amount-row {
        grid-template-columns: auto 1fr;
        align-items: center;
    }
}

.chip-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}

@media (max-width: 380px) {
    .chip-grid { grid-template-columns: repeat(2, 1fr); }
}

input[type="number"],
input[type="text"],
input[type="password"],
input[type="search"] {
    width: 100%;
    min-height: var(--touch);
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.1);
    color: var(--text);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    font-size: 16px;
    font-family: inherit;
    font-weight: 500;
    transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
}

input:focus {
    outline: none;
    border-color: rgba(167,139,250,0.6);
    box-shadow: 0 0 0 3px rgba(167,139,250,0.15);
    background: rgba(255,255,255,0.07);
}

input[type="search"] {
    padding-left: 42px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%236b7280' viewBox='0 0 16 16'%3E%3Cpath d='M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001c.03.04.062.078.098.115l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85a1.007 1.007 0 0 0-.115-.099zm-5.242 1.656a5.5 5.5 0 1 1 0-11 5.5 5.5 0 0 1 0 11z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: 14px center;
}

.chip {
    min-height: var(--touch);
    background: rgba(255,255,255,0.05);
    color: var(--text);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: var(--radius-sm);
    padding: 10px 8px;
    font-weight: 700;
    font-size: 0.9rem;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition);
    -webkit-tap-highlight-color: transparent;
}

.chip:hover {
    background: rgba(167,139,250,0.15);
    border-color: rgba(167,139,250,0.3);
}

.chip:active { transform: scale(0.95); }

.chip.is-selected {
    background: rgba(167,139,250,0.25);
    border-color: rgba(167,139,250,0.5);
    color: #fff;
    box-shadow: 0 0 12px rgba(167,139,250,0.2);
}

/* ——— Buttons ——— */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: var(--touch);
    border: none;
    border-radius: var(--radius-sm);
    padding: 13px 22px;
    font-size: 0.95rem;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    width: 100%;
    text-align: center;
    text-decoration: none;
    transition: all var(--transition);
    -webkit-tap-highlight-color: transparent;
    letter-spacing: -0.01em;
    position: relative;
    overflow: hidden;
}

.btn::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(255,255,255,0);
    transition: background var(--transition);
}

.btn:hover::after { background: rgba(255,255,255,0.06); }
.btn:active { transform: scale(0.98); }

.btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    transform: none;
}

.btn-primary {
    background: linear-gradient(135deg, var(--pink) 0%, var(--accent) 100%);
    color: #fff;
    box-shadow: 0 8px 24px rgba(244,114,182,0.3);
}

.btn-primary:hover {
    box-shadow: 0 12px 32px rgba(244,114,182,0.4);
    filter: brightness(1.05);
}

.btn-secondary {
    background: rgba(167,139,250,0.12);
    border: 1px solid rgba(167,139,250,0.25);
    color: var(--accent);
    width: 100%;
}

.btn-secondary:hover {
    background: rgba(167,139,250,0.2);
    border-color: rgba(167,139,250,0.4);
    color: #fff;
}

.btn-danger {
    background: var(--danger-dim);
    border: 1px solid rgba(248,113,113,0.3);
    color: var(--danger);
    width: 100%;
}

.btn-danger:hover {
    background: rgba(248,113,113,0.2);
    border-color: rgba(248,113,113,0.5);
    color: #fff;
}

.btn.is-loading {
    opacity: 0.85;
    cursor: wait;
    pointer-events: none;
}

.btn.is-loading .btn-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.undo-form { margin-top: 8px; }

.muted-note {
    margin: 8px 0 0;
    font-size: 0.83rem;
    color: var(--text-muted);
}

@media (min-width: 768px) {
    .btn-secondary { width: auto; min-width: 140px; }
    .btn-row {
        display: flex;
        flex-wrap: wrap;
        gap: 10px;
    }
    .btn-row .btn-secondary { width: auto; }
    .btn-row .btn-danger { width: auto; min-width: 160px; }
}

.action-bar { margin-top: 16px; }

/* ——— Alerts ——— */
.alert {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 14px 16px;
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    font-size: 0.9rem;
    line-height: 1.5;
    word-break: break-word;
    animation: alertIn 0.3s cubic-bezier(0.34,1.56,0.64,1);
}

@keyframes alertIn {
    from { opacity: 0; transform: translateY(-8px) scale(0.97); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.alert-icon {
    font-size: 1.1rem;
    flex-shrink: 0;
    margin-top: 1px;
}

.alert-success {
    background: rgba(52,211,153,0.1);
    border: 1px solid rgba(52,211,153,0.3);
    color: #a7f3d0;
}

.alert-success .alert-icon { color: var(--green); }

.alert-error {
    background: rgba(248,113,113,0.1);
    border: 1px solid rgba(248,113,113,0.3);
    color: #fca5a5;
}

.alert-error .alert-icon { color: var(--danger); }

.alert-info {
    background: rgba(251,191,36,0.08);
    border: 1px solid rgba(251,191,36,0.25);
    color: var(--yellow);
}

.alert-text { flex: 1; }

.alert-close {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 8px;
    background: rgba(255,255,255,0.06);
    color: var(--text-muted);
    font-size: 1.1rem;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
}

.alert-close:hover {
    background: rgba(255,255,255,0.12);
    color: var(--text);
}

.alert.is-hiding {
    opacity: 0;
    transform: translateY(-6px) scale(0.97);
    transition: all 0.22s ease-in;
}

/* ——— Toast system ——— */
#toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 99999;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: min(360px, calc(100vw - 40px));
    pointer-events: none;
}

.toast {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 14px 16px;
    background: rgba(26,26,46,0.97);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: 0 16px 48px rgba(0,0,0,0.5);
    backdrop-filter: blur(16px);
    font-size: 0.875rem;
    line-height: 1.4;
    pointer-events: auto;
    animation: toastIn 0.35s cubic-bezier(0.34,1.56,0.64,1);
    max-width: 100%;
}

@keyframes toastIn {
    from { opacity: 0; transform: translateX(24px) scale(0.95); }
    to { opacity: 1; transform: translateX(0) scale(1); }
}

.toast.is-hiding {
    animation: toastOut 0.25s ease-in forwards;
}

@keyframes toastOut {
    to { opacity: 0; transform: translateX(24px) scale(0.9); }
}

.toast-success { border-color: rgba(52,211,153,0.3); }
.toast-error { border-color: rgba(248,113,113,0.3); }
.toast-info { border-color: rgba(167,139,250,0.3); }

.toast-icon { font-size: 1.05rem; flex-shrink: 0; margin-top: 1px; }
.toast-success .toast-icon { color: var(--green); }
.toast-error .toast-icon { color: var(--danger); }
.toast-info .toast-icon { color: var(--accent); }
.toast-body { flex: 1; color: var(--text); }

/* ——— Modal ——— */
.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 10000;
    background: rgba(0,0,0,0.7);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
    background: var(--card2);
    border: 1px solid rgba(167,139,250,0.2);
    border-radius: var(--radius);
    padding: 28px 24px;
    max-width: 420px;
    width: 100%;
    box-shadow: 0 32px 80px rgba(0,0,0,0.6), 0 0 0 1px rgba(167,139,250,0.05) inset;
    animation: modalIn 0.3s cubic-bezier(0.34,1.56,0.64,1);
}

@keyframes modalIn {
    from { opacity: 0; transform: scale(0.9) translateY(16px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-icon {
    width: 52px;
    height: 52px;
    border-radius: 16px;
    background: var(--danger-dim);
    border: 1px solid rgba(248,113,113,0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    color: var(--danger);
    margin-bottom: 16px;
}

.modal h3 {
    margin: 0 0 8px;
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.modal p {
    margin: 0 0 20px;
    color: var(--text-muted);
    font-size: 0.9rem;
    line-height: 1.6;
}

.modal-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

/* ——— Login ——— */
.login-wrap {
    max-width: 440px;
    margin: clamp(16px, 8vh, 48px) auto;
}

.login-wrap .card { margin-bottom: 0; }

.login-wrap .card h1 {
    display: flex;
    align-items: center;
    gap: 10px;
}

.shake {
    animation: shake 0.5s cubic-bezier(0.36,0.07,0.19,0.97) both;
}

@keyframes shake {
    10%, 90% { transform: translateX(-2px); }
    20%, 80% { transform: translateX(4px); }
    30%, 50%, 70% { transform: translateX(-4px); }
    40%, 60% { transform: translateX(4px); }
}

.hp-field {
    position: absolute;
    left: -10000px;
    width: 1px;
    height: 1px;
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
}

.password-wrap {
    position: relative;
    display: flex;
    align-items: stretch;
}

.password-wrap input { padding-right: 52px; }

.password-toggle {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    width: 38px;
    height: 38px;
    border: none;
    border-radius: 8px;
    background: rgba(255,255,255,0.05);
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
    font-size: 0.9rem;
}

.password-toggle:hover {
    background: rgba(255,255,255,0.1);
    color: var(--text);
}

/* ——— Tables ——— */
.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 -4px;
    padding: 0 4px;
}

table.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

table.data-table th,
table.data-table td {
    text-align: left;
    padding: 13px 12px;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    vertical-align: middle;
}

table.data-table th {
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    background: rgba(0,0,0,0.15);
    position: sticky;
    top: 0;
}

table.data-table tbody tr {
    transition: background var(--transition);
}

table.data-table tbody tr:hover {
    background: rgba(255,255,255,0.03);
}

table.data-table td.actions-cell { white-space: nowrap; }

table.data-table .actions-cell .btn-secondary {
    display: inline-flex;
    width: auto;
    min-width: 0;
    padding: 7px 12px;
    min-height: 36px;
    font-size: 0.82rem;
    margin: 2px 3px 2px 0;
}

table.data-table .actions-cell .undo-form {
    display: inline-block;
    margin: 0;
    vertical-align: middle;
}

table.data-table .actions-cell .undo-form .btn-danger {
    width: auto;
    min-height: 36px;
    padding: 7px 12px;
    font-size: 0.82rem;
}

/* ——— Badges ——— */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 600;
    margin-top: 4px;
    letter-spacing: 0.03em;
}

.badge-panel {
    background: rgba(52,211,153,0.12);
    color: var(--green);
    border: 1px solid rgba(52,211,153,0.2);
}

.badge-api {
    background: rgba(96,165,250,0.12);
    color: var(--info);
    border: 1px solid rgba(96,165,250,0.2);
}

.badge-legacy {
    background: rgba(107,114,128,0.15);
    color: var(--text-muted);
    border: 1px solid rgba(107,114,128,0.2);
}

.badge-default {
    background: rgba(167,139,250,0.12);
    color: var(--accent);
    border: 1px solid rgba(167,139,250,0.2);
}

/* ——— Record preview ——— */
.record-preview {
    max-width: 280px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text-muted);
    font-size: 0.78rem;
    cursor: pointer;
    transition: color var(--transition);
}

.record-preview:hover { color: var(--text); }

.record-preview.expanded {
    white-space: normal;
    max-width: 100%;
    word-break: break-all;
    color: var(--text);
}

@media (min-width: 768px) {
    .record-preview { max-width: 380px; }
}

/* ——— Batch & record cards (mobile) ——— */
.mobile-only { display: block; }
.desktop-only { display: none; }

@media (min-width: 768px) {
    .mobile-only { display: none; }
    .desktop-only { display: block; }
}

.batch-card, .record-card {
    background: rgba(0,0,0,0.2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 16px;
    margin-bottom: 10px;
    transition: border-color var(--transition);
}

.batch-card:last-child, .record-card:last-child { margin-bottom: 0; }
.batch-card:hover, .record-card:hover { border-color: var(--border-hover); }

.batch-card dl, .record-card dl {
    margin: 0;
    display: grid;
    gap: 10px;
}

.batch-card dt, .record-card dt {
    font-size: 0.72rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
}

.batch-card dd, .record-card dd {
    margin: 0 0 4px;
    font-size: 0.92rem;
    word-break: break-word;
    font-weight: 500;
}

.batch-card .card-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 14px;
}

@media (min-width: 480px) {
    .batch-card .card-actions {
        flex-direction: row;
        flex-wrap: wrap;
    }
    .batch-card .card-actions .btn-secondary { flex: 1; min-width: 100px; }
}

/* ——— Detail page ——— */
.detail-header .btn-row {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 16px;
}

.detail-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    font-size: 0.86rem;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.detail-meta span {
    display: flex;
    align-items: center;
    gap: 5px;
}

.copy-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: rgba(255,255,255,0.04);
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    font-family: inherit;
}

.copy-btn:hover {
    border-color: var(--border-hover);
    color: var(--text);
    background: rgba(255,255,255,0.08);
}

.copy-btn.copied {
    color: var(--green);
    border-color: rgba(52,211,153,0.3);
}

/* ——— Toolbar / search ——— */
.toolbar {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.search-field {
    flex: 1;
    min-width: 180px;
}

.search-field input { width: 100%; }

/* ——— Pagination ——— */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin-top: 20px;
    flex-wrap: wrap;
}

.pagination a,
.pagination span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 38px;
    height: 38px;
    padding: 0 10px;
    border-radius: 10px;
    font-size: 0.875rem;
    font-weight: 600;
    text-decoration: none;
    border: 1px solid var(--border);
    transition: all var(--transition);
}

.pagination a {
    background: rgba(255,255,255,0.04);
    color: var(--text);
}

.pagination a:hover {
    background: rgba(255,255,255,0.09);
    border-color: var(--border-hover);
}

.pagination .current {
    background: rgba(167,139,250,0.2);
    border-color: rgba(167,139,250,0.4);
    color: var(--accent);
}

.pagination .disabled {
    opacity: 0.35;
    cursor: default;
    color: var(--text-muted);
    border-color: var(--border);
    background: transparent;
}

/* ——— Empty state ——— */
.empty-state {
    text-align: center;
    padding: 48px 24px;
}

.empty-icon {
    width: 72px;
    height: 72px;
    margin: 0 auto 16px;
    border-radius: 20px;
    background: rgba(255,255,255,0.04);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.75rem;
    color: var(--text-muted);
}

.empty-state h3 {
    margin: 0 0 8px;
    font-size: 1.1rem;
    font-weight: 700;
}

.empty-state p {
    color: var(--text-muted);
    margin: 0 0 20px;
    font-size: 0.9rem;
}

/* ——— Footer ——— */
.footer {
    margin-top: 28px;
    padding-bottom: env(safe-area-inset-bottom);
    color: var(--text-muted);
    text-align: center;
    font-size: 0.75rem;
    line-height: 1.6;
}

.footer code { color: var(--yellow); font-size: 0.85em; }

/* ——— Progress bar ——— */
.progress-bar-wrap {
    height: 4px;
    background: rgba(255,255,255,0.06);
    border-radius: 999px;
    overflow: hidden;
    margin-top: 14px;
    display: none;
}

.progress-bar-wrap.is-visible { display: block; }

.progress-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--accent), var(--pink));
    border-radius: 999px;
    transition: width 0.4s ease;
    animation: progressGlow 1.5s ease-in-out infinite;
}

@keyframes progressGlow {
    0%, 100% { box-shadow: 0 0 6px rgba(167,139,250,0.5); }
    50% { box-shadow: 0 0 16px rgba(244,114,182,0.7); }
}

/* ——— Content animation ——— */
.content-enter {
    animation: contentIn 0.35s cubic-bezier(0.4,0,0.2,1);
}

@keyframes contentIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.content { position: relative; z-index: 1; }

/* ——— Focus visible ——— */
:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
}

/* ——— Mobile-only elements ——— */
@media (max-width: 767px) {
    .table-wrap, .batch-card, .toolbar { position: relative; z-index: 1; }
    .logged-in .footer { display: none; }
}

/* ——— Section header ——— */
.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
    flex-wrap: wrap;
    gap: 10px;
}

.section-header h2 { margin: 0; }

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

/* ——— batch hidden via filter ——— */
.batch-card[data-search][hidden],
tr[data-search][hidden] { display: none !important; }
