/* ─── Fonts ─────────────────────────────────────────────────────────────── */
@font-face {
    font-family: 'Brandon Grotesque';
    src: url('fonts/brandon-grotesque-regular.woff2') format('woff2'),
         url('fonts/brandon-grotesque-regular.woff') format('woff');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}
@font-face {
    font-family: 'Brandon Grotesque';
    src: url('fonts/brandon-grotesque-regular-italic.woff2') format('woff2'),
         url('fonts/brandon-grotesque-regular-italic.woff') format('woff');
    font-weight: normal;
    font-style: italic;
    font-display: swap;
}
@font-face {
    font-family: 'Brandon Grotesque';
    src: url('fonts/brandon-grotesque-bold.woff2') format('woff2'),
         url('fonts/brandon-grotesque-bold.woff') format('woff');
    font-weight: bold;
    font-style: normal;
    font-display: swap;
}
@font-face {
    font-family: 'Brandon Grotesque';
    src: url('fonts/brandon-grotesque-bold-italic.woff2') format('woff2'),
         url('fonts/brandon-grotesque-bold-italic.woff') format('woff');
    font-weight: bold;
    font-style: italic;
    font-display: swap;
}

/* ─── Tokens ─────────────────────────────────────────────────────────────── */
:root {
    --primary:        #1f6f78;
    --primary-dark:   #155960;
    --accent:         #d97841;
    --text:           #182026;
    --background:     #f2eee8;
    --card:           #fffcf7;
    --border:         rgba(24, 32, 38, 0.12);
    --support-text:   #5f6b73;
    --okay:           #1d8348;
    --error:          #b33a3a;
    --status-warning: #d97841;
    --shadow-sm:      0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow:         0 4px 6px -1px rgb(0 0 0 / 0.1);
    --shadow-lg:      0 20px 50px rgba(51, 44, 34, 0.12);
    /* legacy compat */
    --brand:          #1f6f78;
    --brand-soft:     #d4ebe5;
    --good:           #1d8348;
    --bad:            #b33a3a;
    --muted:          #5f6b73;
    --line:           rgba(24, 32, 38, 0.12);
}

[data-theme="dark"] {
    --primary:        #3ab5c0;
    --primary-dark:   #2a9aa5;
    --accent:         #e8935f;
    --text:           #f3f4f6;
    --background:     #1a1a1a;
    --card:           #262626;
    --border:         #404040;
    --support-text:   #9ca3af;
    --okay:           #22c55e;
    --error:          #ee4f4f;
    --status-warning: #f5a71f;
    --shadow-sm:      0 1px 2px 0 rgb(255 255 255 / 0.05);
    --shadow:         0 4px 6px -1px rgb(255 255 255 / 0.1);
    --shadow-lg:      0 8px 16px -4px rgb(255 255 255 / 0.15);
    --brand:          #3ab5c0;
    --brand-soft:     #1e3d40;
    --good:           #22c55e;
    --bad:            #ee4f4f;
    --muted:          #9ca3af;
    --line:           #404040;
}

/* ─── Reset ──────────────────────────────────────────────────────────────── */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: "Brandon Grotesque", system-ui, -apple-system, sans-serif;
}

body {
    background: var(--background);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* ─── Layout shell ───────────────────────────────────────────────────────── */
.app-wrapper {
    display: flex;
    width: 100%;
    min-height: 100vh;
    flex-direction: column;
}

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
}

/* ─── Header ─────────────────────────────────────────────────────────────── */
.header {
    padding: 1.5rem 2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    border-bottom: 1px solid var(--border);
    background: var(--card);
    transition: background-color 0.3s ease;
}

.header-brand {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.header-eyebrow {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    color: var(--primary);
    font-weight: bold;
}

.header h1 {
    font-size: 1.6rem;
    font-weight: bold;
    color: var(--text);
    line-height: 1.1;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

/* ─── Theme toggle ───────────────────────────────────────────────────────── */
.theme-toggle {
    background: none;
    border: 1px solid var(--border);
    padding: 0.5rem;
    border-radius: 0.5rem;
    color: var(--text);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}
.theme-toggle:hover {
    background: var(--background);
    border-color: var(--primary);
    color: var(--primary);
}
.theme-toggle svg {
    width: 20px;
    height: 20px;
    stroke: currentColor;
    stroke-width: 2;
}
.icon-sun { display: none; }
.icon-moon { display: none; }
[data-theme="light"] .icon-sun { display: block; }
[data-theme="dark"] .icon-moon { display: block; }

/* ─── Main ───────────────────────────────────────────────────────────────── */
.main {
    flex: 1;
    overflow-x: hidden;
    display: grid;
    align-content: start;
}

.content-layout {
    grid-area: 1 / 1;
    width: 100%;
    max-width: 1400px;
    margin: 0 auto;
    padding: 1.5rem 2rem 3rem;
}

/* ─── Footer ─────────────────────────────────────────────────────────────── */
.footer {
    padding: 1rem 2rem;
    text-align: center;
    border-top: 1px solid var(--border);
    background: var(--card);
    color: var(--support-text);
    font-size: 0.875rem;
    transition: background-color 0.3s ease;
}

/* ─── Cards ──────────────────────────────────────────────────────────────── */
.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 1rem;
    box-shadow: var(--shadow);
    transition: all 0.3s ease;
}

/* ─── Toolbar ────────────────────────────────────────────────────────────── */
.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    justify-content: space-between;
    align-items: flex-end;
    padding: 1.25rem;
    margin-bottom: 1rem;
    animation: slideDown 0.4s ease-out;
}

.field {
    display: grid;
    gap: 6px;
    min-width: min(360px, 100%);
}

.field span {
    font-size: 0.85rem;
    color: var(--support-text);
    font-weight: 600;
}

select {
    border-radius: 0.75rem;
    border: 1px solid var(--border);
    min-height: 44px;
    padding: 0 14px;
    font: inherit;
    font-size: 0.95rem;
    background: var(--background);
    color: var(--text);
    cursor: pointer;
    transition: all 0.2s ease;
}
select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(31, 111, 120, 0.15);
}

.toolbar-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    align-items: center;
}

/* ─── Buttons ────────────────────────────────────────────────────────────── */
.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    text-decoration: none;
    cursor: pointer;
    border-radius: 0.75rem;
    border: 1px solid transparent;
    min-height: 40px;
    padding: 0 1rem;
    font: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    background: var(--primary);
    color: white;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}
.button:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: var(--shadow);
}
.button.secondary {
    background: var(--accent);
    color: white;
}
.button.secondary:hover {
    filter: brightness(0.9);
    transform: translateY(-1px);
    box-shadow: var(--shadow);
}
.button.ghost {
    background: transparent;
    color: var(--text);
    border-color: var(--border);
}
.button.ghost:hover {
    background: var(--background);
    border-color: var(--primary);
    color: var(--primary);
}

.button.danger {
    background: var(--error);
    color: white;
}

.button.danger:hover {
    filter: brightness(0.95);
    transform: translateY(-1px);
    box-shadow: var(--shadow);
}

.button[aria-disabled="true"] {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

/* ─── Stats grid ───────────────────────────────────────────────────────────── */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    margin-bottom: 1rem;
    animation: fadeIn 0.5s ease-out;
}

.stat {
    padding: 1.25rem;
    animation: scaleIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    animation-fill-mode: both;
}

.stat:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.stat-label {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--support-text);
    font-weight: 600;
}

.stat-value {
    margin-top: 0.5rem;
    font-size: 1.75rem;
    font-weight: bold;
    color: var(--text);
    line-height: 1;
}

/* ─── Charts ─────────────────────────────────────────────────────────────── */
.content-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
    margin-bottom: 1rem;
}

.chart-card {
    padding: 1.25rem;
    animation: floatIn 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    animation-fill-mode: both;
}

.chart-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.wide {
    grid-column: 1 / -1;
}

.section-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 12px;
    border-bottom: 1px solid var(--border);
    padding: 1.25rem 1.25rem 0.75rem 1.25rem;
}

.section-head h2 {
    font-size: 1rem;
    font-weight: bold;
    color: var(--text);
}

.section-head p {
    font-size: 0.8rem;
    color: var(--support-text);
}

.chart-host {
    min-height: 280px;
}

.empty {
    display: grid;
    place-items: center;
    min-height: 220px;
    color: var(--support-text);
    border: 2px dashed var(--border);
    border-radius: 0.75rem;
    font-size: 0.9rem;
    animation: fadeIn 0.4s ease-out;
}

.chart-svg {
    width: 100%;
    height: auto;
    overflow: visible;
}

.chart-labels {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 0.875rem;
    margin-top: 0.75rem;
}

.legend-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8rem;
    color: var(--support-text);
}

.legend-swatch {
    width: 10px;
    height: 10px;
    border-radius: 999px;
    flex-shrink: 0;
}

/* ─── Tables ─────────────────────────────────────────────────────────────── */
.tables-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
}

.tables-grid .card {
    padding: 1.25rem;
    animation: floatIn 0.7s cubic-bezier(0.4, 0, 0.2, 1);
    animation-fill-mode: both;
}

.tables-grid .card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

table {
    width: 100%;
    border-collapse: collapse;
}

th {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--support-text);
    font-weight: 600;
    padding: 0.5rem 0.75rem;
    border-bottom: 2px solid var(--border);
    text-align: left;
}

td {
    padding: 0.625rem 0.75rem;
    border-bottom: 1px solid var(--border);
    text-align: left;
    font-size: 0.875rem;
    transition: background 0.15s ease;
}

tbody tr:last-child td {
    border-bottom: 0;
}

tbody tr:hover td {
    background: var(--background);
}

/* ─── Status pills ───────────────────────────────────────────────────────── */
.status-pill {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    padding: 0 0.625rem;
    border-radius: 999px;
    background: var(--brand-soft);
    color: var(--brand);
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    animation: scaleIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.status-pill.done {
    background: #ddf4e5;
    color: var(--okay);
}

.status-pill.error {
    background: #f8dede;
    color: var(--error);
}

[data-theme="dark"] .status-pill.done {
    background: #1a3d2b;
    color: #4ade80;
}
[data-theme="dark"] .status-pill.error {
    background: #3d1a1a;
    color: #f87171;
}

/* ─── Loading overlay ────────────────────────────────────────────────────── */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0);
    backdrop-filter: blur(0px);
    z-index: 9999;
    display: flex;
    opacity: 0;
    pointer-events: none;
    transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.loading-overlay.active {
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    opacity: 1;
    pointer-events: all;
}

.loading-spinner {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 1.5rem;
    flex-grow: 1;
}

.clock {
    height: 80px;
    width: 80px;
    border: 8px solid;
    border-radius: 50%;
    position: relative;
    animation: colors 8s linear infinite;
}

.clock::before {
    height: 10px;
    width: 10px;
    position: absolute;
    top: 50%;
    left: 50%;
    background-color: currentColor;
    border-radius: 50%;
    content: "";
    margin: -5px 0 0 -5px;
    z-index: 1;
}

.hand {
    width: 5px;
    background-color: currentColor;
    border-radius: 3px;
    margin-left: -2.5px;
}

.hand.minute {
    animation: hand 1s linear infinite;
    transform-origin: center bottom;
    position: absolute;
    top: 4px;
    left: 50%;
    height: 27px;
}

.hand.hour {
    animation: hand 12s linear infinite;
    transform-origin: center bottom;
    position: absolute;
    top: 12px;
    left: 50%;
    height: 20px;
}

.loading-text {
    color: white;
    font-size: 1rem;
    font-weight: 600;
    text-align: center;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

/* ─── Animations ─────────────────────────────────────────────────────────── */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes slideDown {
    from { opacity: 0; transform: translateY(-16px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes scaleIn {
    from { opacity: 0; transform: scale(0.92); }
    to   { opacity: 1; transform: scale(1); }
}

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

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.7; }
}

@keyframes hand {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}

@keyframes colors {
    0%   { border-color: #1f6f78; color: #1f6f78; }
    25%  { border-color: #d97841; color: #d97841; }
    50%  { border-color: #5f0f40; color: #5f0f40; }
    75%  { border-color: #00917c; color: #00917c; }
    100% { border-color: #1f6f78; color: #1f6f78; }
}

/* ─── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 960px) {
    .content-grid,
    .tables-grid {
        grid-template-columns: 1fr;
    }
    .header {
        padding: 1rem;
    }
    .content-layout {
        padding: 1rem;
    }
}

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

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

.tab-anim-in {
    z-index: 2;
    animation: slideUpFade 0.35s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

.tab-anim-out {
    z-index: 1;
    pointer-events: none;
    animation: slideDownFade 0.25s ease-in forwards;
}
