/* Swasthya Pharmacy Manager */
:root {
  --brand: #0f766e;
  --brand-dark: #115e59;
  --brand-soft: #e6f4f2;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --border: #e3e6ea;
  --text: #16191d;
  --text-2: #4b5260;
  --muted: #7a818e;
  --good: #15803d;   --good-bg: #e8f6ec;
  --warn: #a16207;   --warn-bg: #fdf4e1;
  --bad: #b42318;    --bad-bg: #fdecea;
  --info: #1d5fb8;   --info-bg: #e8f0fb;
  --series-1: #2a78d6;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --sidebar-w: 232px;
  font-size: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: -apple-system, "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
  background: var(--bg); color: var(--text); line-height: 1.45;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 .6em; line-height: 1.25; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
code { background: #eef0f3; padding: 1px 5px; border-radius: 4px; }
.muted { color: var(--muted); }
.small { font-size: .86em; }
.right, td.num, th.num { text-align: right; }
.nowrap { white-space: nowrap; }
.mt { margin-top: 16px; } .mb { margin-bottom: 16px; }
.hidden { display: none !important; }
.ico { width: 18px; height: 18px; flex: none; }

/* ---------- Layout ---------- */
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w);
  background: #0e2a2a; color: #cfe3e1; overflow-y: auto; z-index: 30;
  transition: transform .2s;
}
.brand { display: flex; gap: 10px; align-items: center; padding: 16px 14px; border-bottom: 1px solid rgba(255,255,255,.08); }
.brand strong { display: block; color: #fff; font-size: .98rem; }
.brand small { color: #8fb3af; }
.brand-mark { width: 34px; height: 34px; border-radius: 8px; background: var(--brand); color: #fff; display: grid; place-items: center; font-size: 24px; font-weight: 700; }
.sidebar nav { padding: 8px; display: flex; flex-direction: column; gap: 2px; }
.sidebar nav a { display: flex; align-items: center; gap: 10px; color: #cfe3e1; padding: 8px 10px; border-radius: 6px; }
.sidebar nav a:hover { background: rgba(255,255,255,.07); text-decoration: none; }
.sidebar nav a.active { background: var(--brand); color: #fff; }
.main { margin-left: var(--sidebar-w); min-height: 100vh; display: flex; flex-direction: column; }
.main.nosidebar { margin-left: 0; }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 10px 20px; background: var(--surface);
  border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20;
}
.topbar h1 { font-size: 1.15rem; margin: 0; flex: 1; }
.topbar-right { display: flex; align-items: center; gap: 16px; }
.today { color: var(--muted); }
.menu-toggle { display: none; }
.usermenu { position: relative; }
.usermenu summary { cursor: pointer; list-style: none; padding: 6px 10px; border-radius: 6px; }
.usermenu summary::-webkit-details-marker { display: none; }
.usermenu summary:hover { background: var(--surface-2); }
.usermenu .menu { position: absolute; right: 0; top: 110%; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); min-width: 180px; padding: 6px; }
.usermenu .menu a, .usermenu .menu button { display: block; width: 100%; text-align: left; padding: 8px 10px; background: none; border: 0; color: var(--text); font: inherit; cursor: pointer; border-radius: 4px; }
.usermenu .menu a:hover, .usermenu .menu button:hover { background: var(--surface-2); text-decoration: none; }
.content { padding: 20px; flex: 1; }
.foot { padding: 10px 20px; color: var(--muted); font-size: .8rem; }

/* ---------- Cards / grid ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px; }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h2, .card-head h3 { margin: 0; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi .label { color: var(--text-2); font-size: .85rem; }
.kpi .value { font-size: 1.5rem; font-weight: 650; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .sub { color: var(--muted); font-size: .8rem; margin-top: 2px; }
.kpi a.value { color: var(--text); display: block; }
.kpi.warn { border-left: 4px solid var(--warn); }
.kpi.bad { border-left: 4px solid var(--bad); }
.kpi.good { border-left: 4px solid var(--good); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.tbl th, .tbl td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
.tbl th { background: var(--surface-2); font-weight: 600; color: var(--text-2); font-size: .85rem; white-space: nowrap; }
.tbl tbody tr:hover { background: #fafbfc; }
.tbl tfoot td { font-weight: 650; background: var(--surface-2); }
.tbl.compact th, .tbl.compact td { padding: 5px 8px; }
.tbl tr.row-bad td { background: var(--bad-bg); }
.tbl tr.row-warn td { background: var(--warn-bg); }
.tbl .actions { white-space: nowrap; text-align: right; }
.empty { text-align: center; color: var(--muted); padding: 24px !important; }

/* ---------- Forms ---------- */
label { display: block; font-weight: 550; color: var(--text-2); font-size: .88rem; }
label > input, label > select, label > textarea { margin-top: 4px; }
input, select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid #cfd4db; border-radius: 6px; font: inherit; color: var(--text); background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(15,118,110,.25); border-color: var(--brand); }
input[type=checkbox], input[type=radio] { width: auto; }
label.check { display: flex; gap: 8px; align-items: center; font-weight: 500; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; }
.form-grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.form-grid .span2 { grid-column: span 2; }
.form-grid .span-all { grid-column: 1 / -1; }
.form-grid h3 { margin: 8px 0 0; }
.form-actions { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; margin-bottom: 12px; }
.filters label { min-width: 140px; }
.filters input, .filters select { padding: 6px 8px; }
.hint { font-weight: 400; color: var(--muted); font-size: .8rem; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 6px; border: 1px solid #cfd4db;
  background: #fff; color: var(--text); font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-danger { background: #fff; border-color: #f1b5af; color: var(--bad); }
.btn-danger:hover { background: var(--bad-bg); }
.btn-sm { padding: 4px 9px; font-size: .85rem; }
.btn-lg { padding: 12px 20px; font-size: 1.05rem; }
.btn-block { width: 100%; justify-content: center; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-icon { background: none; border: 0; font-size: 20px; cursor: pointer; padding: 4px 8px; }
.inline-form { display: inline; }

/* ---------- Badges / alerts ---------- */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .76rem; font-weight: 600; background: #eef0f3; color: var(--text-2); }
.badge-good { background: var(--good-bg); color: var(--good); }
.badge-warning { background: var(--warn-bg); color: var(--warn); }
.badge-critical { background: var(--bad-bg); color: var(--bad); }
.badge-info { background: var(--info-bg); color: var(--info); }
.alert { padding: 10px 14px; border-radius: 6px; margin-bottom: 12px; border: 1px solid transparent; }
.alert-success { background: var(--good-bg); color: #14532d; border-color: #bfe5cb; }
.alert-danger, .alert-error { background: var(--bad-bg); color: #7a1a12; border-color: #f4c3bd; }
.alert-warning { background: var(--warn-bg); color: #713f12; border-color: #f1dcae; }
.alert-info { background: var(--info-bg); color: #163e75; border-color: #c4d7f3; }

/* ---------- Tabs / pager ---------- */
.tabs { display: flex; gap: 4px; flex-wrap: wrap; border-bottom: 1px solid var(--border); margin-bottom: 14px; }
.tabs a { padding: 8px 12px; color: var(--text-2); border-bottom: 2px solid transparent; }
.tabs a.active { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }
.tabs a:hover { text-decoration: none; color: var(--text); }
.pager { display: flex; gap: 12px; align-items: center; justify-content: flex-end; margin-top: 12px; color: var(--muted); }

/* ---------- Auth ---------- */
.auth-page { display: grid; place-items: center; min-height: 100vh; background: linear-gradient(135deg, #0e2a2a, #0f766e); padding: 20px; }
.auth-card { background: #fff; width: 100%; max-width: 400px; padding: 32px; border-radius: 12px; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.auth-card.wide { max-width: 720px; }
.auth-card h1 { font-size: 1.4rem; margin-bottom: 4px; color: var(--brand-dark); }
.auth-card form > label { margin-bottom: 14px; }
.checks { list-style: none; padding: 0; columns: 2; }
.checks .ok { color: var(--good); } .checks .bad { color: var(--bad); font-weight: 600; }

/* ---------- Charts ---------- */
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid-line { stroke: #eceef1; stroke-width: 1; }
.chart .axis-label { fill: var(--muted); font-size: 11px; }
.chart .bar { fill: var(--series-1); }
.chart .bar.dim { opacity: .45; }
.chart .hit { fill: transparent; cursor: default; }
.chart-tip {
  position: absolute; pointer-events: none; background: #16191d; color: #fff; padding: 6px 9px; border-radius: 6px;
  font-size: 12px; white-space: nowrap; transform: translate(-50%, -110%); opacity: 0; transition: opacity .1s; z-index: 5;
}
.chart-tip.show { opacity: 1; }
.chart-tip b { font-variant-numeric: tabular-nums; }
.chart-empty { color: var(--muted); padding: 40px 0; text-align: center; }

/* ---------- POS ---------- */
.pos { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 16px; align-items: start; }
.pos-search { position: relative; }
.pos-search input { font-size: 1.05rem; padding: 11px 12px; }
.search-results {
  position: absolute; left: 0; right: 0; top: 100%; background: #fff; border: 1px solid var(--border); border-radius: 0 0 8px 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,.12); max-height: 380px; overflow-y: auto; z-index: 15;
}
.search-results .res { padding: 8px 12px; cursor: pointer; border-bottom: 1px solid #f0f1f3; display: flex; justify-content: space-between; gap: 10px; }
.search-results .res.sel, .search-results .res:hover { background: var(--brand-soft); }
.search-results .res .meta { color: var(--muted); font-size: .82rem; }
.search-results .res.out { opacity: .55; }
.cart td input { padding: 5px 6px; }
.cart td input.qty { width: 70px; }
.cart td input.disc { width: 64px; }
.cart td select { padding: 5px 4px; min-width: 0; width: 128px; }
.cart th, .cart td { padding: 6px 5px; }
.cart td input.qty, .cart td input.disc { width: 58px; }
.pos-side .totals { width: 100%; }
.pos-side .totals td { padding: 5px 0; }
.pos-side .totals tr.grand td { font-size: 1.5rem; font-weight: 700; border-top: 2px solid var(--border); padding-top: 8px; }
.paymodes { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 8px 0 12px; }
.paymodes label { margin: 0; }
.paymodes input { position: absolute; opacity: 0; pointer-events: none; }
.paymodes span { display: block; text-align: center; padding: 8px 4px; border: 1px solid #cfd4db; border-radius: 6px; cursor: pointer; font-weight: 600; color: var(--text-2); }
.paymodes input:checked + span { background: var(--brand); border-color: var(--brand); color: #fff; }
.paymodes input:focus-visible + span { outline: 2px solid var(--brand); outline-offset: 2px; }
.kbd { font-size: .75rem; color: var(--muted); }
.sched { font-size: .7rem; padding: 1px 5px; border-radius: 4px; background: var(--bad-bg); color: var(--bad); font-weight: 700; margin-left: 4px; }

/* ---------- Invoice ---------- */
.invoice { background: #fff; max-width: 820px; margin: 0 auto; padding: 24px; border: 1px solid var(--border); color: #000; }
.invoice.a5 { max-width: 600px; font-size: 12px; }
.invoice.thermal { max-width: 300px; font-size: 11px; padding: 8px; font-family: "Courier New", monospace; }
.invoice .inv-head { display: flex; justify-content: space-between; gap: 16px; border-bottom: 2px solid #000; padding-bottom: 8px; margin-bottom: 8px; }
.invoice.thermal .inv-head { display: block; text-align: center; }
.invoice h2 { margin: 0; font-size: 1.4em; }
.invoice table { width: 100%; border-collapse: collapse; }
.invoice th, .invoice td { padding: 3px 4px; border-bottom: 1px solid #ccc; text-align: left; }
.invoice th { border-bottom: 1px solid #000; }
.invoice .num { text-align: right; }
.invoice .tot td { border: 0; padding: 2px 4px; }
.invoice .grand td { font-size: 1.25em; font-weight: 700; border-top: 1px solid #000; }
.invoice .foot-note { margin-top: 12px; font-size: .9em; border-top: 1px dashed #999; padding-top: 6px; }
.print-bar { max-width: 820px; margin: 0 auto 12px; display: flex; gap: 8px; flex-wrap: wrap; }

@media print {
  body { background: #fff; }
  .sidebar, .topbar, .foot, .no-print, .print-bar, .filters, .form-actions, .pager { display: none !important; }
  .main { margin: 0; }
  .content { padding: 0; }
  .card { box-shadow: none; border: 0; padding: 0; }
  .invoice { border: 0; padding: 0; max-width: none; }
  .invoice.thermal { width: 72mm; }
  a { color: #000; }
}

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .pos { grid-template-columns: 1fr; }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  .sidebar { transform: translateX(-100%); }
  body.sidebar-open .sidebar { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.4); }
  .main { margin-left: 0; }
  .menu-toggle { display: block; }
  .today { display: none; }
  .grid-2, .grid-3, .grid-4, .form-grid, .form-grid.cols-3, .form-grid.cols-4 { grid-template-columns: 1fr; }
  .form-grid .span2 { grid-column: auto; }
  .content { padding: 12px; }
}
.report-layout { grid-template-columns: 240px minmax(0, 1fr); }
@media (max-width: 860px) { .report-layout { grid-template-columns: 1fr; } }
