:root {
  --teal: #1F5F63; --teal-dark: #15454a; --teal-light: #e3f0f1; --teal-mid: #4f8f93;
  --ink: #1b2325; --muted: #5d6b6e; --line: #d9e2e3; --bg: #f4f7f7; --card: #ffffff;
  --amber: #b26a00; --amber-bg: #fff4e0; --red: #b5362d; --red-bg: #fdecea; --green: #1f7a3f; --green-bg: #e6f4ea;
  --radius: 12px; --shadow: 0 1px 2px rgba(20,40,42,.06), 0 4px 14px rgba(20,40,42,.06);
  --sans: -apple-system, "SF Pro Text", "Segoe UI", Inter, Roboto, "Noto Sans Arabic", system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root { --ink: #e8eeee; --muted: #9fb0b2; --line: #2b3a3c; --bg: #0f1718; --card: #182224; --teal-light: #173a3d; --amber-bg: #3a2a08; --red-bg: #3a1613; --green-bg: #11301b; }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--sans); font-size: 15px; line-height: 1.45; -webkit-font-smoothing: antialiased; }
a { color: var(--teal); }
button, input, select, textarea { font: inherit; color: inherit; }
h1 { font-size: 22px; margin: 0 0 4px; letter-spacing: -.01em; }
h2 { font-size: 16px; margin: 18px 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
h3 { font-size: 15px; margin: 0 0 6px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.ar { direction: rtl; font-family: var(--sans); }

/* layout */
.shell { display: flex; min-height: 100dvh; }
nav.side { width: 220px; background: var(--teal); color: #fff; padding: 18px 12px; position: sticky; top: 0; height: 100dvh; display: flex; flex-direction: column; gap: 4px; }
nav.side .brand { font-weight: 700; font-size: 20px; padding: 6px 10px 16px; letter-spacing: .02em; display: flex; align-items: center; gap: 10px; }
nav.side a { color: #e8f3f3; text-decoration: none; padding: 10px 12px; border-radius: 10px; display: flex; align-items: center; gap: 10px; font-weight: 500; }
nav.side a.active, nav.side a:hover { background: rgba(255,255,255,.14); color: #fff; }
nav.side .spacer { flex: 1; }
nav.side .user { font-size: 13px; opacity: .85; padding: 8px 12px; }
nav.side svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
main { flex: 1; padding: 24px 28px 90px; max-width: 1100px; width: 100%; }
nav.bottom { display: none; }
@media (max-width: 760px) {
  nav.side { display: none; }
  main { padding: 16px 14px 90px; }
  nav.bottom { display: flex; position: fixed; bottom: 0; left: 0; right: 0; background: var(--card); border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); z-index: 20; }
  nav.bottom a { flex: 1; text-align: center; text-decoration: none; color: var(--muted); font-size: 11px; padding: 4px 0; }
  nav.bottom a.active { color: var(--teal); font-weight: 600; }
  nav.bottom svg { width: 22px; height: 22px; display: block; margin: 0 auto 2px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
}
.topbar { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.topbar h1 { flex: 1; }

/* cards & lists */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px; box-shadow: var(--shadow); }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.list .item { padding: 10px 0; border-top: 1px solid var(--line); display: flex; gap: 10px; align-items: flex-start; cursor: pointer; }
.list .item:first-child { border-top: 0; }
.list .item .main { flex: 1; min-width: 0; }
.list .item .title { font-weight: 600; }
.list .item .sub { color: var(--muted); font-size: 13px; }
.empty { color: var(--muted); padding: 12px 0; font-size: 14px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; margin-bottom: 14px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.kpi .n { font-size: 26px; font-weight: 700; line-height: 1.1; color: var(--teal); }
.kpi .l { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.kpi.warn .n { color: var(--amber); }
.kpi.bad .n { color: var(--red); }

/* chips */
.chip { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--teal-light); color: var(--teal-dark); font-weight: 600; white-space: nowrap; }
.chip.amber { background: var(--amber-bg); color: var(--amber); }
.chip.red { background: var(--red-bg); color: var(--red); }
.chip.green { background: var(--green-bg); color: var(--green); }
.chip.grey { background: var(--line); color: var(--muted); }
.status-consult { background: var(--line); color: var(--muted); }
.status-listed { background: var(--amber-bg); color: var(--amber); }
.status-preop { background: var(--amber-bg); color: var(--amber); }
.status-scheduled { background: var(--teal-light); color: var(--teal-dark); }
.status-done { background: var(--green-bg); color: var(--green); }
.status-postop { background: var(--green-bg); color: var(--green); }
.status-closed { background: var(--line); color: var(--muted); }
.progress { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; margin-top: 6px; }
.progress > div { height: 100%; background: var(--teal-mid); }
.progress.full > div { background: var(--green); }

/* buttons & forms */
.btn { border: 1px solid var(--line); background: var(--card); padding: 8px 14px; border-radius: 10px; cursor: pointer; font-weight: 600; font-size: 14px; display: inline-flex; align-items: center; gap: 6px; }
.btn.primary { background: var(--teal); color: #fff; border-color: var(--teal); }
.btn.danger { color: var(--red); border-color: var(--red); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--teal); }
.btn:disabled { opacity: .5; cursor: default; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.field label { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
input[type=text], input[type=password], input[type=date], input[type=time], input[type=number], input[type=tel], input[type=email], input[type=search], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); min-height: 40px; }
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--teal-mid); outline-offset: 1px; border-color: var(--teal-mid); }
.form2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
@media (max-width: 560px) { .form2 { grid-template-columns: 1fr; } }
.check { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; border-top: 1px solid var(--line); cursor: pointer; }
.check:first-child { border-top: 0; }
.check input { width: 20px; height: 20px; margin-top: 2px; accent-color: var(--teal); flex-shrink: 0; }
.check .lbl { flex: 1; }

.check .who { font-size: 12px; color: var(--muted); display: block; margin-top: 2px; text-decoration: none; }
.check .lbl { display: flex; flex-direction: column; }
.check.done .lbl > .t { text-decoration: line-through; color: var(--muted); }

/* tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 12px; overflow-x: auto; }
.tabs button { background: none; border: 0; padding: 10px 12px; font-weight: 600; color: var(--muted); border-bottom: 2px solid transparent; cursor: pointer; white-space: nowrap; }
.tabs button.active { color: var(--teal); border-bottom-color: var(--teal); }

/* table */
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 8px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; font-weight: 600; white-space: nowrap; }
.tablewrap { overflow-x: auto; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--teal-light); }

/* pipeline board */
.board { display: grid; grid-template-columns: repeat(6, minmax(200px, 1fr)); gap: 10px; overflow-x: auto; align-items: start; }
.board .col { background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px; min-height: 120px; }
.board .col h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 4px 6px; display: flex; justify-content: space-between; }
.board .cardlet { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px; margin-bottom: 8px; cursor: pointer; }
.board .cardlet .t { font-weight: 600; }
.board .cardlet .s { font-size: 12.5px; color: var(--muted); }
@media (max-width: 760px) { .board { display: block; } .board .col { margin-bottom: 10px; } }

/* modal */
.modal-bg { position: fixed; inset: 0; background: rgba(10,20,22,.45); display: flex; align-items: flex-end; justify-content: center; z-index: 50; }
.modal { background: var(--card); width: 100%; max-width: 640px; max-height: 92dvh; overflow: auto; border-radius: 18px 18px 0 0; padding: 18px 18px calc(18px + env(safe-area-inset-bottom)); }
@media (min-width: 761px) { .modal-bg { align-items: center; } .modal { border-radius: 18px; } }
.modal h3 { font-size: 18px; margin-bottom: 12px; }
.modal .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; }

/* login */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 20px; }
.login .box { width: 100%; max-width: 360px; }
.login .brand { font-size: 32px; font-weight: 700; color: var(--teal); text-align: center; margin-bottom: 4px; }
.login .tag { text-align: center; color: var(--muted); margin-bottom: 22px; }

/* calendar */
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal .dh { font-size: 11px; color: var(--muted); text-align: center; text-transform: uppercase; }
.cal .d { aspect-ratio: 1; border: 1px solid var(--line); border-radius: 8px; padding: 4px; font-size: 12px; cursor: pointer; background: var(--card); position: relative; }
.cal .d.dim { opacity: .35; }
.cal .d.today { border-color: var(--teal); border-width: 2px; }
.cal .d.sel { background: var(--teal-light); }
.cal .d .n { position: absolute; bottom: 3px; right: 5px; font-size: 11px; font-weight: 700; color: var(--teal); }
.cal .d .dot { position: absolute; bottom: 4px; left: 5px; width: 6px; height: 6px; border-radius: 50%; background: var(--amber); }

/* misc */
#toast { position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 99; max-width: 90vw; }
#toast.show { opacity: 1; }
.fab { position: fixed; right: 18px; bottom: 76px; width: 54px; height: 54px; border-radius: 50%; background: var(--teal); color: #fff; border: 0; font-size: 30px; line-height: 54px; text-align: center; box-shadow: 0 6px 18px rgba(31,95,99,.4); cursor: pointer; z-index: 21; }
@media (min-width: 761px) { .fab { bottom: 28px; right: 28px; } }
.banner { background: var(--amber-bg); color: var(--amber); padding: 10px 14px; border-radius: 10px; margin-bottom: 12px; font-size: 14px; }
.banner.red { background: var(--red-bg); color: var(--red); }
.offline { background: var(--line); color: var(--muted); }
.note { padding: 8px 0; border-top: 1px solid var(--line); }
.note .meta { font-size: 12px; color: var(--muted); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; font-size: 14px; }
.kv .k { color: var(--muted); }
.phone { font-size: 17px; font-weight: 600; letter-spacing: .02em; }
pre.msg { white-space: pre-wrap; font-family: var(--sans); background: var(--bg); padding: 10px; border-radius: 10px; font-size: 14px; }
