:root {
    --navy: #071d33;
    --navy-2: #0d2c4a;
    --red: #d71920;
    --teal: #0f766e;
    --amber: #b45309;
    --ink: #142033;
    --muted: #667085;
    --line: #d8dee8;
    --soft: #eef3f8;
    --panel: #ffffff;
    --danger: #b42318;
    --danger-soft: #fff1f0;
    --success: #027a48;
    --success-soft: #ecfdf3;
    --warning-soft: #fff8e8;
    --shadow: 0 18px 45px rgba(7, 29, 51, 0.12);
    color-scheme: light;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: #f5f7fb;
    color: var(--ink);
}

button,
input,
select,
textarea {
    font: inherit;
}

button,
a.button {
    min-height: 40px;
}

.login-page {
    display: grid;
    place-items: center;
    padding: 32px;
    background: linear-gradient(180deg, #ffffff 0%, #edf2f7 100%);
}

.login-wrap {
    width: min(100%, 430px);
}

.login-panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
    padding: 32px;
}

.login-logo {
    display: block;
    width: 240px;
    max-width: 100%;
    margin: 0 auto 22px;
}

.login-panel h1 {
    margin: 0 0 22px;
    font-size: 24px;
    line-height: 1.15;
    text-align: center;
    color: var(--navy);
}

.login-form {
    display: grid;
    gap: 16px;
}

.login-footnote,
.fineprint {
    margin: 16px 0 0;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.45;
}

.alert {
    padding: 12px;
    border-radius: 8px;
    font-size: 14px;
}

.alert-danger {
    color: var(--danger);
    background: var(--danger-soft);
    border: 1px solid #f4b8b2;
}

.app-shell {
    display: grid;
    grid-template-columns: 246px minmax(0, 1fr);
}

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    gap: 24px;
    padding: 22px 18px;
    background: var(--navy);
    color: #fff;
}

.brand {
    display: block;
    background: #fff;
    border-radius: 8px;
    padding: 14px;
}

.brand img {
    display: block;
    width: 100%;
}

.nav-tabs {
    display: grid;
    gap: 8px;
}

.nav-tab {
    width: 100%;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 8px;
    background: transparent;
    color: rgba(255, 255, 255, 0.78);
    padding: 11px 12px;
    text-align: left;
    cursor: pointer;
}

.nav-tab.active,
.nav-tab:hover {
    background: #fff;
    color: var(--navy);
}

.user-box {
    margin-top: auto;
    display: grid;
    gap: 5px;
    padding-top: 18px;
    border-top: 1px solid rgba(255, 255, 255, 0.16);
    font-size: 14px;
}

.user-box strong {
    color: #bbf7d0;
}

.user-box a {
    color: #fff;
    text-decoration: none;
    margin-top: 8px;
}

.workspace {
    min-width: 0;
    padding: 24px;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    margin-bottom: 22px;
}

.eyebrow {
    margin: 0 0 5px;
    color: var(--red);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
}

.topbar h1 {
    margin: 0;
    color: var(--navy);
    font-size: 28px;
    line-height: 1.1;
}

.source-pill,
.badge {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: #fff;
    color: var(--muted);
    padding: 5px 10px;
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
}

.badge-success {
    border-color: #abefc6;
    background: var(--success-soft);
    color: var(--success);
}

.badge-danger {
    border-color: #fecdca;
    background: var(--danger-soft);
    color: var(--danger);
}

.badge-warning {
    border-color: #fedf89;
    background: var(--warning-soft);
    color: var(--amber);
}

.badge-muted {
    background: #f8fafc;
}

.view {
    display: none;
}

.view.active {
    display: block;
}

.calculator-grid {
    display: grid;
    grid-template-columns: repeat(12, minmax(0, 1fr));
    gap: 16px;
    align-items: start;
}

.span-8 {
    grid-column: span 8;
}

.span-4 {
    grid-column: span 4;
}

.span-2 {
    grid-column: span 2;
}

.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 18px;
    box-shadow: 0 10px 28px rgba(7, 29, 51, 0.06);
}

.sticky-panel {
    position: sticky;
    top: 20px;
}

.panel-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}

.panel-heading h2 {
    margin: 0;
    color: var(--navy);
    font-size: 17px;
    line-height: 1.2;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
}

label {
    display: grid;
    gap: 7px;
    color: #344054;
    font-size: 13px;
    font-weight: 700;
}

input,
select,
textarea {
    width: 100%;
    min-width: 0;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    background: #fff;
    color: var(--ink);
    padding: 10px 11px;
    outline: none;
    transition: border-color 120ms ease, box-shadow 120ms ease;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--teal);
    box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
}

textarea {
    min-height: 180px;
    line-height: 1.45;
    resize: vertical;
}

.hidden {
    display: none !important;
}

.inline-warning {
    margin: -2px 0 14px;
    border-radius: 8px;
    padding: 10px 12px;
    color: var(--amber);
    background: var(--warning-soft);
    border: 1px solid #fedf89;
    font-size: 13px;
    line-height: 1.4;
}

.inline-warning.valid {
    color: var(--success);
    background: var(--success-soft);
    border-color: #abefc6;
}

.inline-warning.invalid {
    color: var(--danger);
    background: var(--danger-soft);
    border-color: #fecdca;
}

.inline-warning.muted {
    color: var(--muted);
    background: #f8fafc;
    border-color: var(--line);
}

.total-box {
    display: grid;
    gap: 5px;
    padding: 16px;
    border-radius: 8px;
    background: var(--navy);
    color: #fff;
}

.total-box span {
    color: rgba(255, 255, 255, 0.72);
    font-size: 13px;
    font-weight: 700;
}

.total-box strong {
    font-size: clamp(28px, 3.8vw, 42px);
    line-height: 1;
    overflow-wrap: anywhere;
}

.breakdown {
    display: grid;
    gap: 9px;
    margin: 16px 0;
}

.breakdown div {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 12px;
    align-items: baseline;
    padding-bottom: 9px;
    border-bottom: 1px solid #eef2f6;
}

.breakdown dt,
.breakdown dd {
    margin: 0;
    font-size: 13px;
}

.breakdown dt {
    color: var(--muted);
}

.breakdown dd {
    color: var(--navy);
    font-weight: 800;
    text-align: right;
}

.button,
a.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--navy);
    padding: 9px 13px;
    font-weight: 800;
    text-decoration: none;
    cursor: pointer;
}

.button:hover,
a.button:hover {
    border-color: #98a2b3;
}

.button-primary {
    border-color: var(--red);
    background: var(--red);
    color: #fff;
}

.button-ghost {
    background: #f8fafc;
}

.button-danger {
    border-color: #fecdca;
    color: var(--danger);
    background: #fff;
}

.button-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.button-row.tight {
    gap: 8px;
}

.upload-box {
    border: 1px dashed #98a2b3;
    border-radius: 8px;
    padding: 14px;
    background: #f8fafc;
    cursor: pointer;
}

.upload-box input {
    border: 0;
    padding: 4px 0 0;
    background: transparent;
}

.preview-strip {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    min-height: 8px;
    margin: 10px 0 16px;
}

.preview-strip img {
    width: 100%;
    aspect-ratio: 4 / 3;
    object-fit: cover;
    border-radius: 8px;
    border: 1px solid var(--line);
}

.caption-panel {
    margin-top: 16px;
}

.report-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 16px;
}

.stat {
    display: grid;
    gap: 6px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 16px;
}

.stat span {
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
}

.stat strong {
    color: var(--navy);
    font-size: 24px;
    line-height: 1.1;
    overflow-wrap: anywhere;
}

.history-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
}

.search-input {
    width: min(320px, 100%);
}

.history-list {
    display: grid;
    gap: 12px;
}

.history-card {
    display: grid;
    grid-template-columns: 116px minmax(0, 1fr) auto;
    gap: 14px;
    align-items: center;
    border: 1px solid #e4e7ec;
    border-radius: 8px;
    padding: 12px;
    background: #fff;
}

.history-thumb {
    width: 116px;
    aspect-ratio: 4 / 3;
    border-radius: 8px;
    background: var(--soft);
    border: 1px solid var(--line);
    object-fit: cover;
}

.history-thumb.placeholder {
    display: grid;
    place-items: center;
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
}

.history-title {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}

.history-title h3 {
    margin: 0;
    color: var(--navy);
    font-size: 16px;
}

.history-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 14px;
    color: var(--muted);
    font-size: 13px;
}

.history-price {
    color: var(--navy);
    font-size: 20px;
    font-weight: 900;
    text-align: right;
    white-space: nowrap;
}

.history-buttons {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 10px;
}

.empty-state {
    border: 1px dashed #b8c0cc;
    border-radius: 8px;
    padding: 28px;
    color: var(--muted);
    text-align: center;
    background: #f8fafc;
}

.toast {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 20;
    max-width: min(360px, calc(100vw - 40px));
    padding: 12px 14px;
    border-radius: 8px;
    background: var(--navy);
    color: #fff;
    box-shadow: var(--shadow);
    transform: translateY(16px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 160ms ease, transform 160ms ease;
}

.toast.show {
    transform: translateY(0);
    opacity: 1;
}

@media (max-width: 1180px) {
    .calculator-grid {
        grid-template-columns: 1fr;
    }

    .span-8,
    .span-4 {
        grid-column: auto;
    }

    .sticky-panel {
        position: static;
    }
}

@media (max-width: 900px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: static;
        height: auto;
        flex-direction: row;
        align-items: center;
        flex-wrap: wrap;
    }

    .brand {
        width: 180px;
    }

    .nav-tabs {
        grid-auto-flow: column;
        margin-left: auto;
    }

    .user-box {
        width: 100%;
    }

    .topbar,
    .history-card {
        align-items: stretch;
        flex-direction: column;
    }

    .form-grid,
    .report-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .history-card {
        grid-template-columns: 92px minmax(0, 1fr);
    }

    .history-price {
        grid-column: 1 / -1;
        text-align: left;
    }
}

@media (max-width: 620px) {
    .workspace {
        padding: 16px;
    }

    .sidebar {
        padding: 14px;
    }

    .nav-tabs,
    .form-grid,
    .report-grid {
        grid-template-columns: 1fr;
        grid-auto-flow: row;
        width: 100%;
    }

    .brand {
        width: 150px;
    }

    .source-pill {
        white-space: normal;
    }

    .span-2 {
        grid-column: auto;
    }

    .panel {
        padding: 14px;
    }

    .history-card {
        grid-template-columns: 1fr;
    }

    .history-thumb {
        width: 100%;
    }

    .history-actions,
    .history-buttons,
    .button-row {
        justify-content: stretch;
    }

    .button,
    a.button {
        width: 100%;
    }
}
