/* Colours from the existing PH Lawless system (v13 mobile + desktop):
   dark brown header, warm cream background, bronze accent. */
:root {
  --bg: #F7F2EB; --surface: #FFFFFF; --soft: #FFF7EC;
  --ink: #241F1A; --ink-2: #3A3027; --muted: #6E6254;
  --line: #DCCDBC; --line-2: #CDBBA5; --row-line: #F1E7DB;
  --header: #241F1A; --header-ink: #FFFFFF; --header-muted: #EADCC8;
  --accent: #8A642D; --accent-ink: #FFFFFF; --accent-dark: #6F4F22; --accent-soft: #F3E6D2;
  --ok: #15803D; --ok-bg: #E9F5EC; --ok-line: #A7D7B5;
  --warn: #9A4A0B; --warn-bg: #FDF0E0; --warn-line: #E8B98A;
  --danger: #B91C1C;
  --radius: 14px;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Noto Sans Arabic", Arial, sans-serif;
  color: var(--ink); background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--bg); }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
h1 { margin: 0; font-size: 28px; font-weight: 700; letter-spacing: -0.02em; }
h2 { margin: 12px 0 0; font-size: 18px; }
.eyebrow { font-size: 13px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
:focus-visible { outline: 3px solid #D9B77E; outline-offset: 2px; }
[hidden] { display: none !important; }

/* sign-in */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: var(--bg); }
.auth-card { width: min(420px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 28px; display: flex; flex-direction: column; gap: 14px; box-shadow: 0 1px 3px rgba(0,0,0,.05); }
.auth-card h1 { font-size: 24px; }
.auth-card p { margin: 0; }
.auth-brand { display: flex; align-items: center; gap: 12px; font-size: 18px; font-weight: 700; }
.auth-brand img { width: 44px; height: 44px; object-fit: contain; border-radius: 10px; background: #fff; border: 1px solid var(--line); padding: 3px; }

/* fields & buttons */
.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 600; }
.field-label { font-size: 14px; font-weight: 600; margin-bottom: 6px; }
input, select { height: 48px; padding: 0 14px; border: 1px solid var(--line-2); border-radius: 10px; font-size: 16px; background: #fff; }
input:disabled { background: var(--soft); color: var(--muted); }
.form-error { color: var(--danger); font-weight: 600; font-size: 14px; }
.form-error:empty { display: none; }
.btn { height: 44px; padding: 0 16px; border-radius: 10px; font-size: 15px; font-weight: 700;
  border: 1px solid var(--line-2); background: var(--surface); color: var(--ink); white-space: nowrap; }
.btn:hover { background: var(--soft); }
.btn.primary { border: 0; background: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: var(--accent-dark); }
.btn.big { height: 56px; font-size: 18px; border-radius: 12px; }
.btn.ghost { border: 0; background: transparent; color: var(--ink-2); }
.btn.on-dark { background: transparent; color: var(--header-ink); border-color: rgba(255,255,255,.35); }
.btn.on-dark:hover { background: rgba(255,255,255,.1); }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .6; cursor: wait; }
.link { border: 0; background: none; padding: 0; color: var(--accent); font-size: 16px; font-weight: 600; text-align: start; }
.link:hover { color: var(--accent-dark); text-decoration: underline; }
.link.disabled { color: var(--muted); font-weight: 500; font-size: 15px; }
.small-link { font-size: 14px; margin-top: 8px; }
.pills { display: flex; flex-wrap: wrap; gap: 8px; }
.pill { min-height: 40px; padding: 0 16px; border-radius: 999px; font-size: 15px; font-weight: 600;
  border: 1px solid var(--line-2); background: var(--surface); }
.pill.on { border-color: var(--accent); background: var(--accent); color: var(--accent-ink); }
.pill .count { margin-inline-start: 6px; opacity: .75; }

/* header */
.top { min-height: 72px; padding: 10px 28px; display: flex; align-items: center; gap: 24px;
  background: var(--header); color: var(--header-ink); position: sticky; top: 0; z-index: 5; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand img { width: 46px; height: 46px; object-fit: contain; border-radius: 10px; background: #fff; padding: 3px; }
.brand-name { font-size: 18px; font-weight: 700; }
.who-line { font-size: 13px; color: var(--header-muted); }
.tabs { display: flex; gap: 4px; flex-grow: 1; }
.tab { height: 42px; padding: 0 16px; border: 0; border-radius: 10px; background: transparent; color: var(--header-muted);
  font-size: 16px; font-weight: 700; }
.tab:hover { background: rgba(255,255,255,.08); color: #fff; }
.tab.on { background: var(--accent); color: #fff; }
.top-right { display: flex; align-items: center; gap: 12px; }

/* connection status: always visible */
.status { display: flex; align-items: center; gap: 8px; height: 40px; padding: 0 16px; border-radius: 999px;
  font-size: 14px; font-weight: 700; white-space: nowrap; border: 1px solid; }
.status .dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.status.ok { background: var(--ok-bg); border-color: var(--ok-line); color: #14532D; }
.status.ok .dot { background: var(--ok); }
.status.busy { background: #FFF8E6; border-color: #EBD08E; color: #5C4306; }
.status.busy .dot { background: #C99A06; animation: pulse 1s infinite alternate; }
.status.warn { background: var(--warn-bg); border-color: var(--warn-line); color: #6B2F05; }
.status.warn .dot { background: var(--warn); }
@keyframes pulse { to { opacity: .35; } }

/* toolbar: assistant + search */
.toolbar { display: flex; gap: 16px; padding: 16px 28px 0; }
.ask { flex: 3 1 420px; display: flex; align-items: center; gap: 10px; height: 52px; padding: 0 6px 0 16px;
  background: var(--surface); border: 2px solid var(--accent); border-radius: 12px; color: var(--accent); }
.ask input { flex-grow: 1; border: 0; height: 44px; padding: 0; font-size: 16px; outline: none; background: transparent; color: var(--ink); min-width: 0; }
.ask .btn { height: 40px; }
.search { position: relative; flex: 2 1 280px; display: flex; align-items: center; gap: 10px; height: 52px; padding: 0 16px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; color: var(--muted); }
.search input { flex-grow: 1; border: 0; height: 44px; padding: 0; background: transparent; font-size: 15px; color: var(--ink); outline: none; min-width: 0; }
.search-results { position: absolute; inset-inline: 0; top: 56px; background: var(--surface); border-radius: 12px;
  box-shadow: 0 8px 30px rgba(0,0,0,.15); overflow: hidden; z-index: 6; }
.search-results:empty { display: none; }
.ask-help { padding: 0 28px; }
.ask-suggest { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 0 28px 8px; }
.ask-suggest:empty { display: none; }
.ask-help:empty { display: none; }
.ask-answer { margin-top: 10px; padding: 12px 16px; background: var(--accent-soft); border-radius: 12px; display: flex;
  flex-wrap: wrap; align-items: center; gap: 10px; font-weight: 600; }
.ask-answer > .link:last-child { margin-inline-start: auto; font-size: 20px; }
.ask-answer.column { flex-direction: column; flex-wrap: nowrap; align-items: stretch; }
.ask-q { display: flex; justify-content: space-between; gap: 12px; }
.ask-q .link { font-size: 20px; }
.patient-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); grid-auto-rows: min-content; gap: 10px; align-items: start; }
.patient-card { display: flex; flex-direction: column; gap: 3px; padding: 12px 14px; text-align: start; font-weight: 500;
  background: var(--surface); border: 1px solid var(--line-2); border-radius: 12px; }
.patient-card:hover { border-color: var(--accent); background: var(--soft); }
.patient-card strong { font-size: 16px; }
.patient-card .next { color: var(--accent-dark); font-weight: 700; }
.patient-card.new { border-style: dashed; color: var(--accent); }
.match { display: flex; gap: 12px; align-items: center; width: 100%; min-height: 48px; padding: 8px 16px; border: 0;
  border-bottom: 1px solid var(--row-line); background: var(--surface); text-align: start; font-size: 15px; }
.match:hover { background: var(--soft); }
.match .hint { margin-inline-start: auto; color: var(--accent); font-weight: 700; }
.match.new { color: var(--accent); font-weight: 700; }
.matches { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.matches:empty { display: none; }

/* main layout */
.body { display: flex; gap: 24px; padding: 20px 28px 32px; align-items: flex-start; }
.main { flex-grow: 1; display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.title-row { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.filters input[type="search"] { width: min(360px, 100%); }
.list { display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.row { display: flex; align-items: center; gap: 16px; min-height: 68px; padding: 10px 20px; border-bottom: 1px solid var(--row-line); }
.row.slim { min-height: 52px; }
.row:last-child { border-bottom: 0; }
.row.pending { background: #FFFBF3; }
.pending-note { color: var(--warn); font-weight: 600; margin-top: 2px; }
.time { width: 76px; flex-shrink: 0; font-size: 16px; font-weight: 600; color: var(--ink-2); }
.who-col { flex: 1 1 180px; display: flex; flex-direction: column; min-width: 140px; }
.name { font-size: 16px; font-weight: 600; }
.qty { font-size: 16px; font-weight: 700; white-space: nowrap; }
.qty.minus { color: var(--danger); }
.flag { margin-top: 4px; font-size: 13px; font-weight: 700; color: var(--danger); }
.chip { flex-shrink: 0; padding: 6px 12px; border-radius: 999px; font-size: 13px; font-weight: 700; white-space: nowrap; }
.chip.booked { background: #EFE7DB; color: #3A3027; }
.chip.arrived { background: #E6EFD9; color: #33501A; }
.chip.pay { background: #FBE3CF; color: #8A3A0C; }
.chip.done { background: #EEEBE6; color: #4F4A43; }
.act { width: 150px; flex-shrink: 0; display: flex; justify-content: flex-end; gap: 8px; }
.act.two { width: auto; }
.empty { padding: 32px; text-align: center; color: var(--muted); font-size: 15px; }

.side { width: 360px; flex-shrink: 0; position: sticky; top: 96px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.big-action { height: 76px; border: 1px solid var(--line-2); border-radius: var(--radius); background: var(--surface);
  font-size: 19px; font-weight: 700; display: flex; align-items: center; gap: 14px; padding: 0 22px; text-align: start; color: var(--ink); }
.big-action:hover { background: var(--soft); }
.big-action.primary { border: 0; background: var(--accent); color: var(--accent-ink); }
.big-action.primary:hover { background: var(--accent-dark); }
.big-action .aside { margin-inline-start: auto; font-size: 15px; font-weight: 600; color: var(--muted); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 1px 3px rgba(0,0,0,.04); }
.card.more { margin-top: 12px; padding: 18px 20px; display: flex; flex-direction: column; gap: 12px; }
.card.panel { padding: 22px; display: flex; flex-direction: column; gap: 16px; }
.card.panel input:not([type=checkbox]), .card.panel select, .card.panel textarea { width: 100%; }
.card.panel .mat input { width: 80px; }
.low-line { display: flex; justify-content: space-between; gap: 12px; font-size: 15px; }
.who-big { font-size: 22px; font-weight: 700; }
.patient-chip { display: flex; justify-content: space-between; gap: 12px; padding: 12px 14px; border-radius: 10px;
  background: var(--accent-soft); font-weight: 600; }
.new-patient { display: flex; flex-direction: column; gap: 12px; }
.lines { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.lines li { display: flex; justify-content: space-between; gap: 12px; font-size: 15px; }
.materials { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.mat { display: flex; align-items: center; gap: 10px; }
.mat span { flex-grow: 1; font-size: 15px; }
.mat input { width: 80px; height: 40px; }

/* patient file, doctor session, follow-up */
.alert-line { padding: 10px 12px; border-radius: 10px; background: #FDE8E8; color: #8E1B1B; font-weight: 700; }
.note-line { padding: 10px 12px; border-radius: 10px; background: var(--soft); border: 1px solid var(--line); }
.total-line { display: flex; justify-content: space-between; margin-top: 10px; font-size: 16px; }
textarea { width: 100%; padding: 10px 14px; border: 1px solid var(--line-2); border-radius: 10px; font: inherit; font-size: 16px; resize: vertical; }
.btn.danger { border: 0; background: var(--danger); color: #fff; }
.btn.danger:hover { background: #8E1B1B; }
a.btn { display: inline-flex; align-items: center; text-decoration: none; }
.act.wide-act { width: auto; flex-wrap: wrap; }
.big-action:disabled { opacity: .55; cursor: default; }
.read-back { font-weight: 500; color: var(--muted); }
.close-x { margin-inline-start: auto; font-size: 20px; }
.empty.card { padding: 20px; }
.row.dim { opacity: .6; }
.help-group { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; }
.small-pill { min-height: 34px; font-size: 14px; padding: 0 12px; }
.ask-what { font-size: 13px; white-space: nowrap; }
@media (max-width: 640px) { .ask-what { display: none; } }
.answer-list.plain { list-style: none; padding: 0; }
.answer-list.plain li { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 4px 0; border-bottom: 1px solid var(--line); }
.answer-list { margin: 4px 0; padding-inline-start: 20px; display: flex; flex-direction: column; gap: 4px; font-weight: 600; }
.day-head { margin-top: 18px; font-size: 17px; }
.pill.taken { border-color: var(--danger); color: var(--danger); }
.pill.taken.on { background: var(--danger); color: #fff; }
.slot-warn { flex-basis: 100%; margin-top: 6px; }
.chip.cancelled { background: #F3E3E3; color: #7F1D1D; }
.filters input[type=date] { width: auto; }

/* type-it switch */
.field-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 6px; }
.field-head .field-label { margin: 0; }
.switch-row { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 600; cursor: pointer; }
.switch { width: 44px; height: 26px; border-radius: 999px; border: 0; background: var(--line-2); position: relative; padding: 0; flex-shrink: 0; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: transform .15s; }
.switch.on { background: var(--accent); }
.switch.on::after { transform: translateX(18px); }

/* settings */
.settings { padding: 20px 28px 40px; display: flex; flex-direction: column; gap: 16px; max-width: 980px; }
.card.section { padding: 20px 22px; display: flex; flex-direction: column; gap: 12px; }
.card.section h2 { margin: 0; }
.card.section > .btn { align-self: flex-start; min-width: 140px; }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 48px;
  border-bottom: 1px solid var(--row-line); flex-wrap: wrap; }
.set-row:last-of-type { border-bottom: 0; }
.svc-group { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }
.price-edit { display: flex; align-items: center; gap: 10px; }
.price-edit input { width: 120px; height: 40px; }
.add-line, .add-user { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 4px; }
.add-line input { flex: 1 1 220px; }
.add-user input, .add-user select { flex: 1 1 180px; }

.toast-slot { position: fixed; inset-inline: 16px; bottom: 16px; display: flex; justify-content: center; z-index: 10; pointer-events: none; }
.toast { pointer-events: auto; max-width: 600px; padding: 14px 18px; background: var(--header); color: #fff; border-radius: 12px;
  font-size: 15px; font-weight: 600; display: flex; align-items: center; gap: 16px; box-shadow: 0 8px 30px rgba(0,0,0,.25); }
.toast .link { color: #F2D6A8; }
.toast.warn { background: #7A3A0F; }
.toast.error { background: #8E1B1B; }

/* small laptops */
@media (max-width: 1100px) {
  .top { flex-wrap: wrap; padding: 10px 20px; gap: 12px; }
  .tabs { order: 3; flex-basis: 100%; }
  .toolbar { flex-wrap: wrap; padding: 12px 20px 0; }
  .ask-help { padding: 0 20px; }
  .ask-suggest { padding: 0 20px 8px; }
  .body { flex-direction: column-reverse; align-items: stretch; padding: 16px 20px; gap: 16px; }
  .side { width: 100%; position: static; }
  .stack { display: grid; grid-template-columns: repeat(3, 1fr); }
  .stack .card.more { grid-column: 1 / -1; margin-top: 0; }
  .card.panel { max-width: 640px; }
  .settings { padding: 16px 20px 32px; }
}

/* phones (browser) */
@media (max-width: 640px) {
  .top { padding: 10px 12px; }
  .top-right { flex-basis: 100%; justify-content: space-between; flex-wrap: wrap; gap: 8px; }
  .top-right .btn { padding: 0 10px; min-height: 38px; font-size: 14px; }
  .top-right .status { font-size: 13px; }
  .tabs { overflow-x: auto; }
  .toolbar { padding: 10px 12px 0; gap: 10px; }
  .body { padding: 12px; }
  .stack { grid-template-columns: 1fr; gap: 8px; }
  .big-action { height: 56px; font-size: 17px; }
  .stack .card.more, .title-row .muted { display: none; }
  .row { flex-wrap: wrap; padding: 12px 16px; gap: 8px 12px; }
  .time { width: auto; }
  .act { width: 100%; justify-content: stretch; }
  .act .btn { flex: 1; height: 48px; }
  h1 { font-size: 22px; }
}

.wa-preview { white-space: pre-wrap; background: #e7f6e3; border-radius: 10px; padding: 10px 12px; font-size: 14px; direction: auto; unicode-bidi: plaintext; }
.bc-text { width: 100%; font: inherit; padding: 10px; border-radius: 10px; border: 1px solid var(--line); unicode-bidi: plaintext; }
a.big-action { text-decoration: none; }

.rep-head { display: flex; align-items: center; gap: 14px; }
.rep-head img { width: 48px; height: 48px; }
.rep-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin: 12px 0; }
.kpi { background: var(--card, #fff); border: 1px solid var(--line); border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 4px; }
.kpi strong { font-size: 20px; }
.kpi.neg strong { color: #a3352b; }
.rep-block { margin-top: 14px; }
.rep-table { width: 100%; border-collapse: collapse; }
.rep-table td { padding: 6px 4px; border-bottom: 1px solid var(--line); }
.rep-table td.num { text-align: end; white-space: nowrap; }
.rep-table tr.tot td { font-weight: 700; border-top: 2px solid var(--line); }
@media print {
  header.top, .toolbar, .ask-help, .ask-suggest, .side, .no-print, .toast-slot { display: none !important; }
  body { background: #fff; }
  .body { display: block; }
  .rep-block { break-inside: avoid; }
}

.https-banner { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 8px 28px; padding: 10px 14px; border-radius: 12px; background: #fff4d6; border: 1px solid #e8c66a; }
@media (max-width: 640px) { .https-banner { margin: 8px 16px; flex-direction: column; align-items: stretch; } }

.rule-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; align-items: end; padding: 8px 0; border-bottom: 1px solid var(--line); }

.rep-table th { text-align: start; font-size: 13px; color: var(--muted, #6b6258); padding: 6px 4px; border-bottom: 2px solid var(--line); }
.rep-table th.num { text-align: end; }
.low-row td { color: #a3352b; font-weight: 600; }
.neg-text { color: #a3352b; }

.link.danger-link { color: #a3352b; margin-inline-start: 8px; }

.split-row { display: grid; grid-template-columns: 1fr 120px auto; gap: 8px; align-items: center; margin: 6px 0; }
.split-row select, .split-row input { min-height: 42px; }
