/* PainWorx staff app. Tokens first; everything else reads from them.
   Brand: navy #20293f, deep navy #141d31, blue #0086cd (painworx.co.za). */
:root {
  --primary: #0086cd; --primary-dark: #0073aa; --primary-soft: #e3f1fa;
  --navy: #20293f; --navy-deep: #141d31;
  --bg: #f3f6fb; --panel: #ffffff; --border: #dbe3ee; --text: #20293f; --muted: #5f6b85;
  --ok: #16a34a; --ok-soft: #dcfce7; --danger: #dc2626; --danger-soft: #fee2e2; --warn: #b45309; --warn-soft: #fef3c7;
  --radius: 8px; --shadow: 0 1px 2px rgba(32,41,63,.05), 0 4px 16px rgba(32,41,63,.06);
  --font: 'Open Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --display: 'Orbitron', 'Open Sans', sans-serif;
  --pad: 16px; --row: 9px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --primary: #2ea8e8; --primary-dark: #0086cd; --primary-soft: #0f2a3b;
  --bg: #0f1522; --panel: #182036; --border: #273152; --text: #e5ebf5; --muted: #9aa7c2;
  --ok-soft: #12301f; --danger-soft: #3b1515; --warn-soft: #3a2c0c;
  color-scheme: dark;
}
:root[data-density="compact"] { --pad: 10px; --row: 5px; }

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.5 var(--font); background: var(--bg); color: var(--text); }
a { color: var(--primary); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0 0 8px; font-weight: 700; text-wrap: balance; }
h1 { font-size: 20px; } h2 { font-size: 16px; }
h3 { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.muted { color: var(--muted); } .mt { margin-top: 14px; } .right { text-align: right; }
.tabular { font-variant-numeric: tabular-nums; }

/* Layout: navy header with the section menu, content below */
.shell { min-height: 100vh; display: flex; flex-direction: column; }
.topbar { background: var(--navy-deep); color: #fff; display: flex; align-items: center; gap: 14px; padding: 10px 20px; }
.brand { display: flex; align-items: center; gap: 10px; font-family: var(--display); font-weight: 800; font-size: 18px; letter-spacing: .02em; color: #fff; }
.brand img { height: 30px; width: auto; display: block; }
.logo { display: inline-flex; align-items: center; }
.logo img { height: 30px; width: auto; max-width: 170px; display: block; }
.logo .wordmark { display: none; font-family: var(--display); font-weight: 800; font-size: 18px; color: #fff; }
.logo .wordmark span { color: var(--primary); }
.logo.is-text img { display: none; } .logo.is-text .wordmark { display: inline; }
.topbar .btn.theme-btn, .card-head .btn.theme-btn { background: transparent; color: #fff; border-color: rgba(255,255,255,.3); }
.topbar .btn.theme-btn:hover, .card-head .btn.theme-btn:hover { background: rgba(255,255,255,.12); }
.brand span { color: var(--primary); }
.brand small { font-family: var(--font); font-weight: 400; font-size: 12px; color: rgba(255,255,255,.6); margin-left: 6px; padding-left: 10px; border-left: 1px solid rgba(255,255,255,.2); }
.topbar .spacer { flex: 1; }
.topbar .who { font-size: 13px; color: rgba(255,255,255,.75); }
.topbar .who b { color: #fff; }
.topbar .btn { background: transparent; color: #fff; border-color: rgba(255,255,255,.3); }
.topbar .btn:hover { background: rgba(255,255,255,.1); }
.sections { background: var(--navy); border-bottom: 3px solid var(--primary); display: flex; gap: 2px; padding: 0 12px; overflow-x: auto; }
.sections a { display: inline-flex; align-items: center; gap: 8px; padding: 12px 14px; margin-bottom: -3px; border-bottom: 3px solid transparent; color: rgba(255,255,255,.75); font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; white-space: nowrap; }
.sections a:hover { color: #fff; background: rgba(255,255,255,.06); }
.sections a.active { color: #fff; background: var(--primary); }
.sections .sep { flex: 1; }
.main { padding: 20px 24px 40px; max-width: 1280px; width: 100%; margin: 0 auto; min-width: 0; }
.pagehead { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.pagehead .actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.offline { background: var(--warn-soft); color: var(--warn); padding: 8px 20px; font-size: 13px; text-align: center; }

/* Panels */
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel .body { padding: var(--pad); }
.grid { display: grid; gap: 14px; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.grid.side { grid-template-columns: 280px minmax(0, 1fr); align-items: start; }
.stat { padding: var(--pad); }
.stat .n { font-size: 30px; font-weight: 700; color: var(--primary); font-variant-numeric: tabular-nums; }
.stat .l { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }

/* Side list (step 2 of the navigation) */
.side-head { padding: 14px; border-bottom: 1px solid var(--border); }
.side-head h3 { margin: 0; }
.side-head p { margin: 4px 0 0; font-size: 12px; color: var(--muted); }
.side-head .btn { margin-top: 10px; width: 100%; justify-content: center; }
.list { display: flex; flex-direction: column; gap: 2px; padding: 8px; max-height: 70vh; overflow: auto; }
.list-item { display: flex; align-items: center; gap: 10px; padding: var(--row) 10px; border-radius: 6px; cursor: pointer; color: var(--text); }
.list-item:hover { background: var(--bg); }
.list-item.active { background: var(--primary-soft); color: var(--primary-dark); font-weight: 600; box-shadow: inset 3px 0 0 var(--primary); }
.list-item.off { opacity: .55; }
.list-item .ic { width: 22px; text-align: center; color: var(--primary); }
.list-item .lbl { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item small { font-size: 11px; color: var(--muted); }

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 3px; border: 1px solid var(--border); background: var(--panel); cursor: pointer; font-weight: 600; white-space: nowrap; transition: background .15s, color .15s; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.success, .btn.saved { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn.icon { padding: 6px 9px; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn-group { display: inline-flex; gap: 6px; flex-wrap: wrap; }
.saved-badge { color: var(--ok); font-weight: 600; font-size: 13px; }
.saved-badge.saving { color: var(--muted); } .saved-badge.err { color: var(--danger); }

/* Forms */
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field label { font-size: 12px; font-weight: 600; color: var(--muted); }
.field label .req { color: var(--danger); }
.field input, .field select, .field textarea, .search { padding: 9px 11px; border: 1px solid var(--border); border-radius: 6px; background: var(--panel); width: 100%; }
.field textarea { min-height: 84px; resize: vertical; line-height: 1.45; }
.field input:focus, .field select:focus, .field textarea:focus, .search:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
.field input[readonly] { background: var(--bg); color: var(--muted); }
.field .hint { font-size: 12px; color: var(--muted); }
.field .err { color: var(--danger); font-size: 12px; }
.field.invalid input, .field.invalid select { border-color: var(--danger); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px 14px; }
.form-grid .span-2 { grid-column: span 2; } .form-grid .span-all { grid-column: 1 / -1; }
@media (max-width: 560px) { .form-grid .span-2 { grid-column: span 1; } }
.checks { display: flex; flex-wrap: wrap; gap: 6px 14px; padding: 4px 0; }
.checks label { display: inline-flex; align-items: center; gap: 6px; font-weight: 400; color: var(--text); font-size: 13px; }
.checks input { accent-color: var(--primary); width: 18px; height: 18px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; min-height: 38px; border: 1.5px solid var(--border); border-radius: 999px; background: var(--panel); cursor: pointer; font-size: 13px; }
.chip:hover { border-color: var(--primary); }
.chip.sel { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.block { margin-bottom: 18px; }
.block > h3 { padding-bottom: 6px; border-bottom: 1px solid var(--border); margin-bottom: 12px; }
.inline { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.search { min-width: 240px; width: auto; }
.alert { padding: 10px 12px; border-radius: 6px; font-size: 13px; margin: 10px 0; }
.alert.err { background: var(--danger-soft); color: var(--danger); }
.alert.ok { background: var(--ok-soft); color: var(--ok); }
.alert.warn { background: var(--warn-soft); color: var(--warn); }
.alert.info { background: var(--primary-soft); color: var(--text); }
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.switch input { width: 40px; height: 22px; appearance: none; background: var(--border); border-radius: 99px; position: relative; cursor: pointer; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: left .15s; }
.switch input:checked { background: var(--primary); } .switch input:checked::after { left: 21px; }

/* Tables */
.table-wrap { overflow: auto; border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: var(--row) 10px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; vertical-align: middle; }
th { background: var(--bg); font-weight: 600; color: var(--muted); position: sticky; top: 0; }
tbody tr:hover { background: var(--bg); }
tbody tr.clickable { cursor: pointer; }
td.actions { text-align: right; }
td.wrap { white-space: normal; }
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge.pending { background: var(--warn-soft); color: var(--warn); }
.badge.confirmed { background: var(--ok-soft); color: var(--ok); }
.badge.completed { background: var(--primary-soft); color: var(--primary-dark); }
.badge.cancelled { background: var(--bg); color: var(--muted); }
.badge.none { background: var(--bg); color: var(--muted); } .badge.draft { background: var(--warn-soft); color: var(--warn); } .badge.submitted { background: var(--ok-soft); color: var(--ok); }
.badge.role { background: var(--primary-soft); color: var(--primary-dark); }
.empty { padding: 36px; text-align: center; color: var(--muted); }

/* Day view */
.day-nav { display: flex; align-items: center; gap: 10px; }
.day-nav .d { font-weight: 700; min-width: 220px; text-align: center; }
.appt-row { display: grid; grid-template-columns: 64px minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--border); cursor: pointer; }
.appt-row:hover { background: var(--bg); }
.appt-row .t { font-weight: 700; color: var(--primary); font-variant-numeric: tabular-nums; }
.appt-row .n { font-weight: 600; }
.appt-row .s { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.appt-row .badges { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.appt-row.off { opacity: .55; }

/* Consultation screen */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 14px; overflow-x: auto; }
.tabs button { flex: 1; padding: 11px 10px; background: none; border: none; border-bottom: 3px solid transparent; color: var(--muted); font-weight: 600; cursor: pointer; white-space: nowrap; }
.tabs button.sel { color: var(--primary); border-bottom-color: var(--primary); }
.flags { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.flag { padding: 10px 12px; border-radius: 6px; font-weight: 600; font-size: 14px; }
.flag.danger { background: var(--danger-soft); color: var(--danger); } .flag.info { background: var(--primary-soft); color: var(--text); }
.ro h3 { margin-bottom: 8px; }
.ro .row { padding: 6px 0; border-top: 1px solid var(--border); }
.ro .row:first-of-type { border-top: 0; }
.ro .row dt { font-size: 12px; font-weight: 600; color: var(--muted); } .ro .row dd { margin: 2px 0 0; overflow-wrap: anywhere; white-space: pre-wrap; }
.scores { display: grid; grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); gap: 10px; }
.scores > div { font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 4px; }
.score { display: inline-flex; align-items: center; justify-content: center; min-width: 36px; padding: 4px 8px; border-radius: 6px; font-weight: 700; font-size: 15px; color: #fff; background: hsl(var(--sh, 140) 60% 36%); }
.score.wide { background: var(--primary); min-width: 54px; }
.kv { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.kv li { display: flex; justify-content: space-between; gap: 10px; padding: 4px 0; }
.sig { max-width: 100%; width: 260px; background: #fff; border: 1px solid var(--border); border-radius: 6px; }
.bd { display: flex; gap: 8px; justify-content: center; }
.bd svg { width: 48%; max-width: 200px; height: auto; }
.bd .bd-r { fill: #cfe7e4; stroke: #9fb8b4; stroke-width: 1; } .bd .bd-r.on { fill: #ef4444; fill-opacity: .55; stroke: #b91c1c; } .bd .bd-x line { stroke: #7f1d1d; stroke-width: 3; stroke-linecap: round; }
.savebar { position: sticky; top: 0; z-index: 3; display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 8px 12px; margin-bottom: 12px; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); }
.dn4 { padding: 10px 12px; border-radius: 6px; background: var(--primary-soft); font-size: 14px; }
.dn4 small { display: block; color: var(--muted); }
.trend svg { width: 100%; height: auto; display: block; }
.trend .g { stroke: var(--border); } .trend .ax { fill: var(--muted); font-size: 10px; }
.trend .ln { fill: none; stroke-width: 2.5; stroke-linejoin: round; } .trend .ln.avg, .trend .dot.avg { stroke: var(--primary); } .trend .dot.avg { fill: var(--primary); }
.trend .ln.worst { stroke: #dc2626; stroke-dasharray: 5 4; } .trend .dot.worst { fill: #dc2626; stroke: #dc2626; }
.trend .key { display: flex; gap: 16px; justify-content: center; font-size: 12px; color: var(--muted); }
.trend .key i { display: inline-block; width: 14px; height: 3px; margin-right: 6px; vertical-align: middle; background: var(--primary); } .trend .key i.w { background: #dc2626; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(160deg, var(--navy-deep), var(--navy) 60%, #0b3a55); padding: 20px; }
.login .card { width: 380px; max-width: 100%; background: var(--panel); border-radius: 10px; padding: 28px; box-shadow: 0 20px 60px rgba(0,0,0,.35); display: grid; gap: 14px; }
.login .card { padding-top: 0; overflow: hidden; }
.login .card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; background: var(--navy-deep); margin: 0 -28px 8px; padding: 18px 20px; }
.login .card-head .logo img { height: 36px; }
.login .card h1 { text-align: center; font-size: 17px; }
.login .links { display: flex; justify-content: space-between; font-size: 13px; }

/* Modal, toast, update bar */
.modal-bg { position: fixed; inset: 0; background: rgba(17,24,39,.55); display: grid; place-items: center; z-index: 50; padding: 20px; }
.modal { background: var(--panel); border-radius: 10px; width: min(640px, 100%); max-height: 90vh; overflow: auto; box-shadow: 0 25px 60px rgba(0,0,0,.35); }
.modal .head { padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal .body { padding: 18px; } .modal .foot { padding: 12px 18px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }
.toast { position: fixed; bottom: 22px; right: 22px; background: var(--navy); color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow); z-index: 60; font-weight: 600; max-width: calc(100vw - 44px); }
.toast.ok { background: var(--ok); } .toast.err { background: var(--danger); }
.update-bar { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); background: var(--navy); color: #fff; padding: 10px 16px; border-radius: 8px; z-index: 61; display: flex; gap: 12px; align-items: center; }
.update-bar[hidden], .toast[hidden] { display: none; }
.update-bar button { background: var(--primary); color: #fff; border: none; border-radius: 3px; padding: 6px 12px; cursor: pointer; font-weight: 600; }

@media (max-width: 860px) {
  .grid.side { grid-template-columns: 1fr; }
  .list { max-height: 40vh; }
  .main { padding: 14px; }
  .topbar .who { display: none; }
  .appt-row { grid-template-columns: 56px minmax(0, 1fr); } .appt-row .badges { grid-column: 2; flex-direction: row; justify-content: flex-start; }
}
