/* ===== ROOT & RESET ===== */
/* Light theme (default) */
:root {
    --bg-dark: #f0f4f8;
    --bg-card: #ffffff;
    --bg-card-hover: #f1f5f9;
    --bg-sidebar: #e8edf3;
    --accent: #d97706;
    --accent-dim: #fde68a;
    --danger: #dc2626;
    --danger-dim: #fee2e2;
    --success: #16a34a;
    --success-dim: #dcfce7;
    --info: #2563eb;
    --text-primary: #1e293b;
    --text-muted: #64748b;
    --border: #cbd5e1;
    --radius: 12px;
    --radius-sm: 8px;
    /* component-specific tokens */
    --bg-form-input: #f8fafc;
    --navbar-bg-start: #e8edf3;
    --navbar-bg-end: #f0f4f8;
    --navbar-toggler-filter: none;
    --bar-track-bg: rgba(0, 0, 0, 0.07);
    --tx-note-bg: rgba(0, 0, 0, 0.05);
    --modal-backdrop-bg: rgba(0, 0, 0, 0.4);
}

/* Dark theme */
[data-theme="dark"] {
    --bg-dark: #0f1117;
    --bg-card: #1a1d27;
    --bg-card-hover: #22263a;
    --bg-sidebar: #12151f;
    --accent: #f59e0b;
    --accent-dim: #92400e;
    --danger: #ef4444;
    --danger-dim: #7f1d1d;
    --success: #22c55e;
    --success-dim: #14532d;
    --info: #3b82f6;
    --text-primary: #f1f5f9;
    --text-muted: #94a3b8;
    --border: #2d3148;
    --bg-form-input: #0f1117;
    --navbar-bg-start: #1a1d27;
    --navbar-bg-end: #0f1117;
    --navbar-toggler-filter: invert(1);
    --bar-track-bg: rgba(255, 255, 255, 0.06);
    --tx-note-bg: rgba(255, 255, 255, 0.06);
    --modal-backdrop-bg: rgba(0, 0, 0, 0.6);
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
    min-height: 100%;
    background: var(--bg-dark);
    color: var(--text-primary);
    font-family: 'Segoe UI', system-ui, sans-serif;
    margin: 0;
    overflow-x: hidden;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== LAYOUT ===== */
.page {
    display: flex;
    min-height: 100dvh;
    overflow: hidden;
}

.sidebar {
    width: auto;
    min-width: 0;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    flex-shrink: 0;
}

main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
}

.top-row {
    background: var(--bg-sidebar);
    border-bottom: 1px solid var(--border);
    padding: 0.5rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
    font-size: 0.8rem;
    color: var(--text-muted);
}

    .top-row a { color: var(--text-muted); }
    .top-row a:hover { color: var(--accent); text-decoration: none; }

.top-row-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.35rem;
    flex: 0 0 auto;
}

.content {
    flex: 1;
    overflow-y: auto;
    min-width: 0;
    padding: 1.5rem 2rem;
}

/* ===== NAVBAR ===== */
.nav-shell {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.nav-desktop {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.nav-menu {
    display: block;
}

.nav-mobile {
    display: none;
}

.top-row.ps-3.navbar {
    background: linear-gradient(135deg, var(--navbar-bg-start) 0%, var(--navbar-bg-end) 100%);
    border-bottom: 2px solid var(--accent);
    padding: 0.75rem 1rem;
}

.navbar-brand {
    color: var(--accent) !important;
    font-weight: 800;
    font-size: 1.1rem;
    letter-spacing: 0.05em;
}

.navbar-toggler { border-color: var(--border); }
.navbar-toggler-icon { filter: var(--navbar-toggler-filter); }

.btn-theme-toggle {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--border);
    color: var(--text-primary);
    border-radius: 999px;
    min-width: 2.5rem;
    min-height: 2.5rem;
    padding: 0.35rem 0.7rem;
    font-size: 1rem;
    line-height: 1;
}

    .btn-theme-toggle:hover {
        background: rgba(255, 255, 255, 0.12);
        color: var(--accent);
    }

.nav-item { padding: 2px 0; }

.nav-link {
    color: var(--text-muted) !important;
    border-radius: var(--radius-sm);
    padding: 0.5rem 0.75rem;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

    .nav-link:hover, .nav-link.active {
        background: rgba(245,158,11,0.12);
        color: var(--accent) !important;
    }

    .nav-link .oi {
        width: 1.1rem;
        text-align: center;
    }

/* ===== DASHBOARD HEADER ===== */
.dashboard-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.header-left { display: flex; align-items: center; gap: 1rem; }

.board-title {
    margin: 0;
    font-size: 1.8rem;
    font-weight: 800;
    color: var(--accent);
}

.unit-price-badge {
    background: rgba(245,158,11,0.15);
    color: var(--accent);
    border: 1px solid rgba(245,158,11,0.3);
    border-radius: 20px;
    padding: 0.2rem 0.75rem;
    font-size: 0.8rem;
    font-weight: 600;
}

.header-actions { display: flex; gap: 0.5rem; }

/* ===== SUMMARY BAR ===== */
.summary-panel {
    margin-bottom: 1.25rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    overflow: hidden;
}

.summary-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    list-style: none;
    cursor: pointer;
    user-select: none;
    padding: 0.7rem 1rem;
    border-bottom: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-primary);
    font-weight: 700;
}

    .summary-toggle::-webkit-details-marker {
        display: none;
    }

    .summary-toggle::after {
        content: '▾';
        color: var(--accent);
        font-size: 0.95rem;
        transition: transform 0.15s ease;
    }

.summary-panel[open] .summary-toggle {
    border-bottom-color: var(--border);
}

.summary-panel[open] .summary-toggle::after {
    transform: rotate(180deg);
}

.summary-toggle-hint {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-muted);
}

.summary-panel-body {
    padding: 0.75rem 1rem 1rem;
}

.summary-bar {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 0.75rem;
}

.summary-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.75rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.summary-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.summary-value {
    font-size: 1.5rem;
    font-weight: 800;
    line-height: 1;
}

/* ===== SEARCH ===== */
.search-box {
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-primary);
    border-radius: var(--radius-sm);
    max-width: 280px;
}

    .search-box:focus {
        background: var(--bg-card);
        border-color: var(--accent);
        color: var(--text-primary);
        box-shadow: 0 0 0 2px rgba(245,158,11,0.2);
    }

/* ===== PAPER BOARD ===== */
.paper-board-shell {
    position: relative;
    padding: 0.25rem 0 1.5rem;
}

.paper-board {
    --paper-row-height: 56px;
    position: relative;
    background:
        radial-gradient(circle at 18% 12%, rgba(173, 120, 80, 0.08), transparent 24%),
        radial-gradient(circle at 82% 24%, rgba(74, 144, 226, 0.05), transparent 22%),
        linear-gradient(180deg, rgba(60, 74, 52, 0.04), transparent 14%),
        linear-gradient(90deg, transparent 0, transparent 4.5rem, rgba(221, 102, 102, 0.32) 4.5rem, rgba(221, 102, 102, 0.32) 4.6rem, transparent 4.6rem),
        linear-gradient(180deg, #f7f2e6 0%, #f2ebdc 100%);
    border: 1px solid rgba(148, 126, 90, 0.35);
    border-radius: 18px;
    box-shadow: 0 28px 48px rgba(0, 0, 0, 0.32), inset 0 0 0 1px rgba(255, 255, 255, 0.38);
    padding: 1.25rem 1rem 1rem;
    color: #463b2d;
    overflow: hidden;
    display: grid;
    grid-template-columns: max-content max-content minmax(220px, 1fr) auto;
    column-gap:2rem;
    row-gap: 0;
}

    .paper-board::before {
        content: '';
        position: absolute;
        inset: 0;
        background:
            radial-gradient(circle at 12% 28%, rgba(161, 128, 83, 0.1) 0, transparent 18%),
            radial-gradient(circle at 73% 63%, rgba(104, 142, 171, 0.06) 0, transparent 16%),
            radial-gradient(circle at 46% 85%, rgba(161, 128, 83, 0.07) 0, transparent 14%);
        pointer-events: none;
        mix-blend-mode: multiply;
    }

.paper-board-header {
    grid-column: 1 / -1;
    position: relative;
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    padding: 0 0.5rem 0.85rem 5.9rem;
    color: rgba(70, 59, 45, 0.72);
    border-bottom: 1px dashed rgba(89, 96, 108, 0.28);
    margin-bottom: 0.2rem;
}

.paper-board-title {
    text-transform: uppercase;
    letter-spacing: 0.18em;
    font-size: 0.72rem;
    font-weight: 800;
}

.paper-board-note {
    font-size: 0.8rem;
    font-style: italic;
}

.paper-empty-state {
    grid-column: 1 / -1;
    min-height: 10rem;
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(70, 59, 45, 0.68);
    font-style: italic;
}

.paper-row {
    position: relative;
    display: grid;
    grid-column: 1 / -1;
    grid-template-columns: subgrid;
    align-items: center;
    min-height: var(--paper-row-height);
    padding: 0 0.5rem;
    transition: background 0.12s ease, box-shadow 0.12s ease;
    touch-action: pan-y;
    user-select: none;
}

    .paper-row:not(:last-child) {
        border-bottom: 1px solid rgba(89, 96, 108, 0.18);
    }

    .paper-row:hover {
        background: rgba(255, 255, 255, 0.18);
    }

.paper-person-column {
    display: flex;
    align-items: baseline;
    gap: 0.55rem;
    min-width: var(--person-col-width, 10rem);
}

.paper-initials {
    font-weight: 800;
    font-size: 1rem;
    min-width: 3.1rem;
    color: rgba(70, 59, 45, 0.94);
}

.paper-name {
    font-size: 0.92rem;
    color: rgba(70, 59, 45, 0.88);
}

.paper-status {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: rgba(70, 59, 45, 0.5);
}

.paper-count-column {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.1rem;
}

.paper-total {
    font-size: 1.15rem;
    font-weight: 800;
    line-height: 1;
}

    .paper-total.due { color: #53473a; }
    .paper-total.clear { color: rgba(83, 71, 58, 0.5); }

.paper-kr {
    font-size: 0.72rem;
    color: rgba(70, 59, 45, 0.65);
}

.paper-tally-column {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.3rem 0.2rem;
    min-height: 28px;
    padding: 0.15rem 0;
}

.paper-tally-cluster {
    position: relative;
    display: flex;
    align-items: flex-end;
    gap: 0.18rem;
    min-width: 2.3rem;
    height: 26px;
    padding-right: 0.18rem;
}

    .paper-tally-cluster.partial {
        min-width: auto;
    }

.paper-tally-stroke,
.paper-tally-slash {
    display: inline-block;
    border-radius: 999px;
    opacity: var(--stroke-opacity, 0.8);
    filter: none;
    -webkit-filter: none;
}

.tally-preview {
    opacity: 0.3 !important;
}

.paper-tally-stroke.tally-ghost,
.paper-tally-slash.tally-ghost {
    display: none;
}

    .paper-tally-stroke.tally-ghost.tally-visible,
    .paper-tally-slash.tally-ghost.tally-visible {
        display: inline-block;
    }

.paper-tally-cluster.cluster-ghost {
    display: none;
}

    .paper-tally-cluster.cluster-ghost.cluster-visible {
        display: flex;
    }

.paper-tally-stroke {
    width: 2px;
    height: var(--stroke-height, 22px);
    margin-top: var(--stroke-offset, 0);
    transform: rotate(var(--stroke-rotate, -2deg));
    transform-origin: center bottom;
}

.paper-tally-slash {
    position: absolute;
    left: 0.4rem;
    top: 0.0rem;
    width: 2px;
    height: 30px;
    transform: translateY(var(--slash-offset, 0)) rotate(var(--slash-rotate, 65deg));
    transform-origin: center center;
}

.ink-blue {
    background: linear-gradient(180deg, rgba(54, 107, 204, 0.84), rgba(39, 82, 162, 0.94));
    box-shadow: 0 0 0 0.4px rgba(54, 107, 204, 0.3);
}

.ink-red {
    background: linear-gradient(180deg, rgba(241, 104, 99, 0.82), rgba(218, 71, 69, 0.94));
    box-shadow: 0 0 0 0.4px rgba(218, 71, 69, 0.22);
}

.paper-overflow,
.paper-clear-note {
    padding: 0.1rem 0.42rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 700;
}

.paper-overflow {
    color: rgba(70, 59, 45, 0.78);
    background: rgba(70, 59, 45, 0.08);
}

.paper-clear-note {
    color: rgba(70, 59, 45, 0.52);
    background: rgba(70, 59, 45, 0.05);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.paper-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    justify-content: flex-end;
}

/* ===== QUICK ACTION BUTTONS ===== */
.quick-actions {
    display: flex;
    gap: 0.35rem;
    flex-wrap: wrap;
}

.btn-quick {
    border: none;
    border-radius: 6px;
    padding: 0.25rem 0.6rem;
    font-size: 0.75rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.1s;
    flex: 1;
    min-width: 36px;
}

    .btn-quick:disabled {
        opacity: 0.3;
        cursor: not-allowed;
    }

    .btn-quick.details {
        background: rgba(245, 158, 11, 0.14);
        color: #8a5a08;
        border: 1px solid rgba(138, 90, 8, 0.2);
        min-width: 58px;
    }

        .btn-quick.details:hover:not(:disabled) {
            background: rgba(245, 158, 11, 0.22);
        }

    .btn-quick.debt {
        background: rgba(54, 107, 204, 0.1);
        color: #2a4f9b;
        border: 1px solid rgba(42, 79, 155, 0.18);
    }

        .btn-quick.debt:hover:not(:disabled) {
            background: rgba(54, 107, 204, 0.16);
        }

    .btn-quick.pay {
        background: rgba(239, 68, 68, 0.12);
        color: #9b3f3d;
        border: 1px solid rgba(155, 63, 61, 0.2);
    }

        .btn-quick.pay:hover:not(:disabled) {
            background: rgba(239, 68, 68, 0.18);
        }

/* ===== MODALS ===== */
.modal-backdrop-custom {
    position: fixed;
    inset: 0;
    background: var(--modal-backdrop-bg);
    backdrop-filter: blur(3px);
    z-index: 1000;
}

.modal-custom {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    z-index: 1001;
    width: min(420px, 92vw);
    box-shadow: 0 24px 64px rgba(0,0,0,0.6);
}

    .modal-custom h5 {
        margin: 0 0 1rem;
        font-weight: 700;
        color: var(--accent);
    }

/* ===== FORMS ===== */
.form-control, .form-select {
    background: var(--bg-form-input);
    border: 1px solid var(--border);
    color: var(--text-primary);
    border-radius: var(--radius-sm);
}

    .form-control:focus, .form-select:focus {
        background: var(--bg-form-input);
        border-color: var(--accent);
        color: var(--text-primary);
        box-shadow: 0 0 0 2px rgba(245,158,11,0.2);
    }

.form-label {
    color: var(--text-muted);
    font-size: 0.82rem;
    margin-bottom: 0.3rem;
}

/* ===== BUTTONS ===== */
.btn-success { background: var(--success); border-color: var(--success); color: #000; font-weight: 600; }
.btn-danger { background: var(--danger); border-color: var(--danger); font-weight: 600; }
.btn-primary { background: var(--info); border-color: var(--info); font-weight: 600; }


/* ===== DETAIL PAGE ===== */
.detail-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.detail-title h2 { margin: 0; font-size: 1.5rem; font-weight: 800; }
.detail-title small { color: var(--text-muted); font-size: 0.8rem; }

.stats-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
    border-left: 4px solid transparent;
}

    .stat-card.danger { border-left-color: var(--danger); }
    .stat-card.success { border-left-color: var(--success); }
    .stat-card.info { border-left-color: var(--info); }
    .stat-card.neutral { border-left-color: var(--accent); }

.stat-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin-bottom: 0.3rem;
}

.stat-number { font-size: 1.6rem; font-weight: 800; line-height: 1.1; }
.stat-sub { font-size: 0.78rem; color: var(--text-muted); margin-top: 0.15rem; }

/* ===== TRANSACTION FORM ===== */
.transaction-form {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
}

    .transaction-form h5 { margin: 0 0 1rem; font-weight: 700; }

/* ===== TRANSACTION LIST ===== */
.tx-list { display: flex; flex-direction: column; gap: 0.4rem; }

.tx-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.6rem 0.85rem;
    border-left: 3px solid transparent;
}

    .tx-row.tx-debt { border-left-color: var(--danger); }
    .tx-row.tx-pay { border-left-color: var(--success); }

.tx-icon { font-size: 1rem; flex-shrink: 0; }

.tx-info {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex: 1;
    flex-wrap: wrap;
}

.tx-units { font-weight: 700; font-size: 0.9rem; }
.tx-kr { color: var(--text-muted); font-size: 0.82rem; }
.tx-note {
    background: var(--tx-note-bg);
    border-radius: 4px;
    padding: 0 6px;
    font-size: 0.78rem;
    color: var(--text-muted);
    font-style: italic;
}
.tx-date { font-size: 0.75rem; color: var(--text-muted); white-space: nowrap; }

.btn-delete {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.8rem;
    padding: 2px 6px;
    border-radius: 4px;
    flex-shrink: 0;
}
    .btn-delete:hover { background: rgba(239,68,68,0.2); color: var(--danger); }

/* ===== STATISTICS PAGE ===== */
.page-header { margin-bottom: 1.25rem; }
.page-header h2 { font-size: 1.8rem; font-weight: 800; color: var(--accent); margin: 0; }

.chart-section {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-bottom: 1rem;
}

    .chart-section h5 { margin: 0 0 1rem; font-weight: 700; color: var(--text-primary); }

.bar-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
}

.bar-label {
    width: 3.5rem;
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--accent);
    text-align: right;
    flex-shrink: 0;
}

.bar-track {
    flex: 1;
    background: var(--bar-track-bg);
    border-radius: 4px;
    height: 22px;
    overflow: hidden;
}

.bar-fill {
    height: 100%;
    border-radius: 4px;
    min-width: 4px;
    transition: width 0.5s ease;
}

    .bar-fill.debt { background: linear-gradient(90deg, var(--danger), var(--accent)); }
    .bar-fill.paid { background: linear-gradient(90deg, var(--success), #16a34a); }

.bar-value { font-size: 0.78rem; color: var(--text-muted); white-space: nowrap; min-width: 100px; }

.ratio-bar {
    display: flex;
    height: 36px;
    border-radius: 8px;
    overflow: hidden;
    font-size: 0.78rem;
    font-weight: 700;
}

    .ratio-bar span { display: flex; align-items: center; padding: 0 8px; white-space: nowrap; overflow: hidden; }

.ratio-debt { background: linear-gradient(90deg, var(--danger-dim), var(--danger)); color: #fff; transition: width 0.5s; }
.ratio-paid { background: linear-gradient(90deg, var(--success-dim), var(--success)); color: #000; transition: width 0.5s; }

/* ===== TABLES ===== */
.table-dark {
    --bs-table-bg: transparent;
    --bs-table-hover-bg: rgba(255,255,255,0.04);
    --bs-table-border-color: var(--border);
    font-size: 0.87rem;
    width: 100%;
}

    .table-dark thead th {
        color: var(--text-muted);
        font-size: 0.75rem;
        text-transform: uppercase;
        letter-spacing: 0.06em;
        border-bottom: 1px solid var(--border);
        padding: 0.5rem 0.75rem;
    }

    .table-dark tbody tr td { padding: 0.5rem 0.75rem; }

.row-clear td { opacity: 0.5; }

/* ===== LEADERBOARD ===== */
.leaderboard { display: flex; flex-direction: column; gap: 0.5rem; }

.leaderboard-row {
    display: flex;
    align-items: center;
    gap: 1rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.9rem 1.25rem;
    cursor: pointer;
    transition: all 0.15s;
}

    .leaderboard-row:hover { background: var(--bg-card-hover); border-color: var(--accent); transform: translateX(4px); }

    .leaderboard-row.rank-1 { border-left: 4px solid gold; background: linear-gradient(90deg, rgba(255,215,0,0.08), transparent); }
    .leaderboard-row.rank-2 { border-left: 4px solid silver; }
    .leaderboard-row.rank-3 { border-left: 4px solid #cd7f32; }
    .leaderboard-row.cleared { opacity: 0.55; }

.rank-badge { font-size: 1.4rem; width: 2.5rem; text-align: center; flex-shrink: 0; }

.hs-initials {
    background: rgba(245,158,11,0.18);
    color: var(--accent);
    font-weight: 800;
    font-size: 0.85rem;
    padding: 0.2rem 0.55rem;
    border-radius: 6px;
    flex-shrink: 0;
}

.hs-name { font-weight: 600; font-size: 1rem; }

.loading-shell {
    position: relative;
}

.loading-shell-content {
    transition: filter 0.15s ease, opacity 0.15s ease;
}

.loading-shell.is-loading .loading-shell-content {
    filter: blur(6px);
    opacity: 0.78;
    pointer-events: none;
    user-select: none;
}

.loading-overlay {
    position: fixed;
    inset: 0;
    z-index: 11000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    background: var(--modal-backdrop-bg);
    backdrop-filter: blur(2px);
}

.loading-overlay-panel {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    min-width: 11rem;
    padding: 1rem 1.25rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-card);
    color: var(--text-primary);
    box-shadow: 0 1rem 3rem rgba(15, 23, 42, 0.2);
    font-weight: 600;
}

/* ===== FULLSCREEN MODE ===== */
.fullscreen-tally-container {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    background: var(--bg-dark);
    z-index: 9999;
    overflow: hidden;
    padding: 1rem;
}

/* ===== FULLSCREEN MODE ===== */
.fullscreen-tally-container {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    background: var(--bg-dark);
    z-index: 9999;
    overflow: hidden;
    padding: 1rem;
}

.fullscreen-tally-container .paper-board-shell {
    flex: 1;
    display: flex;
    overflow: auto;
    padding: 0.25rem 0;
}

.fullscreen-tally-container .paper-board {
    width: 100%;
    max-height: 100%;
    overflow-y: auto;
}

.fullscreen-exit-btn {
    position: fixed;
    top: 1rem;
    right: 1rem;
    background: rgba(239, 68, 68, 0.9);
    color: white;
    border: none;
    border-radius: 8px;
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    z-index: 10000;
    transition: all 0.15s;
}

    .fullscreen-exit-btn:hover {
        background: rgba(239, 68, 68, 1);
        transform: scale(1.05);
    }

/* Loading Overlay Styles */
.loading-overlay {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10001;
}

.loading-backdrop {
    position: absolute;
    inset: 0;
    background: var(--bg-dark);
    backdrop-filter: blur(4px);
    z-index: -1;
}

.loading-spinner {
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1;
}

.paper-row {
    position: relative;
    display: grid;
    grid-column: 1 / -1;
    grid-template-columns: subgrid;
    align-items: center;
    min-height: var(--paper-row-height);
    padding: 0 0.5rem;
    transition: background 0.12s ease, box-shadow 0.12s ease;
    touch-action: pan-y;
    user-select: none;
}

.paper-row::before {
    content: '';
    position: absolute;
    inset: 0.15rem 0;
    border-radius: 14px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.12s ease, background 0.12s ease;
}

.paper-row.swiping {
    z-index: 1;
    box-shadow: 0 10px 24px rgba(70, 59, 45, 0.16);
}

.paper-row.swiping::before {
    opacity: 1;
}

.paper-row.swipe-positive::before {
    background: linear-gradient(90deg, rgba(22, 163, 74, 0.2), rgba(22, 163, 74, 0.05));
}

.paper-row.swipe-negative::before {
    background: linear-gradient(90deg, rgba(220, 38, 38, 0.05), rgba(220, 38, 38, 0.2));
}

.paper-row.swipe-neutral::before {
    background: rgba(37, 99, 235, 0.08);
}

.swipe-preview {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 2;
    display: none;
    align-items: center;
    gap: 0.55rem;
    padding: 0.35rem 0.75rem;
    border-radius: 999px;
    font-size: 0.74rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    border: 1px solid transparent;
    box-shadow: 0 8px 18px rgba(70, 59, 45, 0.14);
    pointer-events: none;
}

.swipe-preview-value {
    font-size: 0.95rem;
    font-weight: 800;
    letter-spacing: 0;
}

.paper-row.swiping .swipe-preview {
    display: inline-flex;
}

.swipe-preview-positive {
    background: rgba(220, 252, 231, 0.95);
    color: #166534;
    border-color: rgba(22, 163, 74, 0.25);
}

.swipe-preview-negative {
    background: rgba(254, 226, 226, 0.95);
    color: #991b1b;
    border-color: rgba(220, 38, 38, 0.25);
}

.swipe-preview-neutral {
    background: rgba(219, 234, 254, 0.95);
    color: #1d4ed8;
    border-color: rgba(37, 99, 235, 0.2);
}

@media (max-width: 900px) {
    .page {
        flex-direction: column;
        min-height: 100dvh;
        height: auto;
        overflow: visible;
    }

    .sidebar {
        display: contents;
        border: 0;
        background: transparent;
    }

    main {
        overflow: visible;
    }

    .content {
        overflow: visible;
        padding: 1rem;
        padding-bottom: 1rem;
    }

    .top-row {
        padding: 0.5rem 1rem;
        align-items: center;
        flex-wrap: nowrap;
    }

    .fullscreen-tally-container {
        overflow-y: auto;
        padding: 0.35rem;
    }

    .fullscreen-tally-container .paper-board-shell {
        flex: 1 1 auto;
        overflow: visible;
        padding: 0;
    }

    .fullscreen-tally-container .paper-board {
        max-height: none;
        overflow: visible;
        padding: 0.85rem 0.7rem 0.7rem;
    }

    .fullscreen-exit-btn {
        top: 0.4rem;
        right: 0.4rem;
        padding: 0.4rem 0.8rem;
        font-size: 0.8rem;
    }

    .app-version {
        display: none;
    }

    .top-row-nav {
        display: flex;
        align-items: center;
        justify-content: flex-start;
        gap: 0.2rem;
        flex: 1 1 auto;
        min-width: 0;
        order: 1;
    }

    .top-row-actions {
        display: flex;
        align-items: center;
        justify-content: flex-end;
        gap: 0.35rem;
        margin-left: auto;
        flex: 0 0 auto;
        order: 2;
        white-space: nowrap;
    }

    .top-row-nav-link {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 0.15rem;
        min-width: 0;
        padding: 0.35rem 0.5rem;
        color: var(--text-muted) !important;
        border-radius: 12px;
        text-decoration: none;
        font-size: 0.72rem;
        line-height: 1;
    }

        .top-row-nav-link .oi {
            width: auto;
            font-size: 0.95rem;
            top: 0;
        }

    .top-row-nav-link.active {
        color: var(--accent) !important;
        background: rgba(245, 158, 11, 0.12);
    }

    .top-row-nav-label {
        font-size: 0.62rem;
        font-weight: 700;
        line-height: 1;
    }

    .btn-theme-toggle {
        order: 2;
        margin-left: auto;
        flex: 0 0 auto;
    }

    .dashboard-header,
    .detail-header,
    .leaderboard-row,
    .tx-row,
    .bar-row {
        align-items: stretch;
    }

    .header-left,
    .detail-header .ms-auto,
    .paper-person-column,
    .paper-count-column,
    .paper-actions,
    .tx-info {
        width: 100%;
    }

    .dashboard-header,
    .detail-header,
    .leaderboard-row,
    .tx-row {
        flex-direction: column;
    }

    .header-left,
    .detail-header .ms-auto {
        flex-wrap: wrap;
    }

    .board-title,
    .page-header h2,
    .detail-title h2 {
        font-size: 1.4rem;
    }

    .summary-bar,
    .stats-row {
        grid-template-columns: 1fr;
    }

    .summary-toggle {
        padding: 0.65rem 0.9rem;
    }

    .summary-panel-body {
        padding: 0.65rem 0.9rem 0.9rem;
    }

    .summary-value,
    .stat-number {
        font-size: 1.35rem;
    }

    .chart-section {
        padding: 1rem;
    }

    .chart-section table {
        display: block;
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .table-dark {
        min-width: 560px;
    }

    .bar-row {
        flex-wrap: wrap;
        gap: 0.4rem;
    }

    .bar-label {
        width: 2.5rem;
        text-align: left;
    }

    .bar-value {
        min-width: 0;
    }

    .ratio-bar {
        height: 32px;
    }

    .transaction-form .d-flex {
        flex-direction: column;
        align-items: stretch !important;
    }

    .transaction-form .d-flex > div,
    .transaction-form .d-flex > button {
        width: 100%;
        min-width: 0 !important;
    }

    .transaction-form input,
    .transaction-form select,
    .transaction-form button {
        width: 100% !important;
        max-width: 100%;
    }

    .tx-row {
        gap: 0.5rem;
    }

    .tx-date,
    .tx-note {
        white-space: normal;
    }

    .tx-date,
    .btn-delete {
        align-self: flex-end;
    }

    .paper-board-shell {
        overflow-x: visible;
        padding: 0;
        touch-action: pan-y;
    }

    .paper-board {
        display: flex;
        flex-direction: column;
        gap: 0.85rem;
        min-width: 0;
        padding: 1rem 0.85rem 0.85rem;
        background:
            radial-gradient(circle at 18% 12%, rgba(173, 120, 80, 0.06), transparent 24%),
            radial-gradient(circle at 1% 20%, rgba(110, 90, 226, 0.04), transparent 22%),
            radial-gradient(circle at 30% 50%, rgba(100, 190, 226, 0.04), transparent 22%),
            radial-gradient(circle at 82% 80%, rgba(74, 144, 226, 0.04), transparent 22%),
            linear-gradient(180deg, rgba(60, 74, 52, 0.03), transparent 14%),
            linear-gradient(180deg, #f7f2e6 0%, #f2ebdc 100%);
        border: 1px solid rgba(148, 126, 90, 0.28);
        border-radius: 18px;
        box-shadow: 0 18px 30px rgba(0, 0, 0, 0.14), inset 0 0 0 1px rgba(255, 255, 255, 0.32);
    }

    .paper-board::before {
        display: none;
    }

    .paper-board-header {
        padding: 0 0 0.65rem;
        margin-bottom: 0;
    }

    .paper-row {
        display: grid;
        grid-template-columns: minmax(0, 1fr);
        grid-template-areas:
            "person"
            "count"
            "tally"
            "actions";
        align-items: start;
        gap: 0.45rem;
        padding: 0.85rem;

        border-top: 1px solid rgba(148, 126, 90, 0.26);
    }

    .paper-row:not(:last-child) {
        border-bottom: 0;
    }

    .paper-row::before {
        display: none;
    }

    .paper-person-column,
    .paper-count-column,
    .paper-tally-column,
    .paper-actions {
        min-width: 0;
    }

    .paper-person-column {
        grid-area: person;
        align-items: baseline;
        flex-wrap: nowrap;
        gap: 0.2rem 0.45rem;
        min-height: 1.3rem;
    }

    .paper-initials {
        min-width: auto;
        font-size: 0.94rem;
        letter-spacing: 0.02em;
    }

    .paper-name {
        font-size: 0.8rem;
        max-width: 12ch;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .paper-status {
        font-size: 0.62rem;
    }

    .paper-count-column {
        grid-area: count;
        flex-direction: row;
        justify-content: space-between;
        align-items: baseline;
    }

    .paper-total {
        font-size: 1.05rem;
    }

    .paper-kr {
        font-size: 0.68rem;
    }

    .paper-tally-column {
        grid-area: tally;
        width: 100%;
        min-height: 20px;
        padding: 0.05rem 0 0.1rem;
    }

    .paper-actions {
        grid-area: actions;
        align-self: stretch;
        display: grid;
        grid-template-columns: repeat(5, minmax(0, 1fr));
        gap: 0.2rem;
        justify-content: stretch;
    }

    .btn-quick {
        width: 100%;
        min-width: 0;
        padding: 0.28rem 0.35rem;
        font-size: 0.64rem;
        min-height: 1.8rem;
    }

    .swipe-preview {
        padding: 0.22rem 0.45rem;
        gap: 0.25rem;
        max-width: 90%;
    }
}

#blazor-error-ui {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    z-index: 1000;
    padding: 0.5rem 1rem;
    background: #fff3cd;
    color: #664d03;
    border-top: 1px solid #ffecb5;
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.15);
}

#blazor-error-ui .dismiss {
    position: absolute;
    right: 0.75rem;
    top: 0.5rem;
    cursor: pointer;
}
