:root {
    --ink: #142033;
    --navy: #0e1b2e;
    --navy-2: #17304d;
    --paper: #f3eee4;
    --card: #fffaf3;
    --line: #d9d0bf;
    --amber: #d97706;
    --amber-d: #b45309;
    --muted: #6b6256;
    --ok: #0f766e;
    --bad: #b42318;
    --shadow: 0 10px 30px rgba(14, 27, 46, 0.08);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
    background: var(--paper);
    color: var(--ink);
    min-height: 100vh;
}

a { color: var(--navy-2); }
.layout { display: flex; min-height: 100vh; }

.sidebar {
    width: 250px;
    background: linear-gradient(180deg, var(--navy) 0%, #0a1422 100%);
    color: #f6efe3;
    padding: 22px 16px;
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
}
.brand {
    display: flex;
    gap: 10px;
    align-items: center;
    padding: 6px 8px 22px;
    border-bottom: 1px dashed rgba(255,255,255,.18);
    margin-bottom: 16px;
}
.stamp {
    width: 40px; height: 40px;
    border: 2px solid var(--amber);
    border-radius: 4px;
    display: grid; place-items: center;
    font-family: "IBM Plex Mono", monospace;
    font-weight: 700;
    color: var(--amber);
    letter-spacing: .04em;
}
.brand h1 { font-size: 16px; margin: 0; letter-spacing: .08em; text-transform: uppercase; }
.brand p { margin: 2px 0 0; font-size: 11px; color: #cbbda6; }

.nav a {
    display: flex; align-items: center; gap: 10px;
    color: #e8dcc8;
    text-decoration: none;
    padding: 10px 12px;
    border-radius: 8px;
    font-size: 14px;
    margin-bottom: 4px;
}
.nav a:hover, .nav a.active {
    background: rgba(217, 119, 6, .16);
    color: #fff;
}
.nav .sec {
    margin: 16px 8px 8px;
    font-size: 11px;
    letter-spacing: .14em;
    text-transform: uppercase;
    color: #9a8d78;
}
.sidebar .foot {
    margin-top: auto;
    padding-top: 12px;
    border-top: 1px dashed rgba(255,255,255,.18);
    font-size: 12px;
    color: #cbbda6;
}

.main { flex: 1; padding: 22px 28px 40px; min-width: 0; }
.topbar {
    display: flex; justify-content: space-between; align-items: flex-end;
    margin-bottom: 18px;
}
.eyebrow {
    font-family: "IBM Plex Mono", monospace;
    font-size: 11px;
    letter-spacing: .16em;
    text-transform: uppercase;
    color: var(--amber-d);
    margin: 0 0 4px;
}
.topbar h2 { margin: 0; font-size: 26px; }

.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 14px;
    box-shadow: var(--shadow);
    padding: 18px;
    margin-bottom: 18px;
}
.card h3 { margin: 0 0 14px; font-size: 16px; }

.flash {
    padding: 10px 14px;
    border-radius: 8px;
    margin-bottom: 14px;
    font-size: 14px;
}
.flash.ok { background: #e6f4f1; color: #115e59; }
.flash.bad { background: #fde8e6; color: #9b1c1c; }

.grid { display: grid; gap: 14px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.stat {
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fff;
}
.stat span { display: block; font-size: 12px; color: var(--muted); letter-spacing: .06em; text-transform: uppercase; }
.stat strong { display: block; font-size: 24px; margin-top: 6px; }
.stat em { font-style: normal; color: var(--ok); font-size: 13px; }

label { display: block; font-size: 12px; font-weight: 600; margin-bottom: 5px; color: #3f3a32; }
input, select, textarea {
    width: 100%;
    border: 1px solid #cfc4b0;
    background: #fff;
    border-radius: 8px;
    padding: 9px 10px;
    font: inherit;
    color: var(--ink);
}
textarea { min-height: 78px; resize: vertical; }
.row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 12px; }
.row-3 { grid-template-columns: repeat(3, 1fr); }
.row-2 { grid-template-columns: repeat(2, 1fr); }
.span-2 { grid-column: span 2; }

.btn {
    display: inline-flex; align-items: center; gap: 6px;
    border: 0; border-radius: 8px;
    padding: 9px 14px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    font-size: 14px;
}
.btn-amber { background: var(--amber); color: #fff; }
.btn-amber:hover { background: var(--amber-d); }
.btn-navy { background: var(--navy); color: #fff; }
.btn-ghost { background: transparent; border: 1px solid var(--line); color: var(--ink); }
.btn-bad { background: #b42318; color: #fff; }
.btn-sm { padding: 5px 9px; font-size: 12px; }

.table-wrap { overflow: auto; }
table.data {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
table.data th, table.data td {
    padding: 9px 8px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    white-space: nowrap;
}
table.data th {
    font-size: 11px;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--muted);
    background: #efe8db;
}
table.data tbody tr:hover { background: #fff7ea; }

.pill {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    color: #fff;
}
.muted { color: var(--muted); }
.right { text-align: right; }
.actions { display: flex; gap: 8px; }

.login-wrap {
    min-height: 100vh;
    display: grid;
    place-items: center;
    background:
        radial-gradient(circle at 20% 20%, rgba(217,119,6,.18), transparent 28%),
        linear-gradient(160deg, #0e1b2e 0%, #17304d 55%, #1f3d2b 100%);
}
.waybill {
    width: 440px;
    background: #f7f1e6;
    border: 2px solid #1a2332;
    box-shadow: 12px 16px 0 #d97706;
    padding: 28px;
}
.waybill .tag {
    font-family: "IBM Plex Mono", monospace;
    font-size: 11px;
    letter-spacing: .2em;
    text-transform: uppercase;
    color: var(--amber-d);
}
.waybill h1 { margin: 8px 0 4px; }
.waybill p.sub { margin: 0 0 18px; color: var(--muted); font-size: 13px; }
.waybill .btn { width: 100%; justify-content: center; margin-top: 8px; }

.invoice {
    background: #fff;
    border: 2px solid #111;
    padding: 28px;
    color: #111;
}
.invoice h2 { text-align: center; letter-spacing: .2em; margin: 0 0 18px; }
.invoice table { width: 100%; border-collapse: collapse; }
.invoice th, .invoice td { border: 1px solid #111; padding: 6px 8px; font-size: 12px; }
.invoice .split { display: flex; justify-content: space-between; gap: 20px; margin-bottom: 14px; }
.invoice address { font-style: normal; line-height: 1.5; }

@media print {
    .sidebar, .topbar, .no-print, .flash { display: none !important; }
    .layout, .main { display: block; padding: 0; background: #fff; }
    .card { box-shadow: none; border: 0; padding: 0; }
}

.menu-btn, .bottom-nav, .scrim { display: none; }
.topbar-left { display: flex; align-items: center; gap: 10px; }
.awb-field { display: flex; gap: 8px; align-items: flex-end; }
.awb-field input { flex: 1; }
.scan-cta { display: none; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }
.photo-block { margin: 16px 0; padding: 14px; border: 1px dashed var(--line); border-radius: 12px; background: #fff; }
.photo-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.photo-actions .btn { min-height: 44px; }
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; margin-top: 10px; }
.photo-card { position: relative; background: #111; border-radius: 10px; overflow: hidden; }
.photo-card img { width: 100%; height: 110px; object-fit: cover; display: block; }
.photo-card .btn { width: 100%; border-radius: 0; }
.scan-overlay {
    position: fixed; inset: 0; background: rgba(10, 16, 28, .72);
    z-index: 80; display: grid; place-items: end;
}
.scan-overlay[hidden] { display: none !important; }
.scan-sheet {
    width: 100%; max-width: 560px; margin: 0 auto;
    background: var(--card); border-radius: 18px 18px 0 0;
    padding: 16px 16px 28px;
}
.scan-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
#scannerBox { min-height: 240px; background: #111; border-radius: 12px; overflow: hidden; }

@media (max-width: 1100px) {
    .grid-4, .row { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 860px) {
    .layout { display: block; }
    .sidebar {
        position: fixed; left: 0; top: 0;
        width: min(82vw, 280px); height: 100vh;
        transform: translateX(-110%);
        transition: transform .2s ease;
        z-index: 50;
    }
    .sidebar.open { transform: none; }
    .scrim.show {
        display: block; position: fixed; inset: 0;
        background: rgba(0,0,0,.45); z-index: 40;
    }
    .menu-btn {
        display: inline-flex; align-items: center; justify-content: center;
        width: 42px; height: 42px; border: 1px solid var(--line);
        background: #fff; border-radius: 10px; font-size: 20px; cursor: pointer;
    }
    .bottom-nav {
        display: flex; position: fixed; left: 0; right: 0; bottom: 0;
        background: #0e1b2e; z-index: 30;
        padding: 8px 6px calc(8px + env(safe-area-inset-bottom));
        justify-content: space-around;
    }
    .bottom-nav a {
        color: #d8cbb6; text-decoration: none; font-size: 12px; font-weight: 600;
        padding: 8px 12px; border-radius: 10px;
    }
    .bottom-nav a.active { background: rgba(217,119,6,.2); color: #fff; }
    .main { padding: 14px 14px 92px; }
    .grid-4, .grid-3, .row, .row-3, .row-2 { grid-template-columns: 1fr; }
    .span-2 { grid-column: auto; }
    input, select, textarea { font-size: 16px; min-height: 44px; }
    .scan-cta { display: block; width: 100%; justify-content: center; margin-bottom: 12px; min-height: 48px; }
    .waybill { width: calc(100% - 28px); box-shadow: 8px 10px 0 #d97706; }
    table.data { font-size: 12px; }
}
