/*
 * Layout — sidebar, topbar, grid, cards.
 * The "chrome" every dashboard page inherits.
 */

/* ---------------------------------------------------------------------------
 * App shell
 * ------------------------------------------------------------------------- */
.app {
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
    grid-template-rows: var(--topbar-h) 1fr;
    grid-template-areas:
        "sidebar topbar"
        "sidebar main";
    height: 100vh;
    position: relative;
    z-index: 2;
}

/* ---------------------------------------------------------------------------
 * Sidebar
 * ------------------------------------------------------------------------- */
.sidebar {
    grid-area: sidebar;
    background: var(--surface-1);
    border-right: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.brand {
    padding: var(--sp-5) var(--sp-5);
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    gap: var(--sp-3);
}
.brand__mark {
    width: 28px;
    height: 28px;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-gold));
    display: grid;
    place-items: center;
    font-family: var(--font-display);
    font-weight: 700;
    font-style: italic;
    font-size: 17px;
    color: var(--text-inverse);
    box-shadow: var(--shadow-sm);
}
.brand__text {
    font-family: var(--font-display);
    font-size: var(--fs-lg);
    font-weight: 500;
    letter-spacing: -0.01em;
}
.brand__text em {
    font-style: italic;
    color: var(--accent-warm);
}
.brand__text::after {
    content: 'Intelligence';
    display: block;
    font-family: var(--font-sans);
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.2em;
    color: var(--text-tertiary);
    font-weight: 500;
    margin-top: 2px;
}

.nav {
    padding: var(--sp-3) 0;
    flex: 1;
}
.nav__group {
    margin-bottom: var(--sp-4);
}
.nav__group-title {
    padding: var(--sp-2) var(--sp-5) var(--sp-1);
    font-size: 10px;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--text-tertiary);
    font-weight: 600;
}
.nav__item {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    padding: var(--sp-2) var(--sp-5);
    font-size: var(--fs-base);
    color: var(--text-secondary);
    border-left: 2px solid transparent;
    transition: all var(--dur-fast) var(--ease-out);
    cursor: pointer;
    position: relative;
}
.nav__item:hover {
    color: var(--text-primary);
    background: var(--surface-2);
}
.nav__item.is-active {
    color: var(--text-primary);
    background: linear-gradient(90deg, var(--accent-primary-dim), transparent);
    border-left-color: var(--accent-primary);
    font-weight: 500;
}
.nav__item svg {
    width: 16px;
    height: 16px;
    stroke-width: 1.5;
    flex-shrink: 0;
}
.nav__item-badge {
    margin-left: auto;
    font-size: 10px;
    padding: 1px 6px;
    border-radius: 999px;
    background: var(--accent-primary);
    color: var(--text-inverse);
    font-weight: 600;
    min-width: 18px;
    text-align: center;
}

.sidebar__footer {
    padding: var(--sp-4) var(--sp-5);
    border-top: 1px solid var(--border-subtle);
    font-size: var(--fs-xs);
    color: var(--text-tertiary);
    display: flex;
    align-items: center;
    gap: var(--sp-2);
}
.live-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--positive);
    box-shadow: 0 0 8px var(--positive);
    animation: pulse-dot 2s infinite;
}
.live-dot.is-offline {
    background: var(--negative);
    box-shadow: 0 0 8px var(--negative);
    animation: none;
}
@keyframes pulse-dot {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.6; transform: scale(0.8); }
}

/* ---------------------------------------------------------------------------
 * Topbar
 * ------------------------------------------------------------------------- */
.topbar {
    grid-area: topbar;
    background: var(--surface-1);
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    padding: 0 var(--sp-6);
    gap: var(--sp-4);
}
.topbar__title {
    font-family: var(--font-display);
    font-size: var(--fs-lg);
    font-weight: 500;
    letter-spacing: -0.01em;
}
.topbar__title small {
    font-family: var(--font-sans);
    font-size: var(--fs-sm);
    color: var(--text-tertiary);
    margin-left: var(--sp-3);
    font-weight: 400;
}
.topbar__spacer { flex: 1; }

.topbar__actions {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
}

/* ---------------------------------------------------------------------------
 * Date range picker
 * ------------------------------------------------------------------------- */
.date-range {
    display: flex;
    align-items: center;
    background: var(--surface-2);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    padding: 2px;
    gap: 2px;
}
.date-range__preset {
    padding: 6px 12px;
    font-size: var(--fs-sm);
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    font-weight: 500;
    transition: all var(--dur-fast);
}
.date-range__preset:hover {
    color: var(--text-primary);
    background: var(--surface-3);
}
.date-range__preset.is-active {
    background: var(--surface-0);
    color: var(--text-primary);
    box-shadow: inset 0 0 0 1px var(--border-default);
}
.date-range__custom {
    padding: 6px 12px;
    font-size: var(--fs-sm);
    color: var(--text-tertiary);
    border-left: 1px solid var(--border-default);
    margin-left: 2px;
    display: flex;
    align-items: center;
    gap: 6px;
}

/* ---------------------------------------------------------------------------
 * Main content
 * ------------------------------------------------------------------------- */
.main {
    grid-area: main;
    overflow-y: auto;
    padding: var(--sp-6);
    scroll-behavior: smooth;
}
.main__inner {
    max-width: var(--content-max);
    margin: 0 auto;
}

/* ---------------------------------------------------------------------------
 * Grid system — explicit, no gymnastics
 * ------------------------------------------------------------------------- */
.grid {
    display: grid;
    gap: var(--sp-4);
    margin-bottom: var(--sp-4);
}
.grid--kpi    { grid-template-columns: repeat(4, 1fr); }
.grid--8-4    { grid-template-columns: 2fr 1fr; }
.grid--6-6    { grid-template-columns: 1fr 1fr; }
.grid--4-8    { grid-template-columns: 1fr 2fr; }
.grid--3-col  { grid-template-columns: repeat(3, 1fr); }
.grid--full   { grid-template-columns: 1fr; }

@media (max-width: 1180px) {
    .grid--kpi    { grid-template-columns: repeat(2, 1fr); }
    .grid--8-4,
    .grid--4-8,
    .grid--6-6,
    .grid--3-col  { grid-template-columns: 1fr; }
}

/* ---------------------------------------------------------------------------
 * Card — the universal container
 * ------------------------------------------------------------------------- */
.card {
    background: var(--surface-1);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: var(--sp-5);
    position: relative;
    overflow: hidden;
    transition: border-color var(--dur-med) var(--ease-out);
}
.card:hover {
    border-color: var(--border-default);
}
.card--elevated {
    background: var(--surface-2);
}
.card--accent {
    border-color: var(--border-accent);
    background:
        linear-gradient(135deg, var(--accent-primary-dim), transparent 60%),
        var(--surface-1);
}

.card__header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--sp-3);
    margin-bottom: var(--sp-4);
}
.card__title {
    font-family: var(--font-sans);
    font-size: var(--fs-sm);
    font-weight: 500;
    color: var(--text-secondary);
    letter-spacing: 0.02em;
    display: flex;
    align-items: center;
    gap: var(--sp-2);
}
.card__title-sub {
    font-size: var(--fs-xs);
    color: var(--text-tertiary);
    font-weight: 400;
    margin-top: 2px;
}
.card__menu {
    color: var(--text-tertiary);
    padding: 4px;
    border-radius: var(--radius-sm);
    transition: all var(--dur-fast);
    display: flex;
}
.card__menu:hover {
    color: var(--text-primary);
    background: var(--surface-2);
}

/* ---------------------------------------------------------------------------
 * KPI stat card — the most-used component
 * ------------------------------------------------------------------------- */
.kpi {
    background: var(--surface-1);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: var(--sp-5);
    position: relative;
    overflow: hidden;
    min-height: 140px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    transition: all var(--dur-med) var(--ease-out);
}
.kpi::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, transparent, var(--accent-primary-dim) 180%);
    opacity: 0;
    transition: opacity var(--dur-med) var(--ease-out);
    pointer-events: none;
}
.kpi:hover {
    border-color: var(--border-default);
    transform: translateY(-2px);
}
.kpi:hover::before { opacity: 1; }

.kpi__label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.16em;
    color: var(--text-tertiary);
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: var(--sp-2);
}
.kpi__label-icon {
    width: 12px; height: 12px;
    stroke-width: 1.8;
}
.kpi__value {
    font-family: var(--font-display);
    font-variation-settings: 'opsz' 144;
    font-size: var(--fs-4xl);
    font-weight: 400;
    line-height: 1;
    letter-spacing: -0.04em;
    color: var(--text-primary);
    font-feature-settings: 'tnum' 1, 'lnum' 1;
    margin-top: var(--sp-4);
    display: flex;
    align-items: baseline;
    gap: 4px;
}
.kpi__value-unit {
    font-size: var(--fs-lg);
    color: var(--text-tertiary);
    font-weight: 300;
}
.kpi__delta {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    font-size: var(--fs-sm);
    margin-top: var(--sp-3);
    font-family: var(--font-mono);
    font-weight: 500;
}
.kpi__delta-pill {
    padding: 2px 6px;
    border-radius: 3px;
    font-size: var(--fs-xs);
    font-weight: 600;
}
.kpi__delta.is-up .kpi__delta-pill    { background: var(--positive-dim); color: var(--positive); }
.kpi__delta.is-down .kpi__delta-pill  { background: var(--negative-dim); color: var(--negative); }
.kpi__delta.is-flat .kpi__delta-pill  { background: var(--surface-3); color: var(--text-tertiary); }
.kpi__delta-label {
    color: var(--text-tertiary);
    font-family: var(--font-sans);
}

.kpi__spark {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 40px;
    opacity: 0.7;
    pointer-events: none;
}

/* ---------------------------------------------------------------------------
 * Chart containers
 * ------------------------------------------------------------------------- */
.chart {
    width: 100%;
    height: 320px;
    position: relative;
}
.chart--tall   { height: 420px; }
.chart--short  { height: 220px; }
.chart__loading {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    background: rgba(10, 9, 8, 0.7);
    backdrop-filter: blur(4px);
    z-index: 10;
    transition: opacity var(--dur-med);
}
.chart__loading.is-hidden {
    opacity: 0;
    pointer-events: none;
}

/* Skeleton shimmer for loading */
.shimmer {
    background: linear-gradient(
        90deg,
        var(--surface-2) 0%,
        var(--surface-3) 50%,
        var(--surface-2) 100%
    );
    background-size: 200% 100%;
    animation: shimmer 1.4s linear infinite;
    border-radius: var(--radius-sm);
}
@keyframes shimmer {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ---------------------------------------------------------------------------
 * Tables
 * ------------------------------------------------------------------------- */
.table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: var(--fs-sm);
}
.table thead th {
    padding: var(--sp-2) var(--sp-3);
    text-align: left;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--text-tertiary);
    font-weight: 600;
    border-bottom: 1px solid var(--border-subtle);
    white-space: nowrap;
    position: sticky;
    top: 0;
    background: var(--surface-1);
    z-index: 1;
}
.table thead th.is-numeric,
.table tbody td.is-numeric {
    text-align: right;
    font-family: var(--font-mono);
    font-feature-settings: 'tnum' 1;
}
.table tbody td {
    padding: var(--sp-3);
    border-bottom: 1px solid var(--border-subtle);
    color: var(--text-primary);
    vertical-align: middle;
}
.table tbody tr {
    transition: background var(--dur-fast);
}
.table tbody tr:hover {
    background: var(--surface-2);
}
.table tbody tr:last-child td {
    border-bottom: none;
}
.table__rank {
    display: inline-block;
    width: 22px;
    height: 22px;
    line-height: 22px;
    text-align: center;
    font-family: var(--font-display);
    font-size: var(--fs-sm);
    color: var(--text-tertiary);
    font-feature-settings: 'tnum' 1, 'lnum' 1;
}
.table__rank--top {
    color: var(--accent-gold);
    font-weight: 600;
}

/* Inline trend bar in table rows */
.trend-bar {
    height: 4px;
    background: var(--surface-3);
    border-radius: 2px;
    overflow: hidden;
    min-width: 60px;
    display: inline-block;
    vertical-align: middle;
}
.trend-bar__fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-warm), var(--accent-primary));
    border-radius: 2px;
    transition: width var(--dur-slow) var(--ease-out);
}

/* ---------------------------------------------------------------------------
 * Buttons
 * ------------------------------------------------------------------------- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: var(--sp-2);
    padding: 7px 14px;
    font-size: var(--fs-sm);
    font-weight: 500;
    color: var(--text-primary);
    background: var(--surface-2);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--dur-fast) var(--ease-out);
    white-space: nowrap;
}
.btn:hover {
    background: var(--surface-3);
    border-color: var(--border-strong);
}
.btn svg {
    width: 14px;
    height: 14px;
    stroke-width: 1.8;
}
.btn--primary {
    background: var(--accent-primary);
    color: var(--text-inverse);
    border-color: var(--accent-primary);
    font-weight: 600;
}
.btn--primary:hover {
    background: #ff7d4e;
    border-color: #ff7d4e;
}
.btn--ghost {
    background: transparent;
    border-color: transparent;
    color: var(--text-secondary);
}
.btn--ghost:hover {
    background: var(--surface-2);
    color: var(--text-primary);
}
.btn--icon {
    padding: 7px;
    width: 32px;
    height: 32px;
    justify-content: center;
}

/* ---------------------------------------------------------------------------
 * Insight card — the "daily brief" pattern
 * ------------------------------------------------------------------------- */
.insight {
    display: flex;
    gap: var(--sp-4);
    padding: var(--sp-4);
    background: var(--surface-2);
    border: 1px solid var(--border-subtle);
    border-left: 2px solid var(--accent-primary);
    border-radius: var(--radius-md);
    transition: all var(--dur-med);
}
.insight:hover {
    border-color: var(--border-default);
    border-left-color: var(--accent-primary);
    transform: translateX(2px);
}
.insight--positive { border-left-color: var(--positive); }
.insight--warning  { border-left-color: var(--warning); }
.insight--info     { border-left-color: var(--info); }

.insight__icon {
    width: 32px; height: 32px;
    border-radius: var(--radius-md);
    background: var(--accent-primary-dim);
    display: grid;
    place-items: center;
    color: var(--accent-primary);
    flex-shrink: 0;
}
.insight--positive .insight__icon { background: var(--positive-dim); color: var(--positive); }
.insight--warning  .insight__icon { background: var(--warning-dim);  color: var(--warning); }
.insight--info     .insight__icon { background: var(--info-dim);     color: var(--info); }

.insight__body { flex: 1; min-width: 0; }
.insight__title {
    font-size: var(--fs-md);
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 2px;
}
.insight__desc {
    font-size: var(--fs-sm);
    color: var(--text-secondary);
    line-height: 1.5;
}
.insight__action {
    margin-top: var(--sp-2);
    font-size: var(--fs-sm);
    color: var(--accent-warm);
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.insight__action:hover { color: var(--accent-primary); gap: 8px; }

/* ---------------------------------------------------------------------------
 * Badges & pills
 * ------------------------------------------------------------------------- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 7px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    border-radius: 3px;
    background: var(--surface-3);
    color: var(--text-secondary);
}
.badge--star     { background: rgba(212, 163, 84, 0.15);  color: var(--accent-gold); }
.badge--puzzle   { background: rgba(108, 163, 199, 0.15); color: var(--info); }
.badge--plow     { background: rgba(224, 181, 74, 0.15);  color: var(--warning); }
.badge--dog      { background: rgba(214, 107, 90, 0.15);  color: var(--negative); }
.badge--live     {
    background: var(--positive-dim);
    color: var(--positive);
    position: relative;
    padding-left: 14px;
}
.badge--live::before {
    content: '';
    position: absolute;
    left: 6px; top: 50%;
    transform: translateY(-50%);
    width: 4px; height: 4px;
    border-radius: 50%;
    background: var(--positive);
    box-shadow: 0 0 6px var(--positive);
    animation: pulse-dot 1.6s infinite;
}

/* ---------------------------------------------------------------------------
 * Food type dot (veg/non-veg indicator — important in Indian context)
 * ------------------------------------------------------------------------- */
.food-dot {
    display: inline-block;
    width: 10px; height: 10px;
    border-radius: 1px;
    border: 1.5px solid currentColor;
    position: relative;
    margin-right: 6px;
    vertical-align: middle;
}
.food-dot::after {
    content: '';
    position: absolute;
    inset: 2px;
    border-radius: 50%;
    background: currentColor;
}
.food-dot--veg     { color: #4caf50; }
.food-dot--non-veg { color: #d32f2f; }
.food-dot--egg     { color: var(--accent-gold); }

/* ---------------------------------------------------------------------------
 * Empty state
 * ------------------------------------------------------------------------- */
.empty {
    padding: var(--sp-10);
    text-align: center;
    color: var(--text-tertiary);
}
.empty__icon {
    width: 48px; height: 48px;
    margin: 0 auto var(--sp-3);
    color: var(--text-tertiary);
    opacity: 0.5;
}
.empty__title {
    font-family: var(--font-display);
    font-size: var(--fs-lg);
    color: var(--text-secondary);
    margin-bottom: var(--sp-2);
}
.empty__desc {
    font-size: var(--fs-sm);
    max-width: 320px;
    margin: 0 auto;
    line-height: 1.6;
}

/* ---------------------------------------------------------------------------
 * Toast notifications
 * ------------------------------------------------------------------------- */
.toast-container {
    position: fixed;
    top: calc(var(--topbar-h) + var(--sp-3));
    right: var(--sp-5);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: var(--sp-2);
    pointer-events: none;
}
.toast {
    background: var(--surface-2);
    border: 1px solid var(--border-default);
    border-left: 3px solid var(--accent-primary);
    border-radius: var(--radius-md);
    padding: var(--sp-3) var(--sp-4);
    min-width: 280px;
    max-width: 420px;
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: flex-start;
    gap: var(--sp-3);
    pointer-events: auto;
    animation: toast-in var(--dur-med) var(--ease-spring);
}
@keyframes toast-in {
    from { transform: translateX(120%); opacity: 0; }
    to   { transform: translateX(0); opacity: 1; }
}
.toast--success { border-left-color: var(--positive); }
.toast--error   { border-left-color: var(--negative); }

/* ---------------------------------------------------------------------------
 * Page entry animation — one well-orchestrated reveal
 * ------------------------------------------------------------------------- */
.reveal {
    opacity: 0;
    transform: translateY(12px);
    animation: reveal var(--dur-slow) var(--ease-out) forwards;
}
.reveal:nth-child(1) { animation-delay: 0ms; }
.reveal:nth-child(2) { animation-delay: 40ms; }
.reveal:nth-child(3) { animation-delay: 80ms; }
.reveal:nth-child(4) { animation-delay: 120ms; }
.reveal:nth-child(5) { animation-delay: 160ms; }
.reveal:nth-child(6) { animation-delay: 200ms; }
.reveal:nth-child(7) { animation-delay: 240ms; }
.reveal:nth-child(8) { animation-delay: 280ms; }
@keyframes reveal {
    to { opacity: 1; transform: translateY(0); }
}

/* =========================================================================
