:root {
    --navy: #12314a;
    --navy-2: #1b4565;
    --gold: #c9a45f;
    --bg: #f4f6f8;
    --card: #ffffff;
    --text: #1c2730;
    --muted: #6b7780;
    --line: #dfe5e9;
    --success: #18794e;
    --success-bg: #e8f5ee;
    --warning: #9a6700;
    --warning-bg: #fff4ce;
    --danger: #b42318;
    --danger-bg: #feeceb;
    --shadow: 0 8px 24px rgba(18, 49, 74, .08);
    --radius: 18px;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body {
    margin: 0;
    min-height: 100vh;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--text);
    background: var(--bg);
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .5; }

.topbar {
    position: sticky;
    top: 0;
    z-index: 50;
    min-height: 72px;
    padding: 0 28px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(255,255,255,.96);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(14px);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark, .auth-logo {
    display: grid;
    place-items: center;
    background: var(--navy);
    color: white;
    font-weight: 800;
    letter-spacing: .04em;
}
.brand-mark { width: 42px; height: 42px; border-radius: 12px; }
.brand strong, .brand small { display: block; }
.brand small { color: var(--muted); font-size: 12px; margin-top: 2px; }
.desktop-nav { display: flex; align-items: center; gap: 24px; color: var(--muted); font-weight: 600; }
.desktop-nav a:hover, .link-button:hover { color: var(--navy); }
.inline-form { display: inline; }
.link-button { border: 0; background: none; color: var(--muted); font-weight: 600; padding: 0; }

.page-shell { width: min(1180px, calc(100% - 32px)); margin: 0 auto; padding: 34px 0 110px; }
.auth-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.page-heading { display: flex; justify-content: space-between; gap: 20px; align-items: end; margin-bottom: 24px; }
.page-heading h1 { margin: 0; font-size: clamp(28px, 4vw, 42px); letter-spacing: -.04em; }
.eyebrow { margin: 0 0 6px; color: var(--gold); font-weight: 800; text-transform: uppercase; letter-spacing: .1em; font-size: 12px; }
.month-switcher { display: flex; align-items: center; gap: 8px; }
.month-switcher input { min-height: 44px; border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; background: white; }
.icon-button { width: 44px; height: 44px; display: grid; place-items: center; border: 1px solid var(--line); background: white; border-radius: 12px; font-size: 26px; }

.flash-stack { display: grid; gap: 10px; margin-bottom: 20px; }
.flash { padding: 14px 16px; border-radius: 12px; border: 1px solid transparent; font-weight: 600; }
.flash-success { color: var(--success); background: var(--success-bg); border-color: #b8e2cb; }
.flash-warning { color: var(--warning); background: var(--warning-bg); border-color: #f2d77d; }
.flash-danger { color: var(--danger); background: var(--danger-bg); border-color: #f4c1bd; }

.stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 20px; }
.stat-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.stat-card span, .stat-card small { display: block; color: var(--muted); }
.stat-card strong { display: block; font-size: 34px; margin: 6px 0 2px; }
.stat-pending { border-top: 4px solid #e9a23b; }
.stat-sent { border-top: 4px solid #36a269; }

.upload-card, .actions-card, .panel, .history-card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.upload-card, .panel, .history-card { padding: 24px; }
.upload-card { margin-bottom: 20px; }
.section-title { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.section-title h2, .actions-card h2, .panel h2, .history-card h2 { margin: 0; font-size: 22px; }
.section-title p, .actions-card p, .panel p { margin: 5px 0 0; color: var(--muted); }
.upload-form { display: grid; gap: 16px; }
.upload-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.date-field { max-width: 260px; }

label { display: grid; gap: 7px; font-weight: 700; font-size: 14px; }
input, select, textarea {
    width: 100%;
    border: 1px solid #cfd8de;
    border-radius: 12px;
    background: white;
    color: var(--text);
    padding: 12px 13px;
    outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--navy-2); box-shadow: 0 0 0 3px rgba(27,69,101,.12); }
textarea { resize: vertical; }

.button {
    min-height: 46px;
    border: 0;
    border-radius: 12px;
    padding: 11px 17px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-weight: 800;
    transition: transform .15s ease, box-shadow .15s ease;
}
.button:hover:not(:disabled) { transform: translateY(-1px); }
.button-primary { background: var(--navy); color: white; box-shadow: 0 8px 18px rgba(18,49,74,.18); }
.button-primary:hover:not(:disabled) { background: var(--navy-2); }
.button-secondary { background: #eef2f5; color: var(--navy); border: 1px solid #d9e0e5; }
.button-camera { background: #eaf4fb; color: #0f5f8f; border: 1px solid #bed9ea; }
.button-large { min-height: 52px; }
.selected-files { padding: 12px 14px; background: #f8fafb; border: 1px dashed #bfcbd3; border-radius: 12px; color: var(--muted); }
.selected-files strong { color: var(--text); }

.actions-card { padding: 20px 24px; display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-bottom: 28px; }
.month-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.documents-section { margin-top: 4px; }
.document-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.document-card { overflow: hidden; background: white; border: 1px solid var(--line); border-radius: 16px; box-shadow: 0 5px 18px rgba(18,49,74,.06); }
.preview { position: relative; display: grid; place-items: center; height: 190px; background: #eef2f5; overflow: hidden; }
.preview img { width: 100%; height: 100%; object-fit: cover; transition: transform .2s ease; }
.preview:hover img { transform: scale(1.02); }
.file-icon { width: 82px; height: 98px; border-radius: 10px; display: grid; place-items: center; color: white; background: #60788a; font-weight: 900; font-size: 18px; box-shadow: 0 8px 18px rgba(18,49,74,.18); }
.file-pdf { background: #bd2c2c; }
.status-badge { position: absolute; top: 12px; right: 12px; padding: 7px 10px; border-radius: 999px; font-size: 12px; font-weight: 900; box-shadow: 0 4px 12px rgba(0,0,0,.1); }
.status-pending { color: var(--warning); background: var(--warning-bg); }
.status-sent { color: var(--success); background: var(--success-bg); }
.document-info { padding: 15px 16px 8px; }
.document-info h3 { margin: 0 0 7px; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.document-info p { margin: 3px 0; color: var(--muted); font-size: 13px; }
.document-info .sent-line { color: var(--success); font-weight: 700; }
.document-actions { border-top: 1px solid var(--line); display: flex; align-items: center; gap: 4px; padding: 8px 10px; flex-wrap: wrap; }
.small-action { border: 0; background: none; padding: 7px 8px; font-size: 13px; font-weight: 800; color: var(--navy-2); }
.danger-link { color: var(--danger); }
.empty-state { padding: 54px 20px; text-align: center; background: white; border: 1px dashed #bdc9d1; border-radius: var(--radius); color: var(--muted); }
.empty-state > div { font-size: 38px; }
.empty-state h3, .empty-state h1 { color: var(--text); margin-bottom: 8px; }

.history-card { margin-top: 28px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 650px; }
th, td { text-align: left; padding: 13px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
td { font-size: 14px; }
.pill { display: inline-flex; border-radius: 999px; padding: 5px 9px; font-size: 11px; font-weight: 900; }
.pill-success { background: var(--success-bg); color: var(--success); }
.pill-danger { background: var(--danger-bg); color: var(--danger); }
.error-detail { display: block; color: var(--danger); margin-top: 5px; max-width: 480px; }

.auth-card { width: min(460px, 100%); background: white; border: 1px solid var(--line); border-radius: 24px; padding: 30px; box-shadow: var(--shadow); }
.auth-logo { width: 64px; height: 64px; border-radius: 18px; margin: 0 auto 18px; font-size: 22px; }
.auth-card h1, .auth-card > p { text-align: center; }
.auth-card h1 { margin-bottom: 6px; }
.auth-card > p { color: var(--muted); margin-top: 0; margin-bottom: 24px; }
.stack-form { display: grid; gap: 15px; }
hr { border: 0; border-top: 1px solid var(--line); width: 100%; margin: 8px 0; }
h3 { margin-bottom: 8px; }
.help-text { color: var(--muted); font-size: 13px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.settings-grid { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(280px, .8fr); gap: 20px; align-items: start; }
.settings-side { display: grid; gap: 20px; }
.top-gap { margin-top: 12px; }
.install-panel { background: linear-gradient(145deg, #fff, #f0f5f8); }
code { background: #eef2f5; border-radius: 6px; padding: 2px 5px; }
.error-page { margin-top: 80px; }

.mobile-nav { display: none; }

@media (max-width: 900px) {
    .document-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .settings-grid { grid-template-columns: 1fr; }
    .actions-card { align-items: flex-start; flex-direction: column; }
}

@media (max-width: 680px) {
    body { padding-bottom: env(safe-area-inset-bottom); }
    .topbar { min-height: 62px; padding: 0 16px; }
    .brand small { display: none; }
    .desktop-nav { display: none; }
    .page-shell { width: min(100% - 22px, 1180px); padding-top: 22px; padding-bottom: 100px; }
    .page-heading { align-items: flex-start; flex-direction: column; }
    .month-switcher { width: 100%; }
    .month-switcher form { flex: 1; }
    .month-switcher input { width: 100%; }
    .stats-grid { grid-template-columns: repeat(3, 1fr); gap: 8px; }
    .stat-card { padding: 14px 11px; border-radius: 14px; }
    .stat-card strong { font-size: 27px; }
    .stat-card small { font-size: 11px; }
    .upload-card, .panel, .history-card { padding: 18px; }
    .upload-actions { grid-template-columns: 1fr; }
    .date-field { max-width: none; }
    .actions-card { padding: 18px; }
    .month-actions, .month-actions form, .month-actions .button { width: 100%; }
    .document-grid { grid-template-columns: 1fr; }
    .preview { height: 220px; }
    .form-row { grid-template-columns: 1fr; }
    .auth-card { padding: 24px 18px; }
    .mobile-nav {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 60;
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        background: rgba(255,255,255,.97);
        border-top: 1px solid var(--line);
        padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
        backdrop-filter: blur(14px);
    }
    .mobile-nav a { display: grid; place-items: center; gap: 2px; color: var(--muted); font-size: 11px; font-weight: 800; }
    .mobile-nav span { color: var(--navy); font-size: 20px; }
}
