:root {
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: #172033;
    background: #f6f7fb;
}
* { box-sizing: border-box; }
body { margin: 0; background: #f6f7fb; }
a { color: inherit; }
.container { width: min(1120px, calc(100% - 32px)); margin: 0 auto; }
.topbar { background: #fff; border-bottom: 1px solid #e7e9f0; }
.topbar-inner { min-height: 64px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.brand { font-weight: 800; text-decoration: none; }
.link-button { border: 0; background: transparent; cursor: pointer; font: inherit; color: #4c5870; }
.page { padding: 40px 0; }
.hero { background: #fff; border: 1px solid #e7e9f0; border-radius: 18px; padding: 28px; margin-bottom: 24px; }
.hero h1 { margin: 8px 0 8px; font-size: clamp(28px, 5vw, 42px); }
.hero p { max-width: 720px; color: #657088; line-height: 1.6; margin-bottom: 0; }
.eyebrow { font-size: 12px; font-weight: 800; letter-spacing: .12em; color: #657088; }
.grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.card { background: #fff; border: 1px solid #e7e9f0; border-radius: 16px; padding: 20px; min-height: 120px; display: flex; flex-direction: column; justify-content: space-between; }
.card span { color: #657088; }
.card strong { font-size: 18px; }
.auth-card { width: min(440px, 100%); margin: 48px auto; padding: 28px; border: 1px solid #e7e9f0; border-radius: 18px; background: #fff; }
.auth-card form { display: grid; gap: 10px; }
.auth-card input { width: 100%; border: 1px solid #ccd2df; border-radius: 10px; padding: 11px 12px; font: inherit; }
.primary { margin-top: 8px; border: 0; border-radius: 10px; padding: 12px 16px; font-weight: 700; cursor: pointer; background: #172033; color: #fff; }
.alert { background: #fff2f2; border: 1px solid #f2caca; padding: 10px 12px; border-radius: 10px; margin-bottom: 14px; }
@media (max-width: 800px) { .grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 520px) { .grid { grid-template-columns: 1fr; } .page { padding-top: 24px; } }
.topnav { display: flex; align-items: center; gap: 16px; }
.topnav a { text-decoration: none; color: #4c5870; }
.compact-hero h1 { font-size: clamp(26px, 4vw, 36px); }
.message-stack { display: grid; gap: 8px; margin-bottom: 18px; }
.notice { background: #fff; border: 1px solid #dfe3eb; padding: 12px 14px; border-radius: 10px; }
.notice-success { border-color: #b9dec8; background: #f1fbf5; }
.notice-error { border-color: #f2caca; background: #fff2f2; }
.summary-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 18px; }
.mini-card { background: #fff; border: 1px solid #e7e9f0; border-radius: 14px; padding: 16px; display: grid; gap: 8px; }
.mini-card span, .muted { color: #657088; font-size: 13px; }
.table-wrap { overflow-x: auto; background: #fff; border: 1px solid #e7e9f0; border-radius: 16px; }
.data-table { width: 100%; border-collapse: collapse; min-width: 1080px; }
.data-table th, .data-table td { text-align: left; vertical-align: top; padding: 16px; border-bottom: 1px solid #edf0f5; }
.data-table th { font-size: 12px; letter-spacing: .04em; text-transform: uppercase; color: #657088; background: #fafbfc; }
.inline-form { display: flex; gap: 8px; align-items: center; }
.top-gap { margin-top: 10px; }
.inline-form input, .hpp-form input { width: 100%; border: 1px solid #ccd2df; border-radius: 9px; padding: 9px 10px; font: inherit; }
.hpp-form { display: grid; gap: 8px; min-width: 220px; }
.hpp-form label { display: grid; gap: 4px; font-size: 12px; color: #657088; }
.secondary { border: 1px solid #ccd2df; background: #fff; border-radius: 9px; padding: 9px 10px; cursor: pointer; white-space: nowrap; }
.small-button { padding: 10px 12px; }
.status { display: inline-block; margin-top: 6px; border-radius: 999px; padding: 4px 8px; font-size: 11px; font-weight: 700; }
.status-ok { background: #eaf8ef; color: #22623a; }
.status-warning { background: #fff6df; color: #805b00; }
.history { margin-top: 8px; font-size: 12px; color: #657088; }
.history ul { padding-left: 18px; margin-bottom: 0; }
.empty-state { background: #fff; border: 1px solid #e7e9f0; border-radius: 16px; padding: 24px; }
.empty-cell { color: #657088; text-align: center !important; padding: 30px !important; }
@media (max-width: 800px) { .summary-row { grid-template-columns: repeat(2, 1fr); } .topnav { gap: 10px; font-size: 14px; } }
@media (max-width: 520px) { .summary-row { grid-template-columns: 1fr; } .topbar-inner { align-items: flex-start; padding: 14px 0; } .topnav { flex-wrap: wrap; justify-content: flex-end; } }
.two-column-layout { display: grid; grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); gap: 18px; margin-bottom: 24px; }
.panel { background: #fff; border: 1px solid #e7e9f0; border-radius: 16px; padding: 20px; }
.panel h2, .section-heading h2 { margin-top: 0; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid.single-column { grid-template-columns: 1fr; }
.form-grid label { display: grid; gap: 6px; font-size: 13px; color: #4c5870; }
.form-grid input, .form-grid select { width: 100%; border: 1px solid #ccd2df; border-radius: 9px; padding: 10px 11px; font: inherit; background: #fff; color: #172033; }
.form-grid small { color: #7b8497; line-height: 1.4; }
.full-span { grid-column: 1 / -1; }
.section-block { margin-top: 24px; }
.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 16px; margin-bottom: 12px; }
.expense-table { min-width: 900px; }
@media (max-width: 800px) { .two-column-layout { grid-template-columns: 1fr; } }
@media (max-width: 620px) { .form-grid { grid-template-columns: 1fr; } .full-span { grid-column: auto; } .section-heading { align-items: flex-start; flex-direction: column; } }

/* Dashboard */
.dashboard-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 18px; }
.dashboard-head h1 { margin: 6px 0 0; font-size: clamp(30px, 5vw, 44px); letter-spacing: -.03em; }
.dashboard-subtitle { margin: 8px 0 0; }
.dashboard-store-pill { min-width: 190px; padding: 12px 14px; border: 1px solid #e7e9f0; background: #fff; border-radius: 14px; display: grid; gap: 4px; }
.dashboard-store-pill span { color: #657088; font-size: 12px; }
.dashboard-controls { display: grid; gap: 16px; margin-bottom: 24px; }
.mode-switch { display: inline-flex; width: fit-content; padding: 4px; gap: 4px; border: 1px solid #dfe3eb; border-radius: 12px; background: #f6f7fb; }
.mode-tab { min-width: 116px; text-align: center; padding: 10px 16px; border-radius: 9px; text-decoration: none; font-size: 13px; font-weight: 800; letter-spacing: .08em; color: #657088; }
.mode-tab.is-active { background: #172033; color: #fff; box-shadow: 0 6px 14px rgba(23,32,51,.12); }
.period-presets { display: flex; flex-wrap: wrap; gap: 8px; }
.period-chip { padding: 8px 12px; border: 1px solid #dfe3eb; border-radius: 999px; text-decoration: none; color: #4c5870; background: #fff; font-size: 13px; }
.period-chip.is-active { border-color: #172033; color: #172033; font-weight: 700; }
.custom-period-form { display: flex; align-items: end; gap: 10px; flex-wrap: wrap; padding-top: 4px; }
.custom-period-form label { display: grid; gap: 5px; color: #657088; font-size: 12px; }
.custom-period-form input { min-width: 150px; border: 1px solid #ccd2df; border-radius: 9px; padding: 9px 10px; font: inherit; color: #172033; background: #fff; }
.dashboard-mode-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 18px; margin: 28px 0 14px; }
.dashboard-mode-heading h2 { margin: 6px 0 4px; font-size: clamp(22px, 4vw, 30px); }
.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.metric-card { min-height: 146px; background: #fff; border: 1px solid #e7e9f0; border-radius: 16px; padding: 18px; display: flex; flex-direction: column; justify-content: space-between; gap: 10px; }
.metric-card strong { font-size: clamp(21px, 3vw, 29px); line-height: 1.1; letter-spacing: -.025em; overflow-wrap: anywhere; }
.metric-card small { color: #7b8497; line-height: 1.35; }
.metric-label { color: #657088; font-size: 13px; font-weight: 650; }
.metric-card-primary { background: #172033; border-color: #172033; color: #fff; }
.metric-card-primary .metric-label, .metric-card-primary small { color: #c9d0df; }
.dashboard-detail-grid { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(300px, .8fr); gap: 16px; margin-top: 18px; }
.compact-heading { align-items: flex-start; }
.compact-heading h2 { margin: 5px 0 0; }
.bridge-row { min-height: 46px; display: flex; align-items: center; justify-content: space-between; gap: 20px; border-top: 1px solid #edf0f5; }
.bridge-row:first-of-type { border-top: 0; }
.bridge-row span { color: #4c5870; }
.bridge-positive strong { color: #22623a; }
.bridge-total { margin-top: 4px; border-top: 1px solid #ccd2df; font-weight: 700; }
.bridge-net { margin-top: 6px; border-top: 2px solid #172033; font-size: 17px; font-weight: 800; }
.quality-warning { margin: 14px 0 0; padding: 12px 14px; border-radius: 10px; background: #fff6df; color: #684b00; line-height: 1.5; font-size: 13px; }
.quality-panel h2 { margin: 5px 0 14px; }
.quality-list { display: grid; gap: 0; }
.quality-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 13px 0; border-top: 1px solid #edf0f5; }
.quality-row:first-child { border-top: 0; padding-top: 0; }
.quality-row > div { display: grid; gap: 4px; }
.quality-row small { color: #7b8497; line-height: 1.35; }
.status-error { background: #fff0f0; color: #9c2b2b; }
.status-count-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-top: 14px; }
.status-count-card { border: 1px solid #edf0f5; border-radius: 12px; padding: 14px; display: grid; gap: 8px; background: #fafbfc; }
.status-count-card span { font-size: 12px; color: #657088; }
.status-count-card strong { font-size: 23px; }
.dashboard-empty { margin-top: 18px; }
.product-profit-panel { margin-top: 18px; }
.product-profit-summary {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
    margin: 14px 0;
}
.product-profit-table-wrap { margin-top: 12px; }
.product-profit-table { min-width: 1180px; }
.product-profit-table td:nth-child(n+3) { white-space: nowrap; }
.profit-negative { color: #9c2b2b; }
.product-profit-all { margin-top: 14px; }
.product-profit-all summary {
    cursor: pointer;
    font-weight: 700;
    color: #172033;
}
.product-profit-note { margin: 14px 0 0; }


@media (max-width: 980px) {
    .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .dashboard-detail-grid { grid-template-columns: 1fr; }
    .product-profit-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 700px) {
    .dashboard-head, .dashboard-mode-heading { align-items: flex-start; flex-direction: column; }
    .dashboard-store-pill { width: 100%; }
    .status-count-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 520px) {
    .metric-grid { grid-template-columns: 1fr; }
    .mode-switch { width: 100%; }
    .mode-tab { flex: 1; min-width: 0; }
    .custom-period-form { display: grid; grid-template-columns: 1fr 1fr; }
    .custom-period-form input { min-width: 0; width: 100%; }
    .custom-period-form button { grid-column: 1 / -1; }
    .status-count-grid { grid-template-columns: 1fr 1fr; }
    .product-profit-summary { grid-template-columns: 1fr; }
}

/* HPP bulk Excel */
.hpp-bulk-panel { margin-bottom: 18px; display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 24px; }
.hpp-bulk-panel h2 { margin: 5px 0 8px; }
.hpp-bulk-panel p { margin: 0; max-width: 680px; line-height: 1.5; }
.hpp-bulk-actions { display: grid; gap: 10px; justify-items: stretch; min-width: 300px; }
.hpp-template-link { display: block; text-align: center; text-decoration: none; }
.hpp-upload-form { display: grid; gap: 8px; }
.hpp-upload-form input[type="file"] { width: 100%; border: 1px solid #ccd2df; border-radius: 9px; padding: 9px; background: #fff; }
.hpp-upload-form .primary { margin-top: 0; }
@media (max-width: 800px) { .hpp-bulk-panel { grid-template-columns: 1fr; } .hpp-bulk-actions { min-width: 0; } }

/* Data import */
.data-upload-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.upload-card { min-width: 0; }
.upload-card form { display: grid; gap: 10px; margin-top: 18px; }
.upload-card input[type="file"] { width: 100%; border: 1px solid #ccd2df; border-radius: 9px; padding: 9px; background: #fff; }
.upload-card .primary { width: 100%; margin-top: 0; }
.import-history .data-table { min-width: 760px; }
@media (max-width: 900px) { .data-upload-grid { grid-template-columns: 1fr; } }


/* Recurring expenses */
.field-errors {
    margin: 0;
    padding-left: 18px;
    color: #9c2b2b;
    font-size: 12px;
    line-height: 1.4;
}

.expense-actions {
    display: grid;
    gap: 8px;
    min-width: 220px;
}

.expense-action {
    border: 1px solid #dfe3eb;
    border-radius: 10px;
    background: #fff;
}

.expense-action summary {
    cursor: pointer;
    padding: 9px 10px;
    font-weight: 700;
    font-size: 13px;
}

.expense-action form {
    display: grid;
    gap: 8px;
    padding: 0 10px 10px;
}

.expense-action label {
    display: grid;
    gap: 5px;
    font-size: 12px;
    color: #657088;
}

.expense-action input,
.expense-action select {
    width: 100%;
    border: 1px solid #ccd2df;
    border-radius: 9px;
    padding: 9px 10px;
    font: inherit;
    background: #fff;
    color: #172033;
}

.expense-confirm {
    display: flex !important;
    grid-template-columns: none;
    align-items: flex-start;
    gap: 8px !important;
}

.expense-confirm input[type="checkbox"] {
    width: auto;
    margin-top: 2px;
}

.rate-history {
    display: grid;
    gap: 3px;
    margin-top: 6px;
    font-size: 12px;
    color: #657088;
}

/* Yearly summary finance table */
.yearly-filter-panel {
    padding: 14px 18px;
    margin-bottom: 14px;
}

.yearly-filter-form {
    display: flex;
    align-items: end;
    gap: 10px;
    width: fit-content;
}

.yearly-filter-form label {
    display: grid;
    gap: 5px;
    color: #657088;
    font-size: 12px;
    font-weight: 700;
}

.yearly-filter-form input {
    width: 110px;
    border: 1px solid #ccd2df;
    border-radius: 9px;
    padding: 9px 10px;
    font: inherit;
    background: #fff;
    color: #172033;
}

.yearly-metric-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    margin-bottom: 18px;
}

.yearly-table {
    min-width: 1320px;
    font-variant-numeric: tabular-nums;
}

.yearly-table th,
.yearly-table td {
    padding: 14px 16px;
    vertical-align: middle;
    white-space: nowrap;
}

.yearly-table thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: #f7f8fb;
    border-bottom: 1px solid #dfe3eb;
}

.yearly-table tbody tr:hover td {
    background: #fafbfc;
}

.yearly-table th:first-child,
.yearly-table td:first-child {
    position: sticky;
    left: 0;
    z-index: 1;
    background: #fff;
}

.yearly-table thead th:first-child {
    z-index: 3;
    background: #f7f8fb;
}

.yearly-table tbody tr:hover td:first-child {
    background: #fafbfc;
}

.yearly-table th:not(:first-child):not(:last-child),
.yearly-number {
    text-align: right;
}

.yearly-number {
    color: #263247;
}
.yearly-net-profit {
    font-weight: 800;
    color: #172033;
}

.yearly-margin {
    font-weight: 700;
}

.yearly-status-cell {
    text-align: left;
}

.yearly-status {
    display: inline-flex;
    align-items: center;
    min-height: 26px;
    padding: 5px 9px;
    border-radius: 999px;
    font-size: 11px;
    line-height: 1;
    font-weight: 800;
    white-space: nowrap;
}

.yearly-status-complete {
    background: #eaf8ef;
    color: #22623a;
}

.yearly-status-incomplete {
    background: #fff6df;
    color: #805b00;
}

.yearly-status-empty {
    background: #f0f2f6;
    color: #657088;
}

.yearly-status-future {
    background: #f0f2f6;
    color: #7b8497;
}
@media (max-width: 980px) {
    .yearly-metric-grid {
        grid-template-columns: repeat(3, minmax(220px, 1fr));
        overflow-x: auto;
    }
}

@media (max-width: 620px) {
    .yearly-filter-form {
        width: 100%;
    }

    .yearly-filter-form label {
        flex: 1;
    }

    .yearly-filter-form input {
        width: 100%;
    }
}
