:root {
  --red: #b3000f;
  --ink: #16181d;
  --muted: #6b7280;
  --line: #e5e7eb;
  --bg: #f6f7f9;
  --card: #fff;
  --green: #0f7b3f;
  --amber: #b45309;
  --blue: #1d4ed8;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}
h1, h2, h3 { margin: 0 0 .4em; line-height: 1.2; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
[hidden] { display: none !important; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card {
  background: var(--card); padding: 32px; border-radius: 16px; width: min(380px, 100%);
  box-shadow: 0 10px 40px rgba(0,0,0,.08); display: grid; gap: 14px;
}
.login-card h1 { font-size: 22px; }
.login-card h1 span, .brand span { color: var(--red); }
.login-card p { margin: 0; color: var(--muted); }
.login-card label { display: grid; gap: 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
.err { color: var(--red); font-size: 13px; }

/* shell */
.topbar {
  position: sticky; top: 0; z-index: 20; background: #fff; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 18px; padding: 10px 18px; flex-wrap: wrap;
}
.brand { font-weight: 800; letter-spacing: -.01em; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.tabs a { padding: 7px 11px; border-radius: 8px; color: #374151; font-weight: 600; font-size: 14px; }
.tabs a:hover { background: #f3f4f6; text-decoration: none; }
.tabs a.on { background: #fde8ea; color: var(--red); }
.view { padding: 22px 18px 60px; max-width: 1200px; margin: 0 auto; }
.head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.head h1 { font-size: 22px; margin: 0; flex: 1; }

/* cards + stats */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 20px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
.stat b { display: block; font-size: 24px; line-height: 1.1; }
.stat span { color: var(--muted); font-size: 12.5px; }
.stat.warn b { color: var(--amber); }
.stat.bad b { color: var(--red); }
.stat.good b { color: var(--green); }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: 12px; margin-bottom: 18px; overflow: hidden; }
.panel > h2 { font-size: 15px; padding: 13px 16px; margin: 0; border-bottom: 1px solid var(--line); display: flex; gap: 8px; align-items: center; }
.panel > h2 small { color: var(--muted); font-weight: 500; }

/* tables */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 9px 14px; border-bottom: 1px solid #f0f1f3; vertical-align: top; }
th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: #fafbfc; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fcfcfd; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { padding: 22px 16px; color: var(--muted); font-size: 14px; }

/* badges */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 700; white-space: nowrap; }
.b-pending { background: #fef3c7; color: #92400e; }
.b-paid { background: #dbeafe; color: #1e40af; }
.b-delivered, .b-active { background: #dcfce7; color: #166534; }
.b-cancelled, .b-refunded, .b-expired { background: #f3f4f6; color: #4b5563; }
.b-open { background: #fee2e2; color: #991b1b; }
.b-renewed, .b-replaced, .b-closed { background: #ede9fe; color: #5b21b6; }
.b-soon { background: #ffedd5; color: #9a3412; }
.b-over { background: #fee2e2; color: #991b1b; }

/* buttons */
.btn { border: 1px solid var(--line); background: #fff; border-radius: 9px; padding: 8px 13px; font: inherit; font-weight: 600; cursor: pointer; }
.btn:hover { background: #f9fafb; }
.btn.primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn.primary:hover { background: #96000c; }
.btn.ghost { background: transparent; }
.btn.sm { padding: 4px 9px; font-size: 12.5px; border-radius: 7px; }
.btn.link { border: 0; background: none; color: var(--blue); padding: 0; font-weight: 600; }
.btn.link:hover { text-decoration: underline; }

/* forms */
input, select, textarea {
  font: inherit; padding: 8px 10px; border: 1px solid #d1d5db; border-radius: 8px; background: #fff; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #fecaca; border-color: var(--red); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.field { display: grid; gap: 5px; margin-bottom: 12px; }
.field label { font-size: 12.5px; font-weight: 700; color: #4b5563; }
.field .hint { font-size: 12px; color: var(--muted); }
.toolbar { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; align-items: center; }
.toolbar input, .toolbar select { width: auto; min-width: 160px; }

/* modal */
.modal { border: 0; border-radius: 14px; padding: 0; width: min(620px, 94vw); box-shadow: 0 20px 60px rgba(0,0,0,.2); }
.modal::backdrop { background: rgba(15, 23, 42, .45); }
.modal-inner { padding: 22px; }
.modal-inner h2 { font-size: 18px; margin-bottom: 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
#modal-body { max-height: 65vh; overflow: auto; padding-right: 2px; }

/* detail */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 900px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 760px) {
  .grid2, .grid3, .detail-grid { grid-template-columns: 1fr; }
  .view { padding: 16px 12px 50px; }
  .tabs { order: 3; width: 100%; flex-wrap: nowrap; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs a { white-space: nowrap; }
  .topbar { gap: 10px; }
  table { font-size: 13px; }
  th, td { padding: 8px 10px; }
}
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 4px 10px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

/* prices */
.hint { color: var(--muted); font-size: 13px; margin: -6px 0 14px; }
.hint a { color: var(--red); }
tr.muted td { color: var(--muted); }
.price-input { width: 110px; text-align: right; padding: 7px 9px; border: 1px solid var(--line); border-radius: 8px; font: inherit; }
.price-input.dirty { border-color: var(--red); background: #fff5f5; font-weight: 700; }
.diff { margin: 8px 0 0; padding-left: 18px; line-height: 1.8; }
@media (max-width: 760px) {
  .old-price, th.old-price { display: none; }
  .prices-table { table-layout: fixed; }
  .prices-table th:nth-child(1) { width: 38%; }
  .prices-table th:nth-child(2) { width: 34%; }
  .prices-table th:nth-child(4) { width: 28%; }
  .prices-table td { word-break: break-word; }
  .price-input { width: 100%; min-width: 62px; padding: 6px; }
}

/* toast */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: #111827; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; z-index: 100;
  box-shadow: 0 8px 24px rgba(0,0,0,.25);
}
.toast.bad { background: var(--red); }
