/* Sarthi Pharmacy — stylesheet.
   One :root token block, then sections. No framework, no build step. */

:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #eef1f7;
  --border: #d9dee8;
  --text: #1c2430;
  --muted: #6b7684;
  --primary: #0f7b6c;
  --primary-dark: #0b5d52;
  --green: #12855f;
  --amber: #b7791f;
  --red: #c0392b;
  --violet: #6b46c1;
  --blue: #2b6cb0;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(20, 30, 50, .08), 0 6px 20px rgba(20, 30, 50, .05);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

h1, h2, h3 { margin: 0 0 .5rem; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }

.muted { color: var(--muted); }
.small { font-size: .82rem; }
.mono { font-family: var(--mono); }
.error { color: var(--red); }
.right { text-align: right; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }

/* ---------------------------------------------------------------- login */

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background: linear-gradient(160deg, #0f7b6c 0%, #0b5d52 45%, #123c46 100%);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border-radius: 14px;
  padding: 2rem;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .25);
  display: flex;
  flex-direction: column;
  gap: .65rem;
}

.login-card h1 { font-size: 1.25rem; }
.login-card label { display: flex; flex-direction: column; gap: .25rem; font-size: .85rem; color: var(--muted); }

.brand-mark {
  width: 46px; height: 46px;
  border-radius: 12px;
  background: var(--primary);
  color: #fff;
  display: grid; place-items: center;
  font-weight: 700; font-size: 1.15rem;
  margin-bottom: .25rem;
}
.brand-mark.small { width: 34px; height: 34px; font-size: .95rem; border-radius: 9px; margin: 0; }

.demo-accounts { margin-top: .75rem; border-top: 1px solid var(--border); padding-top: .75rem; }
.chips { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .35rem; }

.chip {
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 999px;
  padding: .25rem .7rem;
  font-size: .8rem;
  cursor: pointer;
  color: var(--text);
}
.chip:hover { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ---------------------------------------------------------------- shell */

#app-view { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }

.sidebar {
  background: #12333a;
  color: #dce8e6;
  display: flex;
  flex-direction: column;
  padding: 1rem .75rem;
  gap: 1rem;
}

.sidebar .brand { display: flex; gap: .6rem; align-items: center; color: #fff; padding: 0 .25rem; }
.sidebar .brand small { color: #9fbdb8; }

.sidebar nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }

.sidebar nav a {
  display: flex; align-items: center; gap: .55rem;
  padding: .5rem .6rem;
  border-radius: 8px;
  color: #cfe0dd;
  text-decoration: none;
  font-size: .88rem;
  cursor: pointer;
}
.sidebar nav a:hover { background: rgba(255, 255, 255, .08); color: #fff; }
.sidebar nav a.active { background: var(--primary); color: #fff; font-weight: 600; }
.sidebar nav a .ico { width: 1.15rem; text-align: center; }

.sidebar-foot { border-top: 1px solid rgba(255, 255, 255, .12); padding-top: .75rem; display: flex; flex-direction: column; gap: .5rem; }
.sidebar-foot .who strong { display: block; color: #fff; font-size: .88rem; }
.sidebar-foot .who small { color: #9fbdb8; text-transform: capitalize; }

.content { display: flex; flex-direction: column; min-width: 0; }

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: .9rem 1.25rem;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  position: sticky; top: 0; z-index: 20;
}
.topbar h2 { margin: 0; }
.topbar-actions { display: flex; gap: .5rem; flex-wrap: wrap; }

.page { padding: 1.25rem; display: flex; flex-direction: column; gap: 1rem; min-width: 0; }

/* ---------------------------------------------------------------- cards */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem 1.1rem;
  min-width: 0;
}
.card > h3 { margin-bottom: .65rem; display: flex; align-items: center; justify-content: space-between; gap: .5rem; }

.grid { display: grid; gap: 1rem; }
.grid.c2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid.c3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid.c4 { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }

.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .85rem 1rem; box-shadow: var(--shadow); }
.kpi .label { font-size: .76rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.kpi .value { font-size: 1.45rem; font-weight: 680; margin-top: .15rem; }
.kpi .sub { font-size: .78rem; color: var(--muted); }
.kpi.tone-green .value { color: var(--green); }
.kpi.tone-amber .value { color: var(--amber); }
.kpi.tone-red .value { color: var(--red); }
.kpi.tone-blue .value { color: var(--blue); }

/* ---------------------------------------------------------------- forms */

input, select, textarea {
  font: inherit;
  padding: .45rem .55rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  width: 100%;
  min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(15, 123, 108, .25); border-color: var(--primary); }
textarea { min-height: 64px; resize: vertical; }

label.field { display: flex; flex-direction: column; gap: .22rem; font-size: .8rem; color: var(--muted); }
.form-grid { display: grid; gap: .65rem; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.form-grid .span2 { grid-column: span 2; }

button {
  font: inherit;
  padding: .45rem .85rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
}
button:hover { border-color: var(--primary); }
button.primary { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
button.primary:hover { background: var(--primary-dark); }
button.ghost { background: transparent; }
button.danger { background: var(--red); border-color: var(--red); color: #fff; }
button.small-btn { padding: .3rem .6rem; font-size: .8rem; }
button:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn { border: none; background: none; font-size: 1.2rem; line-height: 1; cursor: pointer; color: var(--muted); padding: .2rem .4rem; }
.icon-btn:hover { color: var(--text); }

/* ---------------------------------------------------------------- tables */

table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th, td { padding: .5rem .55rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: .74rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: var(--surface-2); position: sticky; top: 0; }
tbody tr:hover { background: #f8fafc; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow: auto; max-height: 68vh; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }

.empty { padding: 1.5rem; text-align: center; color: var(--muted); }

.badge {
  display: inline-block;
  padding: .12rem .5rem;
  border-radius: 999px;
  font-size: .74rem;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid var(--border);
}
.badge.green { background: #e6f6ef; color: var(--green); border-color: #b7e2ce; }
.badge.amber { background: #fdf3e2; color: var(--amber); border-color: #f0d9a8; }
.badge.red { background: #fdecea; color: var(--red); border-color: #f3c2bc; }
.badge.blue { background: #e8f1fb; color: var(--blue); border-color: #bcd7f2; }
.badge.violet { background: #f0eafc; color: var(--violet); border-color: #d6c8f5; }

/* ---------------------------------------------------------------- POS */

.pos { display: grid; grid-template-columns: 1fr 390px; gap: 1rem; align-items: start; }
@media (max-width: 1080px) { .pos { grid-template-columns: 1fr; } }

.search-results { display: flex; flex-direction: column; gap: .3rem; margin-top: .6rem; max-height: 46vh; overflow: auto; }

.result {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: .5rem;
  padding: .5rem .6rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  background: var(--surface);
}
.result:hover { border-color: var(--primary); background: #f2fbf9; }
.result .name { font-weight: 600; }
.result .meta { font-size: .76rem; color: var(--muted); }

.cart { display: flex; flex-direction: column; gap: .4rem; }
.cart-line { display: grid; grid-template-columns: 1fr auto; gap: .4rem; padding: .45rem .55rem; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
.cart-line .lname { font-weight: 600; font-size: .88rem; }
.cart-line .lmeta { font-size: .74rem; color: var(--muted); }
.cart-line .lctl { display: flex; align-items: center; gap: .3rem; }
.cart-line input { width: 62px; text-align: center; }

.totals { display: flex; flex-direction: column; gap: .22rem; margin-top: .6rem; border-top: 1px solid var(--border); padding-top: .6rem; font-size: .9rem; }
.totals .row { display: flex; justify-content: space-between; }
.totals .row.grand { font-size: 1.15rem; font-weight: 700; border-top: 1px solid var(--border); margin-top: .3rem; padding-top: .4rem; }

/* ---------------------------------------------------------------- charts & bars */

.spark { display: flex; align-items: flex-end; gap: 3px; height: 64px; margin-top: .5rem; }
.spark .bar { flex: 1; background: var(--primary); border-radius: 3px 3px 0 0; min-height: 2px; opacity: .85; }
.spark .bar:hover { opacity: 1; }

.bar-row { display: grid; grid-template-columns: 130px 1fr 90px; gap: .5rem; align-items: center; font-size: .84rem; margin-bottom: .3rem; }
.bar-track { background: var(--surface-2); border-radius: 4px; height: 16px; overflow: hidden; }
.bar-fill { background: var(--primary); height: 100%; border-radius: 4px; }

/* ---------------------------------------------------------------- modal & toast */

.modal { position: fixed; inset: 0; background: rgba(15, 25, 35, .5); display: grid; place-items: center; z-index: 100; padding: 1rem; }
.modal-card { background: var(--surface); border-radius: 12px; width: min(760px, 100%); max-height: 92vh; display: flex; flex-direction: column; box-shadow: 0 24px 70px rgba(0, 0, 0, .3); }
.modal-card > header { display: flex; align-items: center; justify-content: space-between; padding: .85rem 1.1rem; border-bottom: 1px solid var(--border); }
.modal-card > header h3 { margin: 0; }
.modal-body { padding: 1.1rem; overflow: auto; }
.modal-foot { padding: .8rem 1.1rem; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: .5rem; }

.toast {
  position: fixed; bottom: 1.25rem; left: 50%; transform: translateX(-50%);
  background: #1c2430; color: #fff; padding: .6rem 1.1rem; border-radius: 999px;
  box-shadow: var(--shadow); z-index: 200; font-size: .88rem; max-width: 90vw;
}
.toast.ok { background: var(--green); }
.toast.err { background: var(--red); }

/* ---------------------------------------------------------------- invoice */

.invoice { background: #fff; color: #111; padding: 1.25rem; font-size: .85rem; }
.invoice h2 { margin: 0; font-size: 1.05rem; }
.invoice table { font-size: .82rem; }
.invoice th, .invoice td { border-bottom: 1px solid #ddd; padding: .35rem .4rem; }
.invoice .tot { display: flex; justify-content: space-between; padding: .12rem 0; }
.invoice .tot.grand { font-weight: 700; border-top: 2px solid #111; margin-top: .3rem; padding-top: .3rem; font-size: 1rem; }
.invoice-head { display: flex; justify-content: space-between; gap: 1rem; border-bottom: 2px solid #111; padding-bottom: .6rem; margin-bottom: .6rem; }
.invoice-foot { margin-top: 1rem; border-top: 1px dashed #999; padding-top: .5rem; font-size: .75rem; color: #555; }

@media print {
  body * { visibility: hidden; }
  #modal, #modal * { visibility: visible; }
  #modal { position: absolute; inset: 0; background: #fff; }
  .modal-card { box-shadow: none; max-height: none; width: 100%; }
  .modal-card > header, .modal-foot { display: none; }
}
