/* ==========================================================
   Giao diện theo phong cách Etsy Shop Manager
   Cam Etsy #F1641E · nút bo tròn viên thuốc · viền xám nhạt
   ========================================================== */
:root {
  --orange: #f1641e;
  --orange-dark: #d9540f;
  --orange-soft: #fff1ea;
  --ink: #222222;
  --ink-2: #595959;
  --muted: #757575;
  --bg: #ffffff;
  --bg-2: #faf9f8;
  --panel: #ffffff;
  --line: #e1e3df;
  --line-2: #efeeec;
  --ok: #258635;
  --ok-soft: #eefaf0;
  --warn: #a05e03;
  --warn-soft: #fff4e0;
  --danger: #a61a2e;
  --danger-soft: #fdeef0;
  --blue: #2f466c;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .06);
  --shadow: 0 2px 8px rgba(0, 0, 0, .08);
  --shadow-lg: 0 8px 28px rgba(0, 0, 0, .14);
  --r: 8px;
  --r-lg: 12px;
  --sidebar: 240px;
  --topbar: 56px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --orange: #ff7a3d; --orange-dark: #ff8f59; --orange-soft: #2e1a10;
    --ink: #eeeeee; --ink-2: #c9c9c9; --muted: #9d9d9d;
    --bg: #1a1a1a; --bg-2: #212121; --panel: #242424;
    --line: #3a3a3a; --line-2: #303030;
    --ok: #6cc47c; --ok-soft: #14261a; --warn: #e0a54a; --warn-soft: #2a2011;
    --danger: #f08a97; --danger-soft: #2b1418; --blue: #9db3d8;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.4); --shadow: 0 2px 8px rgba(0,0,0,.5);
    --shadow-lg: 0 8px 28px rgba(0,0,0,.6);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 "Graphik Webfont", -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { font-weight: 600; letter-spacing: -.2px; }

/* ---------------- đăng nhập ---------------- */
.login-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: linear-gradient(160deg, var(--orange-soft), var(--bg) 60%);
}
.login-card {
  width: min(410px, 100%); background: var(--panel); border: 1px solid var(--line);
  border-radius: 16px; box-shadow: var(--shadow-lg); padding: 34px 30px;
}
.login-card .logo { display: grid; place-items: center; margin-bottom: 20px; }
.login-card .logo .mark {
  width: 56px; height: 56px; border-radius: 16px; display: grid; place-items: center;
  background: var(--orange); color: #fff; font-size: 27px; margin-bottom: 12px;
}
.login-card h1 { margin: 0; font-size: 21px; text-align: center; }
.login-card .sub { text-align: center; color: var(--muted); font-size: 13.5px; margin: 6px 0 22px; }
.login-hint {
  margin-top: 18px; padding: 12px 14px; background: var(--bg-2); border: 1px solid var(--line);
  border-radius: var(--r); font-size: 12.5px; color: var(--ink-2); line-height: 1.7;
}

/* ---------------- khung ---------------- */
.app { display: none; min-height: 100vh; }
.app.ready { display: block; }

.topbar {
  height: var(--topbar); background: var(--panel); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 14px; padding: 0 20px;
  position: sticky; top: 0; z-index: 30;
}
.topbar .mark {
  width: 30px; height: 30px; border-radius: 9px; background: var(--orange); color: #fff;
  display: grid; place-items: center; font-size: 16px; flex: 0 0 30px;
}
.topbar .shop { font-weight: 600; font-size: 15.5px; }
.topbar .spacer { flex: 1; }
.who { display: flex; align-items: center; gap: 9px; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; background: var(--blue); color: #fff;
  display: grid; place-items: center; font-size: 12.5px; font-weight: 700;
}
.who .meta { line-height: 1.25; }
.who .meta b { font-size: 13px; display: block; }
.who .meta span { font-size: 11.5px; color: var(--muted); }
.role-chip {
  font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px;
  padding: 2px 7px; border-radius: 4px; background: var(--orange-soft); color: var(--orange-dark);
}
.role-chip.staff { background: var(--bg-2); color: var(--muted); }

.shell { display: flex; align-items: flex-start; }
.sidebar {
  width: var(--sidebar); flex: 0 0 var(--sidebar); border-right: 1px solid var(--line);
  padding: 16px 10px; position: sticky; top: var(--topbar);
  height: calc(100vh - var(--topbar)); overflow-y: auto; background: var(--panel);
}
.nav { display: flex; flex-direction: column; gap: 1px; }
.nav a {
  display: flex; align-items: center; gap: 11px; padding: 9px 12px; border-radius: 22px;
  color: var(--ink-2); font-size: 14.5px;
}
.nav a:hover { background: var(--bg-2); color: var(--ink); }
.nav a.on { background: var(--ink); color: #fff; font-weight: 600; }
@media (prefers-color-scheme: dark) { .nav a.on { background: var(--orange); color: #17110d; } }
.nav .ico { width: 18px; text-align: center; font-size: 15px; }
.nav .pill {
  margin-left: auto; background: var(--bg-2); color: var(--muted);
  border-radius: 20px; padding: 1px 8px; font-size: 11.5px; font-weight: 600;
}
.nav a.on .pill { background: rgba(255, 255, 255, .22); color: #fff; }
.nav-sep { margin: 12px 12px 6px; font-size: 10.5px; text-transform: uppercase; letter-spacing: .8px; color: var(--muted); font-weight: 700; }
.sidebar-foot { margin-top: 16px; padding: 12px; font-size: 11.5px; color: var(--muted); border-top: 1px solid var(--line-2); line-height: 1.7; }

.main { flex: 1; min-width: 0; padding: 26px 30px 70px; background: var(--bg); }
.page-head { display: flex; align-items: flex-end; gap: 14px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 26px; }
.page-head p { margin: 3px 0 0; color: var(--muted); font-size: 13.5px; }
.page-head .spacer { flex: 1; }

/* màn hình hẹp: thanh điều hướng chuyển thành hàng ngang cuộn được */
@media (max-width: 900px) {
  .shell { flex-direction: column; }
  .sidebar {
    width: 100%; flex: none; height: auto; position: sticky; top: var(--topbar); z-index: 20;
    border-right: 0; border-bottom: 1px solid var(--line); padding: 8px 12px; overflow: visible;
  }
  .nav { flex-direction: row; flex-wrap: wrap; gap: 6px; }
  .nav a { white-space: nowrap; padding: 7px 13px; font-size: 13.5px; }
  .nav-sep, .sidebar-foot { display: none; }
  .main { padding: 18px 14px 60px; }
  .page-head h1 { font-size: 21px; }
  .who .meta { display: none; }
}

/* ---------------- thành phần ---------------- */
.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--r-lg); padding: 18px;
}
.card.flat { box-shadow: none; }
.card h3 { margin: 0 0 14px; font-size: 12px; text-transform: uppercase; letter-spacing: .7px; color: var(--muted); font-weight: 700; }
.grid { display: grid; gap: 14px; }
.g5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (max-width: 1200px) { .g5 { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 1050px) { .g4 { grid-template-columns: repeat(2, 1fr); } .g3, .g2 { grid-template-columns: 1fr; } }
@media (max-width: 700px) { .g5, .g4 { grid-template-columns: 1fr; } }

.kpi .label { font-size: 12.5px; color: var(--muted); font-weight: 500; }
.kpi .value { font-size: 27px; font-weight: 600; letter-spacing: -.8px; margin-top: 5px; }
.kpi .delta { font-size: 12.5px; margin-top: 5px; color: var(--muted); }
.up { color: var(--ok); font-weight: 600; }
.down { color: var(--danger); font-weight: 600; }

/* nút bo tròn viên thuốc kiểu Etsy */
.btn {
  background: var(--panel); border: 1px solid var(--ink); border-radius: 24px;
  padding: 9px 17px; cursor: pointer; font-weight: 600; font-size: 14px;
  transition: .14s; display: inline-flex; align-items: center; gap: 7px; white-space: nowrap;
}
.btn:hover { background: var(--bg-2); box-shadow: var(--shadow-sm); }
.btn.primary { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.btn.primary:hover { background: #000; }
@media (prefers-color-scheme: dark) {
  .btn.primary { background: var(--orange); border-color: var(--orange); color: #17110d; }
  .btn.primary:hover { background: var(--orange-dark); }
}
.btn.accent { background: var(--orange); border-color: var(--orange); color: #fff; }
.btn.accent:hover { background: var(--orange-dark); }
.btn.soft { border-color: var(--line); color: var(--ink-2); }
.btn.soft:hover { border-color: var(--ink); color: var(--ink); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); padding: 7px 11px; }
.btn.ghost:hover { background: var(--bg-2); color: var(--ink); box-shadow: none; }
.btn.sm { padding: 5px 12px; font-size: 12.5px; }
.btn.danger { border-color: var(--line); color: var(--danger); }
.btn.danger:hover { border-color: var(--danger); background: var(--danger-soft); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.input, select.input, textarea.input {
  width: 100%; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--r); padding: 9px 12px; outline: none; transition: .12s;
}
.input:focus { border-color: var(--ink); box-shadow: 0 0 0 1px var(--ink); }
textarea.input { resize: vertical; min-height: 68px; }
label.f { display: block; margin-bottom: 12px; }
label.f > span { display: block; font-size: 12.5px; color: var(--ink-2); margin-bottom: 5px; font-weight: 500; }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }

.toolbar { display: flex; gap: 9px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.toolbar .grow { flex: 1; min-width: 200px; }

/* thanh tab kiểu Etsy */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; overflow-x: auto; }
.tabs a {
  padding: 10px 15px; font-size: 14px; color: var(--muted); border-bottom: 3px solid transparent;
  white-space: nowrap; font-weight: 500;
}
.tabs a:hover { color: var(--ink); }
.tabs a.on { color: var(--ink); border-bottom-color: var(--orange); font-weight: 600; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .6px;
  color: var(--muted); font-weight: 700; padding: 10px 12px; border-bottom: 1px solid var(--line);
  white-space: nowrap; background: var(--bg-2);
}
td { padding: 12px; border-bottom: 1px solid var(--line-2); vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--bg-2); }
tbody tr[data-open] { cursor: pointer; }
tr.total-row td { font-weight: 700; background: var(--bg-2); border-top: 2px solid var(--line); }
.table-wrap { overflow-x: auto; border-radius: var(--r-lg); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.dim { color: var(--muted); }
.small { font-size: 12.5px; }
.trunc { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }
.neg { color: var(--danger); }
.pos { color: var(--ok); }

.badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 20px;
  font-size: 12px; font-weight: 600; border: 1px solid transparent; white-space: nowrap;
}
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: 0 0 7px; }
.tag {
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 20px;
  padding: 2px 9px; font-size: 11.5px; color: var(--ink-2);
}
.lock { font-size: 11.5px; color: var(--muted); }

.alert { border-radius: var(--r-lg); padding: 13px 16px; border: 1px solid; font-size: 13.5px; line-height: 1.6; }
.alert.warn { background: var(--warn-soft); border-color: #f0d5a0; color: var(--warn); }
.alert.info { background: var(--orange-soft); border-color: #f8d3c2; color: #8a3a12; }
.alert.ok { background: var(--ok-soft); border-color: #b6e3bf; color: var(--ok); }
.alert.err { background: var(--danger-soft); border-color: #f2c0c8; color: var(--danger); }
@media (prefers-color-scheme: dark) {
  .alert.warn { border-color: #59431a; }
  .alert.info { border-color: #5a3722; color: #ffb894; }
  .alert.ok { border-color: #275b32; }
  .alert.err { border-color: #5f2630; }
}

/* biểu đồ cột */
.chart { display: flex; align-items: flex-end; gap: 7px; height: 190px; padding-top: 10px; }
.chart .col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 6px; height: 100%; }
.chart .bar { width: 100%; border-radius: 5px 5px 2px 2px; min-height: 3px; background: var(--orange); opacity: .85; transition: .15s; }
.chart .bar.alt { background: var(--blue); }
.chart .col:hover .bar { opacity: 1; }
.chart .cap { font-size: 10.5px; color: var(--muted); white-space: nowrap; }
.chart .val { font-size: 10.5px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* thanh ngang tỉ trọng */
.hbar { height: 8px; background: var(--bg-2); border-radius: 20px; overflow: hidden; }
.hbar > i { display: block; height: 100%; background: var(--orange); border-radius: 20px; }

/* luồng trạng thái */
.pipe { display: flex; gap: 9px; flex-wrap: wrap; }
.pipe .step {
  flex: 1 1 118px; border: 1px solid var(--line); border-radius: var(--r-lg); padding: 12px 13px;
  background: var(--panel); transition: .14s;
}
.pipe .step:hover { border-color: var(--ink); box-shadow: var(--shadow-sm); }
.pipe .step .n { font-size: 22px; font-weight: 600; }
.pipe .step .l { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ngăn kéo & hộp thoại */
.overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, .42); display: flex; justify-content: flex-end; z-index: 50; }
.overlay.center { align-items: center; justify-content: center; padding: 20px; }
.drawer {
  background: var(--bg); width: min(820px, 100%); height: 100%; overflow-y: auto;
  border-left: 1px solid var(--line); padding: 22px 26px 70px; animation: slide .16s ease-out;
}
.modal {
  background: var(--bg); width: min(560px, 100%); border-radius: 16px; border: 1px solid var(--line);
  padding: 24px; max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow-lg);
}
@keyframes slide { from { transform: translateX(26px); opacity: .3; } to { transform: none; opacity: 1; } }
.drawer-head { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 18px; }
.drawer-head h2 { margin: 0; font-size: 21px; }

.timeline { list-style: none; margin: 0; padding: 0; font-size: 13px; }
.timeline li { padding: 7px 0 7px 16px; border-left: 2px solid var(--line); position: relative; }
.timeline li::before { content: ''; position: absolute; left: -5px; top: 14px; width: 8px; height: 8px; border-radius: 50%; background: var(--line); }

.toast {
  position: fixed; bottom: 22px; right: 22px; z-index: 100; background: var(--ink); color: var(--bg);
  border-radius: 26px; padding: 12px 20px; box-shadow: var(--shadow-lg); font-size: 13.5px;
  max-width: 400px; font-weight: 500;
}
.toast.err { background: var(--danger); color: #fff; }
.toast.ok { background: var(--ok); color: #fff; }

.empty { text-align: center; padding: 46px 20px; color: var(--muted); }
.empty .big { font-size: 34px; margin-bottom: 10px; }
code.k { background: var(--bg-2); border: 1px solid var(--line); border-radius: 5px; padding: 1px 6px; font-size: 12.5px; font-family: Consolas, monospace; }
hr.sep { border: 0; border-top: 1px solid var(--line); margin: 18px 0; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

/* dòng lãi lỗ trong báo cáo */
.pl-line { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line-2); }
.pl-line:last-child { border-bottom: 0; }
.pl-line .lbl { flex: 1; font-size: 14px; }
.pl-line .amt { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.pl-line.head { border-bottom: 2px solid var(--line); font-weight: 600; }
.pl-line.total { border-top: 2px solid var(--ink); border-bottom: 0; margin-top: 6px; padding-top: 14px; }
.pl-line.total .lbl, .pl-line.total .amt { font-size: 17px; font-weight: 700; }
.pl-line .sub { font-size: 11.5px; color: var(--muted); }
.pl-edit { width: 110px; text-align: right; }

/* ---------------- icon ---------------- */
.ico-svg { flex: 0 0 auto; vertical-align: -3px; }
.nav .ico { width: 18px; height: 18px; display: inline-flex; align-items: center; justify-content: center; }
.nav .ico .ico-svg { vertical-align: 0; }
.tabs a .ico-svg { vertical-align: -3px; margin-right: 2px; }
.btn .ico-svg { margin-right: -1px; }
.empty .big .ico-svg { opacity: .45; }
.alert .ico-svg { vertical-align: -3px; }
.topbar .mark svg, .login-card .logo .mark svg { width: 60%; height: 60%; }
