:root {
  --nav-bg: #1c2740;
  --nav-bg-2: #16203a;
  --nav-text: #cdd6ea;
  --nav-muted: #7d8aa8;
  --brand: #2563eb;
  --brand-dark: #1d4ed8;
  --green: #15803d;
  --teal: #0f766e;
  --purple: #7e22ce;
  --red: #dc2626;
  --red-dark: #991b1b;
  --orange: #ea7a12;
  --amber: #d97706;
  --page: #eef2f7;
  --card: #ffffff;
  --line: #dde3ec;
  --line-soft: #edf1f6;
  --text: #1b2333;
  --muted: #64748b;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--page); color: var(--text); font-size: 14px; display: flex; min-height: 100vh; }
a { color: var(--brand-dark); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- sidebar ---------- */
.sidebar {
  width: 236px; flex: 0 0 236px; background: var(--nav-bg); color: var(--nav-text);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 16px 14px; color: #fff; text-decoration: none !important; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 9px; background: var(--brand); color: #fff; display: grid; place-items: center;
  font-weight: 800; font-size: 20px; letter-spacing: -.5px;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-size: 19px; letter-spacing: .3px; }
.brand-text small { color: var(--nav-muted); font-size: 11px; }
.nav-title { color: var(--nav-muted); font-size: 10.5px; font-weight: 700; letter-spacing: .6px; padding: 16px 18px 6px; }
.nav-link {
  display: block; margin: 2px 10px; padding: 10px 12px; border-radius: 8px; color: var(--nav-text);
  font-weight: 600; font-size: 13.5px; text-decoration: none !important;
}
.nav-link:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.nav-link.active { background: var(--brand); color: #fff; box-shadow: 0 2px 8px rgba(37, 99, 235, .35); }
.sidebar-foot { margin-top: auto; padding: 12px 10px 14px; display: grid; gap: 8px; }
.sync-box, .user-box { background: var(--nav-bg-2); border-radius: 9px; padding: 10px 12px; }
.sync-title { color: var(--nav-muted); font-size: 10.5px; font-weight: 700; letter-spacing: .5px; margin-bottom: 4px; }
.sync-line { display: flex; gap: 8px; align-items: flex-start; font-size: 12px; color: #e5ebf7; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #94a3b8; flex: 0 0 9px; margin-top: 4px; }
.dot.ok { background: #22c55e; }
.dot.err { background: #ef4444; }
.user-name { color: #fff; font-weight: 700; font-size: 13px; }
.user-sub { color: var(--nav-muted); font-size: 11.5px; }
.user-links { font-size: 12px; margin-top: 4px; }
.user-links a { color: #93b4ff; }

/* ---------- main ---------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  background: var(--card); border-bottom: 1px solid var(--line); padding: 14px 24px; display: flex; align-items: center; gap: 18px;
  position: sticky; top: 0; z-index: 20;
}
.page-head h1 { margin: 0; font-size: 21px; font-weight: 800; letter-spacing: -.2px; }
.page-head p { margin: 2px 0 0; color: var(--muted); font-size: 12.5px; }
.top-tools { margin-left: auto; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: flex-end; }
.tool { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12.5px; }
.version { background: #eef2ff; color: #4338ca; font-weight: 700; font-size: 11.5px; padding: 6px 10px; border-radius: 8px; border: 1px solid #e0e7ff; }
.menu-toggle { display: none; border: 0; background: none; font-size: 22px; cursor: pointer; }
.content { padding: 18px 24px 24px; flex: 1; }
.foot { text-align: center; color: var(--muted); font-size: 11.5px; padding: 10px; }

select, input[type=text], input[type=password], input[type=number], input[type=date], input[type=search], input[type=email], textarea {
  border: 1px solid #cbd5e1; border-radius: 7px; padding: 8px 10px; font: inherit; background: #fff; color: var(--text); min-width: 0;
}
select:focus, input:focus, textarea:focus { outline: 2px solid rgba(37, 99, 235, .25); border-color: var(--brand); }

/* ---------- cards & panels ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card + .card { margin-top: 16px; }
.card-pad { padding: 16px 18px; }
.card h2 { font-size: 16px; margin: 0 0 12px; }
.card h3 { font-size: 14px; margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.stat { padding: 16px 18px; border-radius: var(--radius); color: #fff; box-shadow: var(--shadow); text-decoration: none !important; display: block; }
.stat .num { font-size: 30px; font-weight: 800; line-height: 1.1; }
.stat .lbl { font-size: 12.5px; opacity: .92; font-weight: 600; margin-top: 4px; }
.stat-green { background: var(--green); }
.stat-teal { background: var(--teal); }
.stat-blue { background: var(--brand-dark); }
.stat-red { background: var(--red); }
.stat-orange { background: var(--orange); }
.stat-purple { background: var(--purple); }
.stat-slate { background: #334155; }

/* ---------- toolbar ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 12px; }
.toolbar .spacer { flex: 1; }
.search { display: flex; align-items: center; gap: 10px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; margin-bottom: 12px; }
.search input { flex: 1; max-width: 420px; }
.btn {
  border: 0; border-radius: 7px; padding: 9px 14px; font: inherit; font-weight: 700; font-size: 13px; cursor: pointer; color: #fff;
  background: var(--brand); display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; text-decoration: none !important;
}
.btn:hover { filter: brightness(1.07); }
.btn:disabled { opacity: .55; cursor: wait; }
.btn-green { background: var(--green); }
.btn-purple { background: var(--purple); }
.btn-dark { background: var(--brand-dark); }
.btn-red { background: var(--red); }
.btn-orange { background: var(--orange); }
.btn-light { background: #fff; color: var(--text); border: 1px solid #cbd5e1; }
.btn-sm { padding: 5px 9px; font-size: 12px; }
.chip { color: #fff; border-radius: 7px; padding: 8px 12px; font-weight: 700; font-size: 12.5px; white-space: nowrap; }
.chip-green { background: var(--green); }
.chip-teal { background: var(--teal); }
.chip-blue { background: var(--brand-dark); }
.chip-red { background: var(--red); }
.chip-orange { background: var(--orange); }
.chip-gray { background: #64748b; }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 0; }
.tab {
  padding: 9px 14px; border: 1px solid var(--line); border-bottom: 0; border-radius: 8px 8px 0 0; background: #f8fafc; color: var(--text);
  font-weight: 600; text-decoration: none !important; display: inline-flex; gap: 8px; align-items: center;
}
.tab.active { background: #fff; position: relative; top: 1px; }
.badge { background: var(--teal); color: #fff; border-radius: 999px; padding: 1px 8px; font-size: 11.5px; font-weight: 700; }
.badge-blue { background: var(--brand-dark); }

/* ---------- tables ---------- */
.table-wrap { background: var(--card); border: 1px solid var(--line); border-radius: 0 var(--radius) var(--radius) var(--radius); overflow: auto; max-height: calc(100vh - 290px); }
.table-wrap.round { border-radius: var(--radius); }
table.grid-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.grid-table th {
  text-align: left; font-weight: 600; color: #334155; background: #f8fafc; padding: 9px 10px; border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line-soft); position: sticky; top: 0; z-index: 1; white-space: nowrap;
}
.grid-table td { padding: 6px 10px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
.grid-table tbody tr:hover { background: #f5f8ff; }
.grid-table tbody tr.selected { background: #dbeafe; }
.grid-table .chk { width: 34px; text-align: center; }
.grid-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.grid-table .nowrap { white-space: nowrap; }
.grid-table .mono { font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; }
.thumb { width: 34px; height: 34px; object-fit: contain; border-radius: 4px; background: #fff; border: 1px solid var(--line-soft); }
.items { display: grid; gap: 2px; }
.item-line { display: flex; gap: 6px; align-items: center; }
.qty { background: #0f172a; color: #fff; border-radius: 5px; padding: 0 6px; font-weight: 700; font-size: 11.5px; }
.qty-1 { background: #e2e8f0; color: #0f172a; }
.empty { padding: 40px; text-align: center; color: var(--muted); }

.dl-late { color: var(--red-dark); font-weight: 800; }
.dl-today { color: var(--red); font-weight: 700; }
.dl-tomorrow { color: var(--amber); font-weight: 700; }
.dl-later { color: var(--brand-dark); font-weight: 600; }
.dl-none { color: var(--muted); }

.pill { display: inline-block; border-radius: 999px; padding: 2px 9px; font-size: 11.5px; font-weight: 700; }
.pill-ok { background: #dcfce7; color: #166534; }
.pill-warn { background: #fef3c7; color: #92400e; }
.pill-err { background: #fee2e2; color: #991b1b; }
.pill-info { background: #dbeafe; color: #1e40af; }
.pill-muted { background: #e2e8f0; color: #334155; }

/* ---------- forms ---------- */
.form { display: grid; gap: 12px; max-width: 640px; }
.form-row { display: grid; gap: 5px; }
.form-row label { font-weight: 600; font-size: 13px; }
.form-row .hint { font-size: 12px; color: var(--muted); }
.form-inline { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; }
.form-inline .form-row { min-width: 160px; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 600; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 4px; }
.code {
  font-family: ui-monospace, Consolas, monospace; background: #0f172a; color: #e2e8f0; padding: 10px 12px; border-radius: 8px;
  word-break: break-all; font-size: 13px;
}

/* ---------- alerts ---------- */
.alert { margin: 14px 24px 0; padding: 11px 14px; border-radius: 8px; font-weight: 600; white-space: pre-line; }
.alert-ok { background: #dcfce7; color: #14532d; border: 1px solid #bbf7d0; }
.alert-err { background: #fee2e2; color: #7f1d1d; border: 1px solid #fecaca; }
.alert-info { background: #e0f2fe; color: #0c4a6e; border: 1px solid #bae6fd; margin: 0 0 12px; }

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); display: grid; place-items: center; z-index: 100; padding: 16px; }
.modal[hidden] { display: none; }
.modal-box { background: #fff; border-radius: 12px; width: min(560px, 100%); max-height: 90vh; display: flex; flex-direction: column; box-shadow: 0 20px 50px rgba(0, 0, 0, .25); }
.modal-head { display: flex; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-x { margin-left: auto; border: 0; background: none; font-size: 22px; cursor: pointer; color: var(--muted); }
.modal-body { padding: 16px 18px; overflow: auto; white-space: pre-line; }
.modal-body ul { margin: 8px 0 0; padding-left: 18px; white-space: normal; font-size: 12.5px; color: #7f1d1d; }
.modal-foot { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
.spinner { width: 22px; height: 22px; border: 3px solid #cbd5e1; border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; vertical-align: middle; margin-right: 10px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- login ---------- */
body.bare { display: block; }
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: radial-gradient(1200px 600px at 20% -10%, #2b3b63 0%, var(--nav-bg) 55%, #111a2e 100%); }
.auth-card { background: #fff; border-radius: 14px; padding: 28px; width: min(400px, 100%); box-shadow: 0 25px 60px rgba(0, 0, 0, .35); }
.auth-card .brand { color: var(--text); padding: 0 0 18px; }
.auth-card .brand-text small { color: var(--muted); }
.auth-card .btn { width: 100%; justify-content: center; padding: 11px; }
.auth-card .form { max-width: none; }

@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  .sidebar { position: fixed; left: -250px; z-index: 50; transition: left .2s; }
  body.nav-open .sidebar { left: 0; }
  .menu-toggle { display: block; }
  .topbar { flex-wrap: wrap; padding: 12px 16px; }
  .top-tools { margin-left: 0; width: 100%; justify-content: flex-start; }
  .tool span { display: none; }
  .content { padding: 14px 16px; }
  .grid-2 { grid-template-columns: 1fr; }
  .table-wrap { max-height: none; }
  .alert { margin: 12px 16px 0; }
}
@media (max-width: 520px) {
  .grid-4 { grid-template-columns: 1fr 1fr; }
  .stat .num { font-size: 24px; }
  #labelFormat { max-width: 200px; }
}
