/* ==============================================================================
   web/style.css — Dropdesk
   Bố cục: thanh trên + tab gạch chân, nội dung rộng tối đa 1200px, bảng là bề mặt chính;
   tạo listing mở ngăn kéo bên phải; trang /admin có cột điều hướng trái.
   ============================================================================== */

:root {
  --bg: #f4f6f7;
  --surface: #ffffff;
  --surface-2: #eef2f3;
  --border: #dbe2e4;
  --fg: #172225;
  --muted: #5d6d72;
  --accent: #1f5f6b;
  --accent-hover: #184c56;
  --accent-fg: #ffffff;
  --accent-soft: #e2eef0;
  --ok: #1d7348;
  --ok-soft: #e3f3ea;
  --warn: #9a5b00;
  --warn-soft: #fbf0dc;
  --danger: #b42318;
  --danger-soft: #fbe9e7;
  --focus: #2f8a9b;
  --shadow: 0 1px 2px rgb(16 34 38 / 6%), 0 4px 16px rgb(16 34 38 / 6%);
  --scrim: rgb(12 22 25 / 42%);

  --font-sans: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;
  --radius: 8px;
  --radius-sm: 6px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1416;
    --surface: #151d20;
    --surface-2: #1b252a;
    --border: #2a363b;
    --fg: #e3eaec;
    --muted: #92a3a8;
    --accent: #5fb0bf;
    --accent-hover: #7cc2cf;
    --accent-fg: #06252b;
    --accent-soft: #17323a;
    --ok: #5cc48d;
    --ok-soft: #133022;
    --warn: #e0a54a;
    --warn-soft: #33270f;
    --danger: #f07a6c;
    --danger-soft: #3a1a17;
    --focus: #7cc2cf;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 6px 20px rgb(0 0 0 / 30%);
    --scrim: rgb(0 0 0 / 55%);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0e1416;
  --surface: #151d20;
  --surface-2: #1b252a;
  --border: #2a363b;
  --fg: #e3eaec;
  --muted: #92a3a8;
  --accent: #5fb0bf;
  --accent-hover: #7cc2cf;
  --accent-fg: #06252b;
  --accent-soft: #17323a;
  --ok: #5cc48d;
  --ok-soft: #133022;
  --warn: #e0a54a;
  --warn-soft: #33270f;
  --danger: #f07a6c;
  --danger-soft: #3a1a17;
  --focus: #7cc2cf;
  --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 6px 20px rgb(0 0 0 / 30%);
  --scrim: rgb(0 0 0 / 55%);
  color-scheme: dark;
}

/* ---------- Nền tảng ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 400 14px/1.5 var(--font-sans);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; text-wrap: balance; font-weight: 600; }
h1 { font-size: 22px; }
h2 { font-size: 18px; }
h3 { font-size: 15px; }
p { margin: 0; }
a { color: var(--accent); }
img { max-width: 100%; }
code, .mono { font-family: var(--font-mono); font-size: 12.5px; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.icon { width: 16px; height: 16px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Nút ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 34px; padding: 0 14px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--fg);
  font: 500 13.5px/1 var(--font-sans); cursor: pointer; white-space: nowrap;
  transition: background-color .15s, border-color .15s, color .15s;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--fg); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn-sm { min-height: 28px; padding: 0 10px; font-size: 12.5px; }
.btn-icon { width: 34px; padding: 0; }
.btn-block { width: 100%; }
.btn[aria-busy="true"] { position: relative; color: transparent; }
.btn[aria-busy="true"]::after {
  content: ""; position: absolute; width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid var(--muted); border-right-color: transparent; animation: spin .8s linear infinite;
}
.btn-primary[aria-busy="true"]::after { border-color: var(--accent-fg); border-right-color: transparent; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Form ---------- */
.field { display: grid; gap: 6px; min-width: 0; }
.field > label, .label { font-size: 12.5px; font-weight: 500; color: var(--muted); }
.field .hint { font-size: 12px; color: var(--muted); }
input[type="text"], input[type="url"], input[type="number"], input[type="password"], select, textarea {
  width: 100%; min-height: 36px; padding: 7px 10px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--fg);
  font: 400 14px/1.4 var(--font-sans);
}
textarea { resize: vertical; font-family: var(--font-mono); font-size: 12.5px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px var(--accent-soft); }
.form-grid { display: grid; gap: 14px; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; }
.form-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- Thanh trên ---------- */
.topbar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1200px; margin: 0 auto; padding-inline: 16px;
  display: flex; align-items: center; gap: 16px; min-height: 56px; flex-wrap: wrap;
}
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 600; font-size: 15.5px; color: var(--fg); text-decoration: none; }
.brand img { width: 26px; height: 26px; }
.brand small { font-weight: 500; color: var(--muted); font-size: 12px; border-left: 1px solid var(--border); padding-left: 10px; }
.topbar-spacer { flex: 1; }
.account-picker { display: flex; align-items: center; gap: 8px; min-width: 0; }
.account-picker select { min-width: 0; width: 260px; max-width: 100%; }
.user-chip { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.avatar {
  width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); font-weight: 600; font-size: 12px; text-transform: uppercase;
}

.tabs { max-width: 1200px; margin: 0 auto; padding-inline: 16px; display: flex; gap: 4px; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; }
.tab {
  position: relative; display: inline-flex; align-items: center; gap: 8px;
  padding: 12px 12px; border: 0; background: none; color: var(--muted);
  font: 500 13.5px/1 var(--font-sans); cursor: pointer; white-space: nowrap;
}
.tab:hover { color: var(--fg); }
.tab[aria-selected="true"] { color: var(--fg); }
.tab[aria-selected="true"]::after { content: ""; position: absolute; inset: auto 8px 0; height: 2px; background: var(--accent); border-radius: 2px; }
.count {
  min-width: 18px; height: 18px; padding: 0 6px; border-radius: 9px;
  display: inline-grid; place-items: center; font-size: 11px; font-weight: 600;
  background: var(--danger-soft); color: var(--danger);
}

/* ---------- Nội dung ---------- */
.page { max-width: 1200px; margin: 0 auto; padding: 24px 16px 48px; display: grid; gap: 16px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.page-head p { color: var(--muted); margin-top: 4px; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); min-width: 0; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.panel-body { padding: 16px; display: grid; gap: 14px; }

/* ---------- Bảng ---------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data th {
  text-align: left; font-weight: 500; font-size: 12px; color: var(--muted); letter-spacing: .02em;
  padding: 10px 16px; background: var(--surface-2); border-bottom: 1px solid var(--border); white-space: nowrap;
}
table.data td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover td { background: color-mix(in srgb, var(--surface-2) 55%, transparent); }
table.data .right { text-align: right; }
.product { display: flex; align-items: center; gap: 12px; min-width: 260px; }
.thumb { width: 44px; height: 44px; border-radius: var(--radius-sm); object-fit: cover; background: var(--surface-2); border: 1px solid var(--border); flex: none; }
.thumb-empty { display: grid; place-items: center; color: var(--muted); }
.product-title { font-weight: 500; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }

/* ---------- Trạng thái ---------- */
.pill {
  display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 8px;
  border-radius: 11px; font-size: 12px; font-weight: 500; white-space: nowrap;
  background: var(--surface-2); color: var(--muted);
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill-ok { background: var(--ok-soft); color: var(--ok); }
.pill-warn { background: var(--warn-soft); color: var(--warn); }
.pill-danger { background: var(--danger-soft); color: var(--danger); }
.pill-accent { background: var(--accent-soft); color: var(--accent); }

/* ---------- Trạng thái rỗng ---------- */
.empty { padding: 40px 24px; text-align: center; display: grid; justify-items: center; gap: 10px; color: var(--muted); }
.empty h3 { color: var(--fg); }
.empty p { max-width: 52ch; }
.empty .icon { width: 28px; height: 28px; stroke-width: 1.5; }

/* ---------- Cảnh báo ---------- */
.alert-list { display: grid; gap: 8px; }
.alert-item {
  display: grid; grid-template-columns: 4px 1fr auto; gap: 14px; align-items: start;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px 14px 0; overflow: hidden;
}
.alert-item .stripe { align-self: stretch; margin-block: -14px; background: var(--warn); }
.alert-item[data-severity="CRITICAL"] .stripe, .alert-item[data-severity="ERROR"] .stripe { background: var(--danger); }
.alert-item[data-severity="INFO"] .stripe { background: var(--accent); }
.alert-meta { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.notice {
  display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: var(--radius);
  background: var(--accent-soft); color: var(--fg); font-size: 13px;
}
.notice .icon { color: var(--accent); margin-top: 2px; }
.notice-warn { background: var(--warn-soft); }
.notice-warn .icon { color: var(--warn); }

/* ---------- Đăng nhập ---------- */
.auth-screen { min-height: 100%; display: grid; place-items: center; padding: 32px 16px; }
.auth-card { width: min(380px, 100%); display: grid; gap: 20px; }
.auth-card .panel-body { padding: 24px; gap: 16px; }
.auth-brand { display: grid; justify-items: center; gap: 10px; text-align: center; }
.auth-brand img { width: 44px; height: 44px; }
.auth-brand p { color: var(--muted); }
.segmented { display: grid; grid-template-columns: 1fr 1fr; padding: 3px; gap: 3px; background: var(--surface-2); border-radius: var(--radius-sm); }
.segmented button { border: 0; background: transparent; padding: 7px; border-radius: 4px; font: 500 13px var(--font-sans); color: var(--muted); cursor: pointer; }
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--fg); box-shadow: var(--shadow); }
.form-error { color: var(--danger); font-size: 13px; min-height: 1em; }
.auth-foot { text-align: center; font-size: 12px; color: var(--muted); }

/* ---------- Ngăn kéo (tạo listing) ---------- */
.drawer-scrim { position: fixed; inset: 0; background: var(--scrim); z-index: 40; }
.drawer {
  position: fixed; inset: 0 0 0 auto; width: min(560px, 100%); z-index: 41;
  background: var(--surface); border-left: 1px solid var(--border); box-shadow: var(--shadow);
  display: grid; grid-template-rows: auto 1fr auto;
  padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px);
}
.drawer-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.drawer-body { overflow-y: auto; padding: 20px; display: grid; gap: 20px; align-content: start; }
.drawer-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.section-title { font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }

.summary { display: grid; gap: 0; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.summary-row { display: grid; grid-template-columns: 140px 1fr; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.summary-row:last-child { border-bottom: 0; }
.summary-row dt { color: var(--muted); }
.summary-row dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.metric { background: var(--surface); padding: 12px 14px; display: grid; gap: 2px; }
.metric .label { font-size: 12px; }
.metric strong { font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; }
.metric[data-tone="ok"] strong { color: var(--ok); }
.metric[data-tone="danger"] strong { color: var(--danger); }
.warnings { margin: 0; padding-left: 18px; color: var(--warn); font-size: 13px; display: grid; gap: 4px; }
.gallery { display: flex; gap: 8px; overflow-x: auto; }
.gallery img { width: 64px; height: 64px; object-fit: cover; border-radius: var(--radius-sm); border: 1px solid var(--border); flex: none; }

/* ---------- Hộp thoại ---------- */
dialog {
  border: 1px solid var(--border); border-radius: var(--radius); padding: 0; width: min(440px, calc(100% - 32px));
  background: var(--surface); color: var(--fg); box-shadow: var(--shadow);
}
dialog::backdrop { background: var(--scrim); }
.dialog-body { padding: 20px; display: grid; gap: 14px; }
.dialog-foot { padding: 12px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }

/* ---------- Toast ---------- */
.toasts { position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); z-index: 60; display: grid; gap: 8px; width: min(380px, calc(100% - 32px)); }
.toast {
  display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: var(--radius);
  background: var(--fg); color: var(--bg); box-shadow: var(--shadow); font-size: 13.5px; animation: toast-in .18s ease-out;
}
.toast[data-tone="error"] { background: var(--danger); color: #fff; }
.toast .icon { margin-top: 2px; }
.toast span { min-width: 0; overflow-wrap: anywhere; }
@keyframes toast-in { from { transform: translateY(6px); opacity: 0; } }

/* ---------- Admin ---------- */
.admin-layout { max-width: 1200px; margin: 0 auto; padding: 24px 16px 48px; display: grid; grid-template-columns: 200px 1fr; gap: 24px; align-items: start; }
.side-nav { position: sticky; top: calc(72px + env(safe-area-inset-top, 0px)); display: grid; gap: 2px; }
.side-nav button {
  display: flex; align-items: center; gap: 10px; text-align: left; padding: 9px 12px; border: 0; border-radius: var(--radius-sm);
  background: transparent; color: var(--muted); font: 500 13.5px var(--font-sans); cursor: pointer;
}
.side-nav button:hover { background: var(--surface-2); color: var(--fg); }
.side-nav button[aria-selected="true"] { background: var(--accent-soft); color: var(--accent); }
.admin-main { display: grid; gap: 16px; min-width: 0; }
.status-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.status-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; display: grid; gap: 8px; }
.status-card .label { font-size: 12px; }
.status-card .detail { font-size: 12.5px; color: var(--muted); overflow-wrap: anywhere; }
.result-box {
  margin: 0; padding: 12px 14px; border-radius: var(--radius-sm); background: var(--surface-2);
  font-family: var(--font-mono); font-size: 12.5px; white-space: pre-wrap; overflow-wrap: anywhere;
}

/* ---------- Màn hình hẹp ---------- */
@media (max-width: 760px) {
  .topbar-inner { gap: 10px; padding-block: 8px; }
  .account-picker { order: 3; width: 100%; }
  .account-picker select { width: 100%; }
  .brand small { display: none; }
  .admin-layout { grid-template-columns: 1fr; }
  .side-nav { position: static; grid-auto-flow: column; overflow-x: auto; scrollbar-width: none; }
  .side-nav button { white-space: nowrap; }
  .metrics { grid-template-columns: 1fr; }
  .summary-row { grid-template-columns: 1fr; gap: 2px; }
  table.data th, table.data td { padding-inline: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
