/* ============================================
   PharmaStock — Minimal Mono + Rose Accent
   ============================================ */

:root {
  --bg: #fafaf6;
  --bg-elev: #ffffff;
  --bg-sunk: #f3f1ec;
  --ink: #16110f;
  --ink-2: #3d3633;
  --ink-3: #6b625e;
  --ink-4: #9a918c;
  --line: #e6e1da;
  --line-2: #d8d2c8;
  --rose: #c9184a;
  --rose-2: #e64a78;
  --rose-soft: #fde4ec;
  --rose-tint: #fff1f5;
  --amber: #b97b18;
  --amber-soft: #fdf2d8;
  --green: #2c6e49;
  --green-soft: #e0efe5;
  --red: #b8202d;
  --red-soft: #fbe2e4;
  --shadow-sm: 0 1px 2px rgba(22, 17, 15, 0.04);
  --shadow-md: 0 4px 14px rgba(22, 17, 15, 0.06);
  --shadow-lg: 0 18px 40px rgba(22, 17, 15, 0.10);
  --radius: 10px;
  --radius-lg: 14px;
  --sans: "IBM Plex Sans Thai", "IBM Plex Sans", system-ui, -apple-system, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --tx-ease: cubic-bezier(.2,.7,.2,1);
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  font-family: var(--sans);
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 14px; }
.mono { font-family: var(--mono); font-feature-settings: "tnum" 1; }
.num { font-variant-numeric: tabular-nums; }

/* === App shell === */
.app {
  display: grid;
  grid-template-columns: 232px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--bg-elev);
  border-right: 1px solid var(--line);
  padding: 20px 14px;
  position: sticky; top: 0;
  height: 100vh;
  overflow-y: auto;
  display: flex; flex-direction: column;
}
.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--line); border-radius: 3px; }

.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 4px 10px 18px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 14px;
}
.brand-mark {
  width: 30px; height: 30px;
  background: var(--ink);
  color: var(--bg);
  display: grid; place-items: center;
  border-radius: 7px;
  font-weight: 600;
  font-size: 14px;
  letter-spacing: -0.02em;
  position: relative;
  overflow: hidden;
}
.brand-mark::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, transparent 0%, transparent 50%, var(--rose) 50%, var(--rose) 100%);
  opacity: 0.9;
  mix-blend-mode: normal;
  clip-path: polygon(100% 0, 100% 50%, 50% 50%);
}
.brand-name {
  font-weight: 600;
  font-size: 15px;
  letter-spacing: -0.01em;
}
.brand-sub {
  font-size: 10px;
  color: var(--ink-4);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-top: 1px;
}

.nav-section-label {
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-4);
  padding: 14px 10px 6px;
}

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  border-radius: 7px;
  color: var(--ink-2);
  font-size: 13.5px;
  cursor: pointer;
  position: relative;
  transition: background .15s var(--tx-ease), color .15s var(--tx-ease);
  user-select: none;
}
.nav-item:hover { background: var(--bg-sunk); }
.nav-item.active {
  background: var(--ink);
  color: var(--bg);
}
.nav-item.active .nav-ic { color: var(--rose-2); }
.nav-ic {
  width: 16px; height: 16px;
  color: var(--ink-3);
  display: grid; place-items: center;
  flex-shrink: 0;
}
.nav-item.active .nav-ic { color: var(--rose-2); }
.nav-badge {
  margin-left: auto;
  background: var(--rose-soft);
  color: var(--rose);
  font-size: 10px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 100px;
  font-family: var(--mono);
}
.nav-item.active .nav-badge { background: var(--rose); color: #fff; }

.sidebar-foot {
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  display: flex; align-items: center; gap: 10px;
}
.avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--rose-soft);
  color: var(--rose);
  display: grid; place-items: center;
  font-weight: 600;
  font-size: 12px;
  border: 1px solid var(--rose-soft);
}
.user-meta { font-size: 12px; }
.user-name { font-weight: 600; }
.user-role { color: var(--ink-4); font-size: 11px; }

/* === Main === */
.main {
  display: flex; flex-direction: column;
  min-width: 0;
}

.topbar {
  display: flex; align-items: center;
  padding: 14px 28px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  position: sticky; top: 0;
  z-index: 10;
  gap: 16px;
}
.crumb {
  font-size: 12px;
  color: var(--ink-4);
  letter-spacing: 0.04em;
}
.crumb b { color: var(--ink); font-weight: 600; letter-spacing: 0; }
.search {
  margin-left: auto;
  display: flex; align-items: center; gap: 8px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 10px;
  width: 280px;
  transition: border-color .15s var(--tx-ease), box-shadow .15s var(--tx-ease);
}
.search:focus-within {
  border-color: var(--ink);
  box-shadow: 0 0 0 3px var(--rose-tint);
}
.search input {
  border: 0; outline: 0; background: transparent;
  flex: 1; min-width: 0;
}
.kbd {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-4);
  border: 1px solid var(--line);
  background: var(--bg);
  border-radius: 4px;
  padding: 1px 5px;
}
.icon-btn {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink-2);
  transition: background .15s var(--tx-ease), border-color .15s var(--tx-ease);
}
.icon-btn:hover { background: var(--bg-sunk); border-color: var(--line-2); }
.icon-btn .dot {
  position: absolute; top: 6px; right: 6px;
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--rose);
  border: 1.5px solid var(--bg);
}
.icon-btn { position: relative; }

.content {
  padding: 28px;
  display: flex; flex-direction: column;
  gap: 24px;
  flex: 1;
}

/* === Page header === */
.page-head { display: flex; align-items: flex-end; gap: 20px; }
.page-title {
  font-size: 26px;
  letter-spacing: -0.02em;
  font-weight: 600;
  margin: 0;
}
.page-sub {
  font-size: 13px;
  color: var(--ink-3);
  margin: 4px 0 0;
}
.page-actions { margin-left: auto; display: flex; gap: 10px; }

/* === Buttons === */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  color: var(--ink);
  padding: 7px 14px;
  border-radius: 8px;
  font-weight: 500;
  font-size: 13.5px;
  transition: all .15s var(--tx-ease);
  white-space: nowrap;
}
.btn:hover { background: var(--bg-sunk); border-color: var(--line-2); }
.btn-primary {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--bg);
}
.btn-primary:hover {
  background: #000;
  border-color: #000;
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(22, 17, 15, 0.18);
}
.btn-rose {
  background: var(--rose);
  border-color: var(--rose);
  color: #fff;
}
.btn-rose:hover {
  background: #a8133c;
  border-color: #a8133c;
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(201, 24, 74, 0.25);
}
.btn-ghost {
  background: transparent;
  border-color: transparent;
}
.btn-ghost:hover { background: var(--bg-sunk); }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }

/* === Cards === */
.card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 18px;
  transition: transform .25s var(--tx-ease), box-shadow .25s var(--tx-ease), border-color .25s var(--tx-ease);
}
.card.hover-lift:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--line-2);
}
.card-head {
  display: flex; align-items: center;
  margin-bottom: 14px;
}
.card-title {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -0.005em;
}
.card-sub {
  font-size: 11px;
  color: var(--ink-4);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* === KPI cards === */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}
.kpi {
  position: relative;
  overflow: hidden;
}
.kpi-label {
  font-size: 11px;
  color: var(--ink-4);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 500;
}
.kpi-val {
  font-size: 30px;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin-top: 8px;
  font-variant-numeric: tabular-nums;
}
.kpi-val .unit { font-size: 14px; color: var(--ink-4); font-weight: 500; margin-left: 4px; }
.kpi-delta {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px;
  font-weight: 500;
  margin-top: 8px;
  font-family: var(--mono);
}
.kpi-delta.up { color: var(--green); }
.kpi-delta.down { color: var(--red); }
.kpi-delta.flat { color: var(--ink-4); }
.kpi-spark {
  position: absolute; right: 14px; top: 18px;
  opacity: 0.85;
}

/* === Tables === */
.tbl-wrap {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--bg-elev);
}
table.tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.tbl thead th {
  text-align: left;
  font-weight: 500;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-4);
  padding: 11px 14px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0;
  white-space: nowrap;
}
.tbl tbody td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
.tbl tbody tr {
  transition: background .12s var(--tx-ease);
}
.tbl tbody tr:hover { background: var(--bg); }
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl .right { text-align: right; font-variant-numeric: tabular-nums; }
.tbl .center { text-align: center; }

/* === Pills / Tags === */
.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px;
  border-radius: 100px;
  font-size: 11px;
  font-weight: 500;
  font-family: var(--mono);
  letter-spacing: 0;
  background: var(--bg-sunk);
  color: var(--ink-2);
  border: 1px solid var(--line);
  white-space: nowrap;
}
.pill.dot::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
}
.pill.ok { background: var(--green-soft); color: var(--green); border-color: transparent; }
.pill.warn { background: var(--amber-soft); color: var(--amber); border-color: transparent; }
.pill.crit { background: var(--red-soft); color: var(--red); border-color: transparent; }
.pill.rose { background: var(--rose-soft); color: var(--rose); border-color: transparent; }
.pill.ghost { background: transparent; }

.code {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink-2);
  background: var(--bg-sunk);
  padding: 1px 5px;
  border-radius: 3px;
}

/* === Form === */
.field { display: flex; flex-direction: column; gap: 6px; }
.field-row { display: flex; gap: 12px; }
.field-row > .field { flex: 1; min-width: 0; }
.label {
  font-size: 11px;
  color: var(--ink-3);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-weight: 500;
}
.input, .select, .textarea {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13.5px;
  color: var(--ink);
  width: 100%;
  transition: border-color .15s var(--tx-ease), box-shadow .15s var(--tx-ease);
  outline: 0;
}
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--ink);
  box-shadow: 0 0 0 3px var(--rose-tint);
}
.textarea { resize: vertical; min-height: 70px; font-family: inherit; }
.select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--ink-3) 50%), linear-gradient(135deg, var(--ink-3) 50%, transparent 50%); background-position: calc(100% - 14px) 14px, calc(100% - 9px) 14px; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; padding-right: 30px; }

/* === Modal === */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(22, 17, 15, 0.45);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: grid; place-items: center;
  z-index: 100;
  padding: 30px;
  animation: fadeIn .2s var(--tx-ease);
}
.modal {
  background: var(--bg-elev);
  border-radius: 16px;
  width: 100%;
  max-width: 720px;
  max-height: 90vh;
  display: flex; flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  animation: popIn .25s var(--tx-ease);
}
.modal.lg { max-width: 880px; }
.modal-head {
  display: flex; align-items: center;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
}
.modal-title { font-size: 16px; font-weight: 600; letter-spacing: -0.01em; }
.modal-sub { font-size: 12px; color: var(--ink-4); margin-top: 2px; }
.modal-body { padding: 22px; overflow-y: auto; }
.modal-foot {
  padding: 14px 22px;
  border-top: 1px solid var(--line);
  background: var(--bg);
  display: flex; gap: 10px; justify-content: flex-end;
}
.close-x {
  margin-left: auto;
  width: 28px; height: 28px;
  border-radius: 7px;
  background: transparent;
  border: 0;
  color: var(--ink-3);
  display: grid; place-items: center;
}
.close-x:hover { background: var(--bg-sunk); color: var(--ink); }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes popIn {
  from { opacity: 0; transform: translateY(8px) scale(.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* === Page transitions === */
.page {
  animation: pageEnter .35s var(--tx-ease);
}
@keyframes pageEnter {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* === Toast === */
.toast-stack {
  position: fixed; bottom: 24px; right: 24px;
  display: flex; flex-direction: column; gap: 10px;
  z-index: 200;
}
.toast {
  background: var(--ink);
  color: var(--bg);
  padding: 12px 16px;
  border-radius: 10px;
  display: flex; align-items: center; gap: 10px;
  font-size: 13px;
  box-shadow: var(--shadow-lg);
  min-width: 280px;
  animation: toastIn .3s var(--tx-ease);
  border-left: 3px solid var(--rose-2);
}
.toast.ok { border-left-color: #4ade80; }
.toast.err { border-left-color: #f87171; }
@keyframes toastIn {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

/* === Filter bar === */
.filterbar {
  display: flex; align-items: center; gap: 10px;
  flex-wrap: wrap;
}
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px;
  border-radius: 7px;
  font-size: 12.5px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  color: var(--ink-2);
  transition: all .15s var(--tx-ease);
}
.chip:hover { background: var(--bg-sunk); border-color: var(--line-2); }
.chip.on {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--bg);
}

/* === Charts === */
.bar-row {
  display: grid;
  grid-template-columns: 80px 1fr 50px;
  gap: 12px;
  align-items: center;
  padding: 6px 0;
  font-size: 12.5px;
}
.bar-track {
  height: 8px;
  background: var(--bg-sunk);
  border-radius: 100px;
  position: relative;
  overflow: hidden;
}
.bar-fill {
  position: absolute; inset: 0 auto 0 0;
  background: var(--ink);
  border-radius: 100px;
  transition: width .8s var(--tx-ease);
}
.bar-fill.rose { background: var(--rose); }

/* === Stepper === */
.stepper {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 22px;
}
.step {
  display: flex; align-items: center; gap: 8px;
  color: var(--ink-4);
  font-size: 12.5px;
}
.step-no {
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 1px solid var(--line-2);
  display: grid; place-items: center;
  font-family: var(--mono);
  font-size: 11px;
  background: var(--bg-elev);
}
.step.active { color: var(--ink); }
.step.active .step-no {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--bg);
}
.step.done .step-no {
  background: var(--rose);
  border-color: var(--rose);
  color: #fff;
}
.step.done { color: var(--ink-2); }
.step-line {
  flex: 1; height: 1px; background: var(--line);
}
.step.done + .step-line { background: var(--rose); }

/* === Drawer === */
.drawer-backdrop {
  position: fixed; inset: 0;
  background: rgba(22, 17, 15, 0.4);
  z-index: 90;
  animation: fadeIn .2s var(--tx-ease);
}
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: 480px;
  max-width: 100vw;
  background: var(--bg-elev);
  z-index: 100;
  display: flex; flex-direction: column;
  animation: drawerIn .3s var(--tx-ease);
  box-shadow: var(--shadow-lg);
}
@keyframes drawerIn {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}

/* === Misc === */
.hr { height: 1px; background: var(--line); border: 0; margin: 0; }
.row { display: flex; align-items: center; gap: 8px; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.muted { color: var(--ink-3); }
.mute2 { color: var(--ink-4); }
.tiny { font-size: 11px; }
.tag-cat {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; color: var(--ink-3);
  padding: 2px 6px;
  background: var(--bg-sunk);
  border-radius: 4px;
}
.empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--ink-4);
}

/* Number flip animation for KPIs */
.flipnum { display: inline-block; }

/* dashed divider */
.dashed { border-top: 1px dashed var(--line-2); margin: 14px 0; }

/* Hero card */
.hero {
  background: linear-gradient(135deg, #16110f 0%, #2a1a1f 100%);
  color: var(--bg);
  border-radius: var(--radius-lg);
  padding: 22px 26px;
  position: relative;
  overflow: hidden;
}
.hero::before {
  content: "";
  position: absolute;
  right: -60px; top: -60px;
  width: 220px; height: 220px;
  border-radius: 50%;
  background: radial-gradient(closest-side, var(--rose) 0%, transparent 70%);
  opacity: 0.4;
}
.hero-row { display: flex; align-items: center; gap: 30px; position: relative; z-index: 1; }
.hero-stat { display: flex; flex-direction: column; }
.hero-stat-label { font-size: 11px; color: rgba(250,250,246,0.55); letter-spacing: 0.08em; text-transform: uppercase; }
.hero-stat-val { font-size: 22px; font-weight: 600; letter-spacing: -0.01em; margin-top: 4px; font-variant-numeric: tabular-nums; }

/* === Tweaks panel override === */
.tweaks-panel { z-index: 250 !important; }

/* Responsive */
@media (max-width: 1100px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 800px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
}
