:root {
    --bg: #f5f6fa;
    --nav-bg: #1a2332;
    --nav-text: #e2e8f0;
    --card-bg: #ffffff;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --success: #059669;
    --warning: #d97706;
    --error: #dc2626;
    --text: #1e293b;
    --text-muted: #64748b;
    --border: #cbd5e1;
    --radius: 8px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-text-size-adjust: 100%;
}

/* Navigation */
nav {
    background: var(--nav-bg);
    display: flex;
    align-items: center;
    padding: 0 2rem;
    height: 56px;
    gap: 2rem;
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-brand {
    color: #fff;
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.5px;
    flex-shrink: 0;
}

.nav-links { display: flex; gap: 0.5rem; }

.nav-links a {
    color: var(--nav-text);
    text-decoration: none;
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    font-size: 0.875rem;
    transition: background 0.15s;
    white-space: nowrap;
}

.nav-links a:hover { background: rgba(255,255,255,0.1); }
.nav-links a.active { background: var(--primary); color: #fff; }

main {
    /* Use the real estate: 16:9 and 21:9 screens were wasting ~40% width at 1200px. */
    max-width: min(1920px, 95vw);
    margin: 0 auto;
    padding: 1.5rem clamp(1.5rem, 3vw, 3rem);
    width: 100%;
}

h1 { font-size: 1.5rem; margin-bottom: 1.25rem; font-weight: 600; }
h2 { font-size: 1.125rem; margin-bottom: 0.75rem; font-weight: 600; }
h3 { font-size: 0.95rem; margin-bottom: 0.75rem; font-weight: 600; color: var(--text-muted); }

/* Flash messages */
.flash-container { margin-bottom: 1rem; }
.flash {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
}
.flash-success { background: #ecfdf5; color: var(--success); border: 1px solid #a7f3d0; }
.flash-warning { background: #fffbeb; color: var(--warning); border: 1px solid #fde68a; }
.flash-error { background: #fef2f2; color: var(--error); border: 1px solid #fecaca; }

/* Cards */
.cards {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.cards-6 { grid-template-columns: repeat(6, 1fr); }

.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    border: 1px solid var(--border);
}

.card-label { font-size: 0.75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }
.card-value { font-size: 1.5rem; font-weight: 700; margin-top: 0.25rem; white-space: nowrap; cursor: default; }
.card-sub { font-size: 0.8rem; color: var(--text-muted); margin-top: 0.15rem; white-space: nowrap; cursor: default; }

/* Chart grid */
.chart-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
    margin-bottom: 1rem;
    align-items: start;
}

.chart-box {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    border: 1px solid var(--border);
    min-height: 320px;
}

.chart-box canvas { width: 100% !important; max-height: 280px; }
.chart-box-list { max-height: 420px; overflow-y: auto; }

/* Ranked list (inline bar visualization) */
.ranked-list { display: flex; flex-direction: column; gap: 0.35rem; }
.ranked-row {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.35rem 0;
}
.ranked-rank {
    flex-shrink: 0;
    width: 1.5rem;
    height: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: #f1f5f9;
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--text-muted);
}
.ranked-info { flex: 1; min-width: 0; }
.ranked-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 0.5rem;
    margin-bottom: 0.2rem;
}
.ranked-name {
    font-size: 0.8rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.ranked-value {
    font-size: 0.8rem;
    font-weight: 700;
    white-space: nowrap;
    flex-shrink: 0;
}
.ranked-bar-track {
    height: 6px;
    background: #f1f5f9;
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 0.15rem;
}
.ranked-bar-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.4s ease;
}
.ranked-share {
    font-size: 0.65rem;
    color: var(--text-muted);
}

/* Filters */
.filters {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.filters select, .filters input {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.875rem;
    background: var(--card-bg);
    max-width: 100%;
}

/* Table */
.table-wrap {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    border: 1px solid var(--border);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
th {
    text-align: left;
    padding: 0.75rem;
    background: #f8fafc;
    border-bottom: 2px solid var(--border);
    font-weight: 600;
    white-space: nowrap;
    color: var(--text-muted);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--primary); }
th.sort-asc::after { content: ' \25B2'; font-size: 0.65rem; }
th.sort-desc::after { content: ' \25BC'; font-size: 0.65rem; }

td { padding: 0.6rem 0.75rem; border-bottom: 1px solid var(--border); }
tr:hover { background: #f8fafc; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }

.total-row { background: #f1f5f9 !important; font-weight: 600; }

/* Badges */
.badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}
.badge-group { background: #dbeafe; color: #1e40af; }
.badge-individual { background: #fce7f3; color: #9d174d; }
.badge-bonus { background: #d1fae5; color: #065f46; }

/* Buttons */
.btn {
    padding: 0.5rem 1.25rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--card-bg);
    cursor: pointer;
    font-size: 0.875rem;
    transition: all 0.15s;
}
.btn:hover { background: #f8fafc; }
.btn-primary {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}
.btn-primary:hover { background: var(--primary-hover); }

/* Entry page */
.entry-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.5rem;
}

.entry-section {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    border: 1px solid var(--border);
}

.entry-section p { color: var(--text-muted); font-size: 0.875rem; margin-bottom: 1rem; }
.entry-section code { background: #f1f5f9; padding: 0.15rem 0.4rem; border-radius: 4px; font-size: 0.8rem; }
.section-divider { border: none; border-top: 1px solid var(--border); margin: 1.25rem 0; }

.form-group { margin-bottom: 1rem; }
.form-group label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}
.form-group input, .form-group select {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.875rem;
}
.form-group input:focus, .form-group select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }

/* Pacing section */
.pacing-container { padding: 0.5rem 0; }
.pacing-metrics { margin-bottom: 1.25rem; }
.pacing-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 1rem;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
    flex-wrap: wrap;
}
.pacing-row.highlight {
    background: #eff6ff;
    margin: 0 -1.25rem;
    padding: 0.65rem 1.25rem;
    border-radius: var(--radius);
    border-bottom: none;
    font-weight: 600;
}
.pacing-label { color: var(--text-muted); }
.pacing-value { font-weight: 600; font-variant-numeric: tabular-nums; }

.progress-section { margin-top: 0.5rem; }
.progress-label { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 0.35rem; }
.progress-bar {
    height: 10px;
    background: var(--border);
    border-radius: 5px;
    overflow: hidden;
    margin-bottom: 0.35rem;
}
.progress-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 5px;
    transition: width 0.5s ease;
}

/* Analytics section */
.analytics-section {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    border: 1px solid var(--border);
    margin-top: 1rem;
    overflow-x: auto;
}
.analytics-section .table-wrap { box-shadow: none; border: none; }

/* Product tags */
.product-tags { display: flex; gap: 0.25rem; flex-wrap: wrap; }
.tag {
    display: inline-block;
    padding: 0.1rem 0.4rem;
    background: #f1f5f9;
    border-radius: 4px;
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Dark mode toggle button */
.dark-toggle {
    margin-left: auto;
    background: none;
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 50%;
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.15s;
}
.dark-toggle:hover { background: rgba(255,255,255,0.1); }
.dark-toggle-icon { font-size: 1.1rem; line-height: 1; }

/* ===== DARK MODE (Dark Reader style) ===== */
html.dark {
    --bg: #181a1b;
    --nav-bg: #1b1d1e;
    --card-bg: #232527;
    --primary: #5a93cc;
    --primary-hover: #4a80b8;
    --text: #d1cdc7;
    --text-muted: #a8a095;
    --border: #3c3f41;
    --success: #5ea66a;
    --warning: #c4a33c;
    --error: #c75050;
}

html.dark th { background: #2a2c2e; }
html.dark tr:hover { background: #2e3133; }
html.dark .total-row { background: #2a2c2e !important; }
html.dark .badge-group { background: #2a3544; color: #8ab4d6; }
html.dark .badge-individual { background: #3a2838; color: #d4a0c4; }
html.dark .badge-bonus { background: #263830; color: #8fc79d; }
html.dark .tag { background: #2e3133; color: var(--text-muted); }
html.dark .entry-section code { background: #2e3133; color: var(--text-muted); }
html.dark .ranked-rank { background: #2e3133; color: var(--text-muted); }
html.dark .ranked-bar-track { background: #2e3133; }
html.dark .pacing-row.highlight { background: #2a3338; }
html.dark .flash-success { background: #1e2e22; color: var(--success); border-color: #2e4433; }
html.dark .flash-warning { background: #2e2a1a; color: var(--warning); border-color: #4a4020; }
html.dark .flash-error { background: #2e1e1e; color: var(--error); border-color: #4a2828; }
html.dark .form-group input,
html.dark .form-group select,
html.dark .filters select,
html.dark .filters input {
    background: #181a1b;
    color: var(--text);
    border-color: var(--border);
}
html.dark .btn { background: var(--card-bg); color: var(--text); }
html.dark .btn:hover { background: #2e3133; }
html.dark .btn-primary { background: var(--primary); color: #e8e6e3; border-color: var(--primary); }
html.dark .btn-primary:hover { background: var(--primary-hover); }
html.dark .nav-links a.active { background: var(--primary); color: #e8e6e3; }

/* ===== RESPONSIVE ===== */

/* Large tablets / small laptops (<=1024px) */
@media (max-width: 1024px) {
    .cards-6 { grid-template-columns: repeat(3, 1fr); }
}

/* Tablets (<=768px) */
@media (max-width: 768px) {
    nav { padding: 0 1rem; gap: 1rem; }
    main { padding: 1rem; }

    .cards { grid-template-columns: repeat(2, 1fr); }
    .cards-6 { grid-template-columns: repeat(2, 1fr); }

    .chart-grid { grid-template-columns: 1fr; }
    .chart-box { min-height: 280px; }

    .entry-grid { grid-template-columns: 1fr; }
    .form-row { grid-template-columns: 1fr; }

    .filters { flex-direction: column; }
    .filters select, .filters input { width: 100%; }

    .btn { width: 100%; text-align: center; }
}

/* Phones (<=480px) */
@media (max-width: 480px) {
    nav {
        flex-wrap: wrap;
        height: auto;
        padding: 0.75rem 1rem;
        gap: 0.5rem;
    }
    .nav-links { width: 100%; justify-content: center; }
    .nav-links a { padding: 0.4rem 0.75rem; font-size: 0.8rem; }

    main { padding: 0.75rem; }
    h1 { font-size: 1.25rem; }

    .cards { grid-template-columns: 1fr 1fr; gap: 0.5rem; }
    .cards-6 { grid-template-columns: 1fr 1fr; }
    .card { padding: 0.75rem; }
    .card-label { font-size: 0.65rem; }
    .card-value { font-size: 1.1rem; }
    .card-sub { font-size: 0.7rem; }

    .chart-grid { gap: 0.75rem; }
    .chart-box { padding: 0.75rem; min-height: 250px; }
    .chart-box canvas { max-height: 220px; }

    table { font-size: 0.75rem; }
    th { padding: 0.5rem; font-size: 0.7rem; }
    td { padding: 0.4rem 0.5rem; }

    .entry-section { padding: 1rem; }

    .pacing-row { font-size: 0.8rem; }
    .analytics-section { padding: 0.75rem; }
}

/* --- nav user badge (2026-07-10) --- */
.nav-user { display: flex; align-items: center; gap: 12px; margin-left: auto; }
.nav-user-name { font-size: 13px; color: #cbd5e0; padding: 4px 10px;
                 background: rgba(255,255,255,0.08); border-radius: 12px; }
.nav-signout { color: #cbd5e0 !important; font-size: 13px; text-decoration: none;
               padding: 4px 10px; border-radius: 6px; }
.nav-signout:hover { background: rgba(255,255,255,0.12); color: #fff !important; }
:root.dark .nav-user-name { background: rgba(255,255,255,0.06); }

/* --- loading skeleton (2026-07-10) --- */
body.is-loading main::after {
  content: 'Loading…';
  position: fixed; top: 60px; right: 20px;
  background: rgba(44,82,130,.92); color: #fff;
  padding: 6px 14px; border-radius: 20px;
  font-size: 12px; letter-spacing: .5px;
  z-index: 999; pointer-events: none;
  animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .5; } }
:root.dark body.is-loading main::after { background: rgba(66,153,225,.9); }
