:root {
    --bg: #f4f6fb;
    --panel: #ffffff;
    --ink: #1d2433;
    --muted: #6b7280;
    --line: #e6e9f0;
    --brand: #2563eb;
    --brand-dark: #1e4fc4;
    --green: #16a34a;
    --green-bg: #e7f8ee;
    --red: #dc2626;
    --red-bg: #fdeaea;
    --amber: #d97706;
    --shadow: 0 1px 3px rgba(16, 24, 40, .08), 0 1px 2px rgba(16, 24, 40, .04);
    --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
    font-size: 15px;
    line-height: 1.45;
}

.app { max-width: 1100px; margin: 0 auto; padding: 0 18px 60px; }

/* ---------- Top bar ---------- */
.topbar {
    position: sticky; top: 0; z-index: 20;
    background: var(--bg);
    padding: 18px 0 10px;
}
.brand { display: flex; align-items: center; gap: 14px; }
.logo {
    font-size: 30px; width: 54px; height: 54px;
    display: grid; place-items: center;
    background: #fff; border-radius: var(--radius); box-shadow: var(--shadow);
}
.brand h1 { margin: 0; font-size: 20px; font-weight: 700; }
.brand .sub { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.brand .sub strong { color: var(--brand); }

.tabs {
    display: flex; gap: 4px; margin-top: 16px;
    background: #fff; padding: 6px; border-radius: 12px;
    box-shadow: var(--shadow); overflow-x: auto;
}
.tab {
    border: 0; background: transparent; cursor: pointer;
    padding: 9px 16px; border-radius: 8px;
    font: inherit; font-weight: 600; color: var(--muted);
    white-space: nowrap; transition: .15s;
}
.tab:hover { color: var(--ink); }
.tab.active { background: var(--brand); color: #fff; }
.tab.logout { margin-left: auto; text-decoration: none; color: var(--red); }
.tab.logout:hover { background: var(--red-bg); }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card {
    background: #fff; border-radius: var(--radius); box-shadow: var(--shadow);
    padding: 34px 30px; width: 100%; max-width: 360px;
    display: grid; gap: 14px; text-align: center;
}
.login-logo {
    font-size: 34px; width: 64px; height: 64px; margin: 0 auto 4px;
    display: grid; place-items: center; background: var(--bg); border-radius: var(--radius);
}
.login-card h1 { margin: 0; font-size: 20px; }
.login-sub { margin: 0 0 6px; color: var(--muted); font-size: 14px; }
.login-card input { text-align: center; font-size: 18px; letter-spacing: 3px; padding: 12px; }
.login-card .btn { padding: 12px; font-size: 15px; }
.login-error {
    background: var(--red-bg); color: var(--red);
    padding: 10px; border-radius: 9px; font-size: 14px;
}

/* ---------- Views ---------- */
main { margin-top: 22px; }
.view { display: none; animation: fade .25s ease; }
.view.active { display: grid; gap: 18px; }
@keyframes fade { from { opacity: 0; transform: translateY(6px);} to {opacity:1;transform:none;} }

/* ---------- Cards ---------- */
.cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.card {
    background: var(--panel); border-radius: var(--radius);
    padding: 16px 18px; box-shadow: var(--shadow);
}
.card .label { color: var(--muted); font-size: 13px; font-weight: 500; }
.card .value { font-size: 26px; font-weight: 700; margin-top: 4px; }
.card.green .value { color: var(--green); }
.card.red .value { color: var(--red); }
.card.blue .value { color: var(--brand); }

/* ---------- Panels ---------- */
.panel {
    background: var(--panel); border-radius: var(--radius);
    box-shadow: var(--shadow); overflow: hidden;
}
.panel.narrow { max-width: 520px; }
.panel-head {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 16px 18px; border-bottom: 1px solid var(--line);
}
.panel-head h2 { margin: 0; font-size: 16px; font-weight: 600; }

/* ---------- Forms ---------- */
.form { padding: 18px; display: grid; gap: 14px; }
.form .row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
label { display: grid; gap: 6px; font-size: 13px; font-weight: 500; color: var(--muted); }
input, select {
    font: inherit; color: var(--ink);
    padding: 10px 12px; border: 1px solid var(--line); border-radius: 9px;
    background: #fff; outline: none; transition: .15s;
}
input:focus, select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
.search { width: 100%; max-width: 340px; padding: 11px 16px; font-size: 15px; }
.head-controls { display: flex; align-items: center; gap: 10px; }
.head-controls select { padding: 11px 14px; font-size: 15px; }

.btn {
    font: inherit; font-weight: 600; cursor: pointer;
    padding: 10px 16px; border-radius: 9px; border: 1px solid transparent;
    transition: .15s;
}
.btn.primary { background: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.ghost { background: #fff; border-color: var(--line); color: var(--ink); }
.btn.ghost:hover { background: var(--bg); }
.btn.btn-sm { padding: 6px 14px; font-size: 13px; }

.opt { color: var(--muted); font-weight: 400; font-size: 12px; }
.hint { color: var(--muted); font-size: 13px; }
.modal-sub { margin: -6px 0 14px; color: var(--muted); font-size: 14px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 12px 18px; text-align: left; border-bottom: 1px solid var(--line); }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); background: #fbfcfe; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fafbff; }
.num { text-align: right; }
td.num { font-variant-numeric: tabular-nums; }

.pill { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.pill.coming { background: var(--red-bg); color: var(--red); }
.pill.done   { background: var(--green-bg); color: var(--green); }
.pill.warn   { background: #fef3c7; color: #b45309; }
.pill.sent   { background: #eef2ff; color: var(--brand); }
.pill.received { background: var(--green-bg); color: var(--green); }

.row-actions { text-align: right; white-space: nowrap; }
.icon-btn {
    border: 0; background: transparent; cursor: pointer; font-size: 15px;
    padding: 4px 6px; border-radius: 6px; color: var(--muted);
}
.icon-btn:hover { background: var(--bg); color: var(--ink); }
.icon-btn.del:hover { color: var(--red); }

.empty { padding: 28px; text-align: center; color: var(--muted); }

/* ---------- Grouped (expandable) received rows ---------- */
.group-row { cursor: pointer; background: #fbfcfe; }
.group-row:hover { background: #f1f5ff; }
.group-row .caret { display: inline-block; color: var(--muted); transition: transform .15s; margin-right: 4px; }
.group-row.open .caret { transform: rotate(90deg); }
.group-row .cnt {
    margin-left: 8px; font-size: 12px; color: var(--muted);
    background: #eef2ff; padding: 2px 8px; border-radius: 999px;
}
.detail-row td { background: #fff; font-size: 14px; }
.detail-row td.indent { padding-left: 34px; color: var(--muted); }

/* ---------- Toast ---------- */
.toast {
    position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px);
    background: var(--ink); color: #fff; padding: 11px 18px; border-radius: 10px;
    font-size: 14px; font-weight: 500; opacity: 0; pointer-events: none;
    transition: .25s; z-index: 50;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--red); }

/* ---------- Modal ---------- */
.modal {
    position: fixed; inset: 0; background: rgba(15,23,42,.45);
    display: none; place-items: center; z-index: 40; padding: 18px;
}
.modal.show { display: grid; }
.modal-card {
    background: #fff; border-radius: var(--radius); padding: 22px;
    width: 100%; max-width: 380px; box-shadow: 0 20px 50px rgba(0,0,0,.25);
}
.modal-card h3 { margin: 0 0 16px; }
.modal-card form { display: grid; gap: 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }

/* ---------- Responsive ---------- */
@media (max-width: 720px) {
    .cards { grid-template-columns: 1fr 1fr; }
    .form .row { grid-template-columns: 1fr; }
    .brand h1 { font-size: 18px; }
}
