:root {
  --primary: #0f766e;
  --primary-dark: #115e59;
  --primary-light: #ccfbf1;
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --red: #dc2626;
  --red-bg: #fee2e2;
  --amber: #b45309;
  --amber-bg: #fef3c7;
  --green: #15803d;
  --green-bg: #dcfce7;
}
* { box-sizing: border-box; }
body {
  margin: 0; display: flex; min-height: 100vh;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 14px; color: var(--text); background: var(--bg);
}

/* ---------- sidebar ---------- */
#sidebar {
  width: 210px; flex-shrink: 0; background: var(--primary-dark); color: #fff;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 16px; font-weight: 700; font-size: 15px; border-bottom: 1px solid rgba(255,255,255,.12); }
.logo { width: 34px; height: 34px; border-radius: 8px; background: #fff; color: var(--primary); display: grid; place-items: center; font-size: 20px; }
nav { display: flex; flex-direction: column; padding: 10px 8px; gap: 2px; }
nav a { color: #d1fae5; text-decoration: none; padding: 10px 12px; border-radius: 8px; }
nav a:hover { background: rgba(255,255,255,.08); }
nav a.active { background: #fff; color: var(--primary-dark); font-weight: 600; }

main { flex: 1; padding: 22px 26px; min-width: 0; }

/* ---------- login & hak akses ---------- */
body.role-kasir .admin-only { display: none !important; }
#user-box { margin-top: auto; padding: 12px 16px; border-top: 1px solid rgba(255,255,255,.12); font-size: 13px; }
#user-box .who { font-weight: 600; }
#user-box .role { color: #a7f3d0; font-size: 12px; }
#user-box button { background: transparent; color: #d1fae5; border: 1px solid rgba(255,255,255,.25); padding: 4px 10px; font-size: 12px; margin-top: 6px; }
#user-box button:hover { background: rgba(255,255,255,.1); }
#auth { position: fixed; inset: 0; z-index: 200; background: linear-gradient(135deg, #115e59, #0f766e 60%, #14b8a6); display: grid; place-items: center; padding: 20px; }
#auth[hidden] { display: none; }
.auth-card { background: #fff; border-radius: 16px; padding: 28px; width: min(400px, 100%); box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.auth-card h1 { margin: 10px 0 4px; font-size: 20px; }
.auth-card label { margin-top: 12px; }
.auth-card input { width: 100%; font-size: 15px; padding: 10px 12px; }
.auth-card .err { color: var(--red); min-height: 20px; margin-top: 10px; font-size: 13px; }
h1 { font-size: 22px; margin: 0 0 16px; }
h2 { font-size: 16px; margin: 0 0 12px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.right { text-align: right; }
.bold { font-weight: 700; }

.card { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 16px; margin-bottom: 16px; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; }
.stat .label { color: var(--muted); font-size: 12px; }
.stat .value { font-size: 22px; font-weight: 700; margin-top: 4px; }

/* ---------- form ---------- */
input, select, textarea, button { font: inherit; }
input, select, textarea {
  padding: 8px 10px; border: 1px solid #cbd5e1; border-radius: 8px; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-light); border-color: var(--primary); }
label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
label > input, label > select, label > textarea { font-size: 14px; color: var(--text); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }

button, .btn {
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border); background: #fff; cursor: pointer; color: var(--text);
}
button:hover { background: #f8fafc; }
button.primary { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
button.primary:hover { background: var(--primary-dark); }
button.danger { color: var(--red); border-color: #fecaca; }
button.danger:hover { background: var(--red-bg); }
button.big { padding: 14px; font-size: 17px; width: 100%; }
button.link { border: none; background: none; color: var(--primary); padding: 2px 4px; }
button:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- tabel ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: #f8fafc; white-space: nowrap; }
tbody tr:hover { background: #f8fafc; }
td.num, th.num { text-align: right; white-space: nowrap; }
.empty { text-align: center; color: var(--muted); padding: 24px; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 11px; font-weight: 600; }
.badge.red { background: var(--red-bg); color: var(--red); }
.badge.amber { background: var(--amber-bg); color: var(--amber); }
.badge.green { background: var(--green-bg); color: var(--green); }
.badge.gray { background: #e2e8f0; color: #475569; }

/* ---------- kasir ---------- */
.pos { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; align-items: start; }
@media (max-width: 1100px) { .pos { grid-template-columns: minmax(0, 1fr); } }
.search-box { position: relative; }
.search-box input { width: 100%; font-size: 16px; padding: 12px 14px; }
.dropdown {
  position: absolute; top: 100%; left: 0; right: 0; z-index: 20; background: #fff; border: 1px solid var(--border);
  border-radius: 8px; box-shadow: 0 10px 25px rgba(0,0,0,.1); max-height: 360px; overflow-y: auto; margin-top: 4px;
}
.dropdown div { padding: 10px 12px; cursor: pointer; display: flex; justify-content: space-between; gap: 10px; }
.dropdown div:hover, .dropdown div.sel { background: var(--primary-light); }
.cart input { width: 80px; padding: 6px; text-align: right; }
.total-box { font-size: 32px; font-weight: 800; color: var(--primary-dark); text-align: right; }
.pay-panel label { margin-bottom: 10px; }
.pay-panel input { font-size: 18px; text-align: right; }
.line { display: flex; justify-content: space-between; padding: 4px 0; }

/* ---------- pembelian ---------- */
.items-table input, .items-table select { padding: 6px; font-size: 13px; width: 100%; min-width: 60px; }
.items-table td { padding: 4px; }
.items-table .w-obat { min-width: 220px; }
.items-table .w-s { width: 70px; }
.items-table .w-sat { width: 120px; min-width: 120px; }
.items-table .w-hj { width: 140px; min-width: 140px; }
.margin-bar { background: var(--primary-light); border-radius: 8px; padding: 8px 12px; margin-bottom: 10px; gap: 8px; }
.margin-bar select { padding: 4px 8px; }
.items-table .w-m { width: 110px; }
.items-table .w-d { width: 140px; }
.hint { font-size: 11px; color: var(--muted); margin-top: 2px; white-space: nowrap; }
.totals { max-width: 380px; margin-left: auto; }
.totals .line input { width: 150px; text-align: right; }

/* ---------- modal & toast ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(15,23,42,.45); display: grid; place-items: center; z-index: 50; padding: 20px; }
.modal { background: #fff; border-radius: 14px; padding: 20px; width: min(720px, 100%); max-height: 90vh; overflow-y: auto; }
.modal.wide { width: min(1000px, 100%); }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.modal-head h2 { margin: 0; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

#toast { position: fixed; bottom: 20px; right: 20px; z-index: 100; display: flex; flex-direction: column; gap: 8px; }
#toast div { background: #0f172a; color: #fff; padding: 12px 16px; border-radius: 10px; box-shadow: 0 6px 20px rgba(0,0,0,.2); max-width: 400px; }
#toast div.err { background: var(--red); }

/* ---------- struk ---------- */
.struk { font-family: "Courier New", monospace; font-size: 12px; color: #000; width: 100%; }
.struk .c { text-align: center; }
.struk hr { border: none; border-top: 1px dashed #000; margin: 6px 0; }
.struk .l { display: flex; justify-content: space-between; gap: 6px; }
.struk-preview { border: 1px dashed #cbd5e1; padding: 12px; margin: 0 auto; background: #fff; }
#print-area { display: none; }

@media print {
  body { display: block; background: #fff; }
  body > *:not(#print-area) { display: none !important; }
  #print-area { display: block; }
}

@media (max-width: 900px) {
  body { flex-direction: column; }
  #sidebar { width: 100%; height: auto; position: static; }
  #user-box { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
  nav { flex-direction: row; overflow-x: auto; }
  nav a { white-space: nowrap; }
  .pos { grid-template-columns: 1fr; }
  main { padding: 14px; }
}
