/* DentWe Clinic
 *
 * Same shape as before -- rail, search, options, content -- but built as a
 * proper surface: one purple accent carried from the mobile app, a single
 * spacing rhythm, and depth from layered shadow rather than from borders.
 */

:root {
  color-scheme: light;

  --purple: #7367f0;
  --purple-600: #5e50ee;
  --purple-100: #ece9fe;
  --purple-glow: rgba(115, 103, 240, 0.28);

  --ink: #2f3349;
  --ink-soft: #4b5068;
  --muted: #8b90a5;
  --faint: #aeb3c4;

  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-2: #fbfbfe;
  --line: #e9ebf2;
  --line-soft: #f1f2f7;

  --green: #22c55e;
  --green-bg: #dcfce7;
  --amber: #f59e0b;
  --amber-bg: #fef3c7;
  --red: #ef4444;
  --red-bg: #fee2e2;
  --blue: #3b82f6;
  --blue-bg: #dbeafe;

  --rail-top: #322d55;
  --rail-bottom: #221f3d;

  --r-sm: 9px;
  --r-md: 13px;
  --r-lg: 18px;
  --r-pill: 999px;

  --sp: 8px;

  --shadow-1: 0 1px 2px rgba(37, 40, 66, 0.05), 0 1px 3px rgba(37, 40, 66, 0.04);
  --shadow-2: 0 2px 6px rgba(37, 40, 66, 0.06), 0 8px 24px rgba(37, 40, 66, 0.06);
  --shadow-3: 0 12px 40px rgba(37, 40, 66, 0.14);

  --rail-w: 150px;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --ink: #e6e8f0;
    --ink-soft: #c3c7d6;
    --muted: #9199ad;
    --faint: #6f7689;
    --bg: #15161d;
    --surface: #1d1f28;
    --surface-2: #22252f;
    --line: #2c3040;
    --line-soft: #262936;
    --purple-100: #2a2750;
    --green-bg: #14331f;
    --amber-bg: #3a2b0c;
    --red-bg: #3a1c1c;
    --blue-bg: #172a45;
    --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-2: 0 2px 6px rgba(0, 0, 0, 0.35), 0 8px 24px rgba(0, 0, 0, 0.3);
    --shadow-3: 0 12px 40px rgba(0, 0, 0, 0.55);
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font: 400 14px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        "Helvetica Neue", "Noto Kufi Arabic", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }

::selection { background: var(--purple-glow); }

/* Focus that is visible without being loud, and never on a mouse click. */
:focus-visible {
  outline: 2px solid var(--purple);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ==================================================================== login */

.login {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px;
  background:
    radial-gradient(900px 500px at 15% -5%, rgba(115, 103, 240, 0.18), transparent 60%),
    radial-gradient(700px 500px at 100% 100%, rgba(59, 130, 246, 0.12), transparent 55%),
    var(--bg);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  padding: 36px 32px 32px;
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-3);
  border: 1px solid var(--line);
  animation: rise 0.4s cubic-bezier(0.2, 0.8, 0.3, 1) both;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(12px); }
}

.login-mark {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  font-size: 24px;
  margin-bottom: 18px;
  background: linear-gradient(135deg, var(--purple), #9b8bff);
  box-shadow: 0 6px 18px var(--purple-glow);
}

.login-card h1 { margin: 0 0 4px; font-size: 21px; letter-spacing: -0.01em; }
.login-card > p { margin: 0; color: var(--muted); font-size: 13.5px; }
.login-card label { display: block; margin-top: 18px; font-weight: 600; font-size: 12.5px; color: var(--ink-soft); }
.login-card input { width: 100%; margin-top: 6px; }

/* ====================================================================== app */

.app { display: flex; min-height: 100vh; }

/* ----------------------------------------------------------------- the rail */

.rail {
  width: var(--rail-w);
  flex: 0 0 var(--rail-w);
  background: linear-gradient(180deg, var(--rail-top), var(--rail-bottom));
  color: #fff;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.rail-top { display: flex; gap: 6px; padding: 12px 12px 4px; }

.rail-icon {
  flex: 1;
  background: rgba(255, 255, 255, 0.1);
  border: 0;
  border-radius: var(--r-sm);
  padding: 7px;
  font-size: 15px;
  cursor: pointer;
  color: #fff;
  transition: background 0.15s ease, transform 0.15s ease;
}

.rail-icon:hover { background: rgba(255, 255, 255, 0.2); }
.rail-icon:active { transform: scale(0.94); }

.rail-user { padding: 14px 14px 10px; text-align: center; }

.rail-avatar {
  width: 58px;
  height: 58px;
  margin: 0 auto;
  border-radius: 18px;
  display: grid;
  place-items: center;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #fff;
  background: linear-gradient(135deg, var(--purple), #a794ff);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.28);
}

.rail-name {
  margin-top: 9px;
  font-size: 12.5px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.94);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rail-toggles { padding: 4px 14px 12px; }

.rail-chip {
  width: 100%;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: var(--r-sm);
  padding: 7px;
  cursor: pointer;
  font: inherit;
  font-size: 12.5px;
  transition: background 0.15s ease;
}

.rail-chip:hover { background: rgba(255, 255, 255, 0.2); }

.rail-nav { flex: 1; overflow-y: auto; padding: 4px 10px; }

.rail-item {
  position: relative;
  width: 100%;
  border: 0;
  background: transparent;
  color: rgba(255, 255, 255, 0.72);
  padding: 13px 6px;
  margin-bottom: 4px;
  border-radius: var(--r-md);
  display: block;
  cursor: pointer;
  font: inherit;
  font-size: 11.5px;
  font-weight: 600;
  transition: background 0.16s ease, color 0.16s ease;
}

.rail-item .rail-glyph { display: block; font-size: 20px; margin-bottom: 5px; filter: grayscale(0.25); }

.rail-item:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }

/* The active section reads as a raised tile rather than a tinted row, so it
 * is findable at a glance from across a surgery. */
.rail-item.active {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.14);
}

.rail-item.active .rail-glyph { filter: none; }

.rail-item.active::before {
  content: "";
  position: absolute;
  left: -10px;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 26px;
  border-radius: 0 3px 3px 0;
  background: #fff;
}

.rail-clinic {
  padding: 12px 10px;
  font-size: 11px;
  color: rgba(255, 255, 255, 0.5);
  text-align: center;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* --------------------------------------------------------------- the topbar */

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

.topbar {
  display: flex;
  align-items: center;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: var(--shadow-1);
}

.search {
  flex: 1;
  border: 0;
  padding: 18px 22px;
  font-size: 15px;
  outline: none;
  background: transparent;
  color: var(--ink);
  min-width: 0;
}

.search::placeholder { color: var(--faint); }

.search-scope {
  display: grid;
  place-items: center;
  padding: 0 20px;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  border-inline-start: 1px solid var(--line);
}

.search-go {
  border: 0;
  margin: 8px 10px;
  border-radius: var(--r-md);
  background: linear-gradient(135deg, var(--purple), #8a7bff);
  color: #fff;
  width: 46px;
  height: 40px;
  font-size: 17px;
  cursor: pointer;
  box-shadow: 0 4px 12px var(--purple-glow);
  transition: transform 0.14s ease, box-shadow 0.14s ease;
}

.search-go:hover { box-shadow: 0 6px 18px var(--purple-glow); }
.search-go:active { transform: translateY(1px) scale(0.98); }

.options-bar {
  background: var(--surface);
  color: var(--muted);
  text-align: center;
  padding: 7px;
  cursor: pointer;
  user-select: none;
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  border-bottom: 1px solid var(--line);
  transition: color 0.15s ease, background 0.15s ease;
}

.options-bar:hover { color: var(--purple); background: var(--surface-2); }
.options-bar .caret { display: inline-block; transition: transform 0.2s ease; }
.options-bar.open .caret { transform: rotate(180deg); }

.options-panel {
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
  padding: 16px 22px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
  animation: drop 0.22s ease both;
}

@keyframes drop {
  from { opacity: 0; transform: translateY(-6px); }
}

/* -------------------------------------------------------------- the content */

.content { padding: 6px 22px 110px; }

.summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(168px, 1fr));
  gap: 12px;
  padding: 18px 22px 4px;
}

.stat {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-1);
  padding: 14px 16px;
  overflow: hidden;
  transition: transform 0.16s ease, box-shadow 0.16s ease;
}

.stat:hover { transform: translateY(-2px); box-shadow: var(--shadow-2); }

/* A thin coloured edge tells the tiles apart without a legend. */
.stat::before {
  content: "";
  position: absolute;
  inset-inline-start: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--purple);
  opacity: 0.8;
}

.stat:nth-child(2)::before { background: var(--blue); }
.stat:nth-child(3)::before { background: var(--amber); }
.stat:nth-child(4)::before { background: var(--green); }
.stat:nth-child(5)::before { background: var(--red); }
.stat:nth-child(6)::before { background: #8b5cf6; }

.stat-label {
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.stat-value {
  font-size: 21px;
  font-weight: 700;
  margin-top: 3px;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
}

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

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-1);
  padding: 15px 17px;
  margin-bottom: 12px;
  transition: transform 0.16s ease, box-shadow 0.16s ease, border-color 0.16s ease;
  animation: fade 0.28s ease both;
}

@keyframes fade {
  from { opacity: 0; transform: translateY(6px); }
}

.card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-2);
  border-color: #dcd9f7;
}

.card-row { display: flex; gap: 15px; align-items: flex-start; }

/* ------------------------------------------------------------- case card */

/* Everything on one line at desk width, wrapping in sensible pieces as the
 * window narrows. Each block owns its width, so a short treatment name no
 * longer leaves a hole across the middle of the card. */
.case-head {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
}

.case-identity { flex: 1 1 180px; min-width: 0; }

.case-treatment {
  flex: 1 1 190px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.case-teeth { flex: 0 0 auto; display: flex; flex-direction: column; gap: 3px; align-items: center; }

.case-status {
  flex: 0 0 auto;
  margin-inline-start: auto;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 7px;
}

.case-chips { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

/* A caption over the value, so a number in a row of text has a name. */
.case-caption {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--faint);
}

.case-treatment-name {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.01em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* The actions sit on their own line under a hairline, so the card reads as
 * information first and controls second. */
.case-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px dashed var(--line);
}

/* Initials on a colour derived from the name: a wall of identical grey
 * silhouettes is harder to scan than a wall of distinct ones. */
.avatar {
  width: 52px;
  height: 52px;
  flex: 0 0 52px;
  border-radius: 15px;
  display: grid;
  place-items: center;
  font-size: 17px;
  font-weight: 700;
  color: #fff;
  letter-spacing: 0.02em;
  box-shadow: var(--shadow-1);
}

.card-main { flex: 1; min-width: 0; }

.card-name {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.01em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-phone { color: var(--muted); font-size: 12.5px; direction: ltr; font-variant-numeric: tabular-nums; }

/* The tooth number, boxed the way a casesheet boxes it. */
.teeth {
  display: inline-grid;
  place-items: center;
  min-width: 54px;
  height: 34px;
  padding: 0 11px;
  font-weight: 700;
  font-size: 14.5px;
  color: var(--ink);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-bottom: 2px solid var(--ink-soft);
  border-radius: var(--r-sm);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.card-treatment { font-weight: 600; }
.card-date { color: var(--muted); font-size: 12px; }

.card-actions { display: flex; gap: 7px; flex-wrap: wrap; }

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
  background: var(--surface-2);
  cursor: pointer;
  font-size: 15px;
  display: grid;
  place-items: center;
  text-decoration: none;
  transition: transform 0.14s ease, box-shadow 0.14s ease, filter 0.14s ease;
}

.icon-btn:hover { transform: translateY(-2px); box-shadow: var(--shadow-2); filter: brightness(1.03); }
.icon-btn:active { transform: translateY(0) scale(0.96); }

.icon-btn.pink { background: #ffe4ef; border-color: #ffcfe2; }
.icon-btn.green { background: #dcfce7; border-color: #bbf7d0; }
.icon-btn.amber { background: #fef3c7; border-color: #fde68a; }

.card-side {
  text-align: end;
  display: flex;
  flex-direction: column;
  gap: 7px;
  align-items: flex-end;
}

/* The case's own state, as a pill with a dot rather than shouted in capitals
 * inside brackets. */
.state-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 4px 12px;
  border-radius: var(--r-pill);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.01em;
  background: var(--line-soft);
  color: var(--muted);
  white-space: nowrap;
}

.state-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

.state-pill.ongoing { background: var(--green-bg); color: #15803d; }
.state-pill.ongoing .state-dot { animation: pulse 1.9s ease-in-out infinite; }
.state-pill.completed { background: var(--purple-100); color: var(--purple-600); }
.state-pill.cancelled { background: var(--red-bg); color: #b91c1c; }

@keyframes pulse {
  50% { opacity: 0.35; transform: scale(0.8); }
}

.chip {
  display: inline-block;
  padding: 3px 11px;
  border-radius: var(--r-pill);
  font-size: 11.5px;
  font-weight: 600;
  background: var(--purple-100);
  color: var(--purple-600);
  white-space: nowrap;
}

.chip.green { background: var(--green-bg); color: #15803d; }
.chip.amber { background: var(--amber-bg); color: #b45309; }
.chip.red { background: var(--red-bg); color: #b91c1c; }
.chip.grey { background: var(--line-soft); color: var(--muted); }

.edited { color: var(--faint); font-size: 11.5px; }

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

.table-wrap {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-1);
  overflow: hidden;
}

.table { width: 100%; border-collapse: collapse; }

.table th, .table td {
  padding: 13px 16px;
  text-align: start;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: middle;
}

.table th {
  background: var(--surface-2);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--muted);
  letter-spacing: 0.06em;
  position: sticky;
  top: 0;
  z-index: 1;
}

.table tbody tr { transition: background 0.13s ease; }
.table tbody tr:hover { background: var(--surface-2); }
.table tr:last-child td { border-bottom: 0; }

.table td.num, .table th.num { text-align: end; font-variant-numeric: tabular-nums; }
.table td.num .btn { margin-inline-start: 6px; }

/* ------------------------------------------------------------ empty states */

.empty { text-align: center; padding: 72px 20px; color: var(--muted); }
.empty-icon { font-size: 40px; opacity: 0.55; margin-bottom: 10px; }
.empty-title { font-size: 17px; font-weight: 700; color: var(--ink); margin-bottom: 5px; }

/* A shape while it loads, rather than the word "Loading" -- the page then
 * settles into content instead of jumping from text to a list. */
.skeleton { padding: 4px 0; }

.skeleton-row {
  height: 84px;
  border-radius: var(--r-md);
  margin-bottom: 12px;
  border: 1px solid var(--line);
  background: linear-gradient(90deg, var(--surface) 25%, var(--surface-2) 37%, var(--surface) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.3s ease-in-out infinite;
}

@keyframes shimmer {
  from { background-position: 100% 0; }
  to { background-position: 0 0; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

/* ------------------------------------------------------------------ inputs */

input, select, textarea {
  font: inherit;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--ink);
  transition: border-color 0.14s ease, box-shadow 0.14s ease;
  max-width: 100%;
}

input:hover, select:hover, textarea:hover { border-color: #d6d9e6; }

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--purple);
  box-shadow: 0 0 0 3px var(--purple-glow);
}

textarea { resize: vertical; min-height: 72px; }

.field { display: flex; flex-direction: column; gap: 5px; font-size: 13px; }
.field > span { color: var(--ink-soft); font-weight: 600; font-size: 12px; }
.field.grow { flex: 1; min-width: 190px; }

.btn {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  padding: 9px 16px;
  border-radius: var(--r-sm);
  cursor: pointer;
  font: inherit;
  font-weight: 600;
  font-size: 13px;
  transition: background 0.14s ease, border-color 0.14s ease, transform 0.14s ease, box-shadow 0.14s ease;
  white-space: nowrap;
}

.btn:hover { background: var(--surface-2); border-color: #d6d9e6; }
.btn:active { transform: translateY(1px); }

.btn.primary {
  background: linear-gradient(135deg, var(--purple), #8a7bff);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 4px 12px var(--purple-glow);
}

.btn.primary:hover { box-shadow: 0 6px 18px var(--purple-glow); filter: brightness(1.03); }

.btn.danger { color: var(--red); border-color: #f6cccc; background: var(--surface); }
.btn.danger:hover { background: var(--red-bg); }

.btn.block { width: 100%; margin-top: 22px; padding: 11px; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; box-shadow: none; }

.error { color: var(--red); margin-top: 12px; min-height: 20px; font-size: 13px; }

/* --------------------------------------------------------------------- fab */

.fab {
  position: fixed;
  inset-inline-end: 26px;
  bottom: 26px;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: 0;
  background: linear-gradient(135deg, var(--purple), #8a7bff);
  color: #fff;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 10px 28px var(--purple-glow), 0 2px 6px rgba(0, 0, 0, 0.18);
  transition: transform 0.16s cubic-bezier(0.2, 0.8, 0.3, 1), box-shadow 0.16s ease;
  z-index: 30;
}

.fab:hover { transform: translateY(-3px) rotate(90deg); box-shadow: 0 14px 34px var(--purple-glow); }
.fab:active { transform: translateY(0) scale(0.94); }

/* ------------------------------------------------------------------- modal */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20, 22, 34, 0.5);
  backdrop-filter: blur(3px);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 40;
  animation: fadein 0.16s ease both;
}

@keyframes fadein { from { opacity: 0; } }

.modal {
  background: var(--surface);
  border-radius: var(--r-lg);
  width: 100%;
  max-width: 580px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-3);
  border: 1px solid var(--line);
  animation: pop 0.22s cubic-bezier(0.2, 0.8, 0.3, 1) both;
}

@keyframes pop {
  from { opacity: 0; transform: translateY(14px) scale(0.98); }
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
}

.modal-head h2 { margin: 0; font-size: 16.5px; letter-spacing: -0.01em; }

.modal-close {
  border: 0;
  background: transparent;
  font-size: 24px;
  cursor: pointer;
  color: var(--muted);
  line-height: 1;
  width: 32px;
  height: 32px;
  border-radius: var(--r-sm);
  transition: background 0.14s ease, color 0.14s ease;
}

.modal-close:hover { background: var(--line-soft); color: var(--ink); }

.modal-body { padding: 22px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.modal-body form { display: flex; flex-direction: column; gap: 14px; }
.modal-body h3 { margin: 6px 0 0; font-size: 14px; color: var(--ink-soft); }
.modal-body .summary { padding: 0; }
.modal-body .options-panel { border: 1px solid var(--line); border-radius: var(--r-md); padding: 14px; animation: none; }

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 4px;
  padding-top: 14px;
  border-top: 1px solid var(--line-soft);
}

/* ------------------------------------------------------------------- toast */

.toast {
  position: fixed;
  inset-inline-start: 50%;
  transform: translateX(-50%);
  bottom: 30px;
  background: var(--ink);
  color: var(--bg);
  padding: 12px 22px;
  border-radius: var(--r-pill);
  z-index: 60;
  font-weight: 600;
  font-size: 13.5px;
  box-shadow: var(--shadow-3);
  animation: toastin 0.25s cubic-bezier(0.2, 0.8, 0.3, 1) both;
}

@keyframes toastin {
  from { opacity: 0; transform: translateX(-50%) translateY(10px); }
}

.toast.error { background: var(--red); color: #fff; }

/* --------------------------------------------------------------------- rtl */

html[dir="rtl"] .rail-item.active::before { left: auto; right: -10px; border-radius: 3px 0 0 3px; }
html[dir="rtl"] .toast { transform: translateX(50%); }
html[dir="rtl"] .card-side { align-items: flex-start; }

@keyframes toastin-rtl {
  from { opacity: 0; transform: translateX(50%) translateY(10px); }
}

html[dir="rtl"] .toast { animation-name: toastin-rtl; }

/* ------------------------------------------------------------------ narrow */

@media (max-width: 900px) {
  :root { --rail-w: 84px; }
  .rail-item span:not(.rail-glyph) { display: none; }
  .rail-item { padding: 14px 4px; }
  .rail-name, .rail-clinic { display: none; }
  .rail-avatar { width: 46px; height: 46px; font-size: 17px; border-radius: 14px; }
  .search-scope { display: none; }
  .content, .summary { padding-inline: 14px; }
}

@media (max-width: 620px) {
  .card-row { flex-wrap: wrap; }
  .card-side { align-items: flex-start; text-align: start; width: 100%; flex-direction: row; flex-wrap: wrap; }
  /* On a phone the status belongs under the name, not squeezed beside it. */
  .case-status { margin-inline-start: 0; align-items: flex-start; width: 100%; }
  .case-chips { justify-content: flex-start; }
  .case-teeth { align-items: flex-start; }
  .table th, .table td { padding: 10px 11px; }
  /* A wide table on a phone scrolls inside its own box rather than pushing
   * the whole page sideways. */
  .table-wrap { overflow-x: auto; }
  .table { min-width: 640px; }
}

/* ================================================================== chart */

.modal.modal-wide { max-width: 1080px; }

.chart { display: flex; flex-direction: column; gap: 16px; }

/* The stage is dark, like the chart a dentist is used to seeing on a
 * screen in the surgery, and it makes the teeth read as objects on a light
 * background rather than as shapes on paper. */
.chart-stage {
  position: relative;
  background:
    linear-gradient(180deg, #2b3444, #232b39);
  border-radius: var(--r-md);
  padding: 26px 22px;
  overflow-x: auto;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);

  --tooth: #f7efdc;
  --tooth-line: #6f6449;
}

.chart-arches {
  position: relative;
  min-width: 660px;
  display: flex;
  flex-direction: column;
  gap: 26px;
  padding: 4px 26px;
}

/* The horizontal rule between the arches, which is the occlusal plane. */
.chart-arches::before {
  content: "";
  position: absolute;
  left: 26px;
  right: 26px;
  top: 50%;
  height: 2px;
  background: rgba(255, 255, 255, 0.85);
  transform: translateY(-1px);
}

.arch { display: flex; align-items: flex-end; justify-content: center; gap: 2px; }
.arch-upper { align-items: flex-end; }
.arch-lower { align-items: flex-start; }

/* The midline. Without it left and right cannot be told apart at a glance. */
.midline {
  width: 2px;
  align-self: stretch;
  background: rgba(255, 255, 255, 0.85);
  margin: -14px 8px;
  border-radius: 2px;
}

.side-mark {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  color: rgba(255, 255, 255, 0.75);
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.06em;
  pointer-events: none;
}

.side-r { inset-inline-start: 0; }
.side-l { inset-inline-end: 0; }

/* ------------------------------------------------------------- one tooth */

.tooth {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  border: 0;
  background: transparent;
  padding: 0 1px;
  cursor: pointer;
  font: inherit;
  border-radius: 8px;
  transition: transform 0.14s ease, filter 0.14s ease;
}

.tooth.upper { flex-direction: column; }
.tooth.lower { flex-direction: column; }

/* The upper arch is the same drawing turned over, which is also how it sits
 * in the mouth -- roots up, crowns down onto the occlusal plane. */
.tooth.upper .tooth-svg { transform: scaleY(-1); }

.tooth:hover { transform: translateY(-3px); filter: brightness(1.08); }
.tooth.upper:hover { transform: translateY(3px); }
.tooth:active { transform: scale(0.97); }

.tooth-svg { display: block; overflow: visible; }

.tooth-number {
  font-size: 10px;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.5);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

.tooth.marked .tooth-number { color: rgba(255, 255, 255, 0.95); }

/* The label and its leader line, as a paper chart annotates a tooth. */
.tooth-label {
  font-size: 10.5px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: var(--r-pill);
  white-space: nowrap;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
  animation: fade 0.2s ease both;
}

.tooth-stem {
  width: 1px;
  height: 14px;
  background: rgba(255, 255, 255, 0.45);
}

.tooth:not(.marked) .tooth-stem { visibility: hidden; }

/* ---------------------------------------------------------- the palette */

.chart-legend { display: flex; flex-wrap: wrap; gap: 8px; }

.swatch {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: var(--r-pill);
  padding: 6px 14px 6px 8px;
  cursor: pointer;
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  transition: border-color 0.14s ease, box-shadow 0.14s ease, transform 0.14s ease;
}

.swatch:hover { transform: translateY(-1px); }

.swatch-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--swatch, var(--muted));
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12);
}

.swatch.erase .swatch-dot {
  background: repeating-linear-gradient(45deg, #fff, #fff 3px, #e5e7eb 3px, #e5e7eb 6px);
}

/* The armed colour is the one every click will apply, so it is unmistakable. */
.swatch.armed {
  border-color: var(--swatch, var(--purple));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--swatch, var(--purple)) 26%, transparent);
}

.chart-toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.chart-count { margin-inline-start: auto; color: var(--muted); font-size: 12.5px; font-weight: 600; }

/* -------------------------------------------------- the field on the form */

.teeth-field {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface);
  padding: 8px 8px 8px 12px;
}

.teeth-summary { flex: 1; min-width: 0; font-size: 13px; color: var(--ink); }
.teeth-summary.empty-value { color: var(--faint); }

@media (max-width: 620px) {
  .chart-stage { padding: 18px 10px; }
  .chart-count { margin-inline-start: 0; }
}

/* A layer opened from inside a dialog sits above it. */
.modal-overlay { z-index: 50; }

/* The chart as it appears on an open casesheet: the picture, then what it
 * says in words, then the way in to change it. */
.case-chart { display: flex; flex-direction: column; gap: 10px; }

.case-chart-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.case-chart-foot .muted { font-size: 13px; }

/* Read-only: it is a picture of the mouth, so nothing invites a click. */
.chart-static .tooth { cursor: default; }
.chart-static .tooth:hover { transform: none; filter: none; }
.chart-static .chart-arches { min-width: 620px; }

/* A rail item a role may not use is taken off it entirely. */
.rail-item.hidden { display: none !important; }

/* ================================================= the casesheet dialog */

/* A record rather than a scroll: what identifies the case stays at the top,
 * what it collects is behind tabs, and the actions stay in reach. */
.sheet { display: flex; flex-direction: column; gap: 14px; min-height: 0; }

.sheet-head { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.sheet-who { flex: 1 1 170px; min-width: 0; }

.sheet-what {
  flex: 1 1 190px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.sheet-money { display: flex; gap: 10px; flex-wrap: wrap; }

.figure {
  flex: 1 1 120px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-inline-start: 3px solid var(--purple);
  border-radius: var(--r-sm);
  padding: 9px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.figure.green { border-inline-start-color: var(--green); }
.figure.amber { border-inline-start-color: var(--amber); }

.figure-value { font-size: 16px; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }

.sheet-complaint {
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: var(--surface-2);
  border-radius: var(--r-sm);
  padding: 9px 12px;
  font-size: 13.5px;
}

.sheet-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  flex-wrap: wrap;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

/* ------------------------------------------------------------------ tabs */

.tabbed { display: flex; flex-direction: column; min-height: 0; }

.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
}

.tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  font-size: 13px;
  padding: 9px 14px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  white-space: nowrap;
  transition: color 0.14s ease, border-color 0.14s ease;
}

.tab:hover { color: var(--ink); }
.tab.active { color: var(--purple); border-bottom-color: var(--purple); }

.tab-badge {
  background: var(--line-soft);
  color: var(--muted);
  border-radius: var(--r-pill);
  padding: 1px 7px;
  font-size: 11px;
}

.tab.active .tab-badge { background: var(--purple-100); color: var(--purple-600); }

.tab-body { padding-top: 14px; min-height: 0; }

.panel { display: flex; flex-direction: column; gap: 12px; }

.panel-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

/* A form that sits above the list it adds to. */
.inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-end;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 12px;
}

.rows { display: flex; flex-direction: column; }

.row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 2px;
  border-bottom: 1px solid var(--line-soft);
  font-size: 13.5px;
}

.row:last-child { border-bottom: 0; }
.row-date { flex: 0 0 92px; color: var(--muted); font-variant-numeric: tabular-nums; font-size: 12.5px; }
.row-main { flex: 1; min-width: 0; }
.row-amount { margin-inline-start: auto; font-variant-numeric: tabular-nums; }

.rows .empty { padding: 40px 20px; }

/* ------------------------------------------------------------- the notes */

.notes { display: flex; flex-direction: column; gap: 10px; }

.note {
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 10px 12px;
  background: var(--surface-2);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* An x-ray is looked at, not glanced at, so it gets room -- but never more
 * than the dialog it sits in. */
.note-media {
  display: block;
  width: 100%;
  max-height: 340px;
  object-fit: contain;
  border-radius: var(--r-sm);
  background: #000000;
}

.note-body { white-space: pre-wrap; font-size: 13.5px; }

.note-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 11.5px;
}

/* ========================================================== prescription */

/* The page and the things you reach for while writing on it, side by side.
 * Everything that is not the page is out of the page's way. */
.rx { display: flex; gap: 16px; align-items: flex-start; }

.rx-stage {
  flex: 1;
  min-width: 0;
  background: var(--line-soft);
  padding: 16px;
  border-radius: var(--r-md);
  display: flex;
  justify-content: center;
  max-height: 68vh;
  overflow: auto;
}

/* Paper. White whatever the viewer's theme is, at the proportions it prints
 * at, so what is on screen is what comes out. */
.rx-sheet {
  background: #ffffff;
  color: #111111;
  width: 100%;
  display: flex;
  flex-direction: column;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.18);
}

.rx-a5 { max-width: 460px; min-height: 650px; }
.rx-a4 { max-width: 560px; min-height: 792px; }

/* The clinic's own artwork, edge to edge as it was uploaded. */
.rx-band { display: block; width: 100%; height: auto; }

.rx-band-empty {
  background: #23282e;
  color: #ffffff;
  padding: 20px 16px;
  text-align: center;
  font-size: 18px;
  font-weight: 700;
}

.rx-page { flex: 1; display: flex; flex-direction: column; padding: 18px 22px 12px; gap: 14px; }

.rx-meta { display: flex; flex-wrap: wrap; gap: 8px 14px; }

.rx-detail { flex: 1 1 180px; display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.rx-detail-date { flex: 0 0 auto; }
.rx-detail-small { flex: 0 1 110px; }

.rx-detail-label { font-size: 11px; color: #777777; white-space: nowrap; }

/* Underlined rather than boxed: a prescription is a written form, and boxes
 * around filled-in values make it look like a screen instead. */
.rx-detail-value {
  flex: 1;
  min-width: 0;
  border-bottom: 1px solid #cccccc;
  padding: 2px 2px 3px;
  font-size: 13.5px;
  min-height: 20px;
}

.rx-main { flex: 1; display: flex; gap: 12px; align-items: stretch; }

.rx-symbol {
  font-size: 34px;
  font-weight: 400;
  line-height: 1;
  color: #222222;
  font-family: Georgia, "Times New Roman", serif;
}

/* Typed straight onto the page, so what is written is what prints. */
.rx-body {
  flex: 1;
  min-height: 300px;
  font-size: 14.5px;
  line-height: 2.05;
  white-space: pre-wrap;
  outline: none;
  /* Ruled, like a pad. The lines are drawn rather than bordered so nothing
   * boxes the text in. */
  background-image: repeating-linear-gradient(
    transparent, transparent 28.7px, #ececec 28.7px, #ececec 29.7px
  );
  padding: 2px 4px;
}

.rx-body:empty::before {
  content: attr(data-placeholder);
  color: #b6b6b6;
}

.rx-sign { display: flex; flex-direction: column; gap: 3px; align-items: flex-end; }
.rx-rule { width: 190px; border-bottom: 1px solid #999999; }
.rx-sign-label { display: flex; gap: 8px; font-size: 11.5px; color: #777777; }
.rx-dentist { color: #333333; font-weight: 600; }
.rx-note { font-size: 11px; color: #888888; text-align: center; }

/* ----------------------------------------------------------- the sidebar */

.rx-side {
  flex: 0 0 268px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-height: 68vh;
}

.rx-side-block { display: flex; flex-direction: column; gap: 8px; min-height: 0; flex: 1; }
.rx-side-block input { width: 100%; }

.rx-medicines {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-inline-end: 2px;
}

.rx-medicine {
  text-align: start;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: var(--r-sm);
  padding: 8px 11px;
  cursor: pointer;
  font: inherit;
  display: flex;
  flex-direction: column;
  gap: 2px;
  transition: border-color 0.14s ease, transform 0.14s ease, box-shadow 0.14s ease;
}

.rx-medicine:hover {
  border-color: var(--purple);
  transform: translateY(-1px);
  box-shadow: var(--shadow-1);
}

.rx-medicine-name { font-weight: 600; font-size: 13px; }
.rx-medicine-directions { font-size: 11.5px; color: var(--muted); }
.rx-hint { font-size: 12.5px; padding: 10px 2px; }

.rx-side-foot {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.rx-side-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }

.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: var(--r-sm); overflow: hidden; }

.segmented button {
  border: 0;
  background: var(--surface);
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  font-size: 12.5px;
  padding: 6px 16px;
  cursor: pointer;
}

.segmented button.active { background: var(--purple); color: #ffffff; }

/* The print button is the sidebar's purpose, so it takes the full width. */
.rx-print { width: 100%; padding: 11px; }

/* ------------------------------------------- the letterhead, in settings */

.card h3 { margin: 0 0 6px; font-size: 15px; }

.letterhead { display: flex; flex-wrap: wrap; gap: 14px; margin: 12px 0; }
.letterhead-slot { flex: 1 1 260px; display: flex; flex-direction: column; gap: 6px; }

/* The mark is square and shown small, so it does not need a band's width. */
.letterhead-logo { flex: 0 0 160px; }
.letterhead-logo .letterhead-preview { aspect-ratio: 1; object-fit: contain; padding: 6px; }

.letterhead-preview {
  width: 100%;
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
  background: #ffffff;
}

.letterhead-empty {
  padding: 22px;
  text-align: center;
  color: var(--faint);
  border: 1px dashed var(--line);
  border-radius: var(--r-sm);
}

/* --------------------------------------------------------------- narrow */

@media (max-width: 820px) {
  .rx { flex-direction: column; }
  .rx-side { flex: 1 1 auto; width: 100%; max-height: none; }
  .rx-medicines { max-height: 220px; }
  .rx-stage { max-height: none; }
}

/* ---------------------------------------------------------------- print */

/* Nothing but the page. It prints from the same markup that was on screen,
 * so what comes out cannot differ from what the dentist approved. */
@media print {
  body { background: #ffffff; }

  .app, .rail, .topbar, .options-bar, .options-panel, .summary, .content,
  .fab, .toast, .rx-side, .modal-head { display: none !important; }

  .modal-backdrop, .modal-overlay {
    position: static;
    display: block;
    background: none;
    backdrop-filter: none;
    padding: 0;
  }

  .modal {
    box-shadow: none;
    border: 0;
    max-width: none;
    max-height: none;
    border-radius: 0;
  }

  .modal-body { padding: 0; overflow: visible; }

  .rx { display: block; }

  .rx-stage {
    background: none;
    padding: 0;
    overflow: visible;
    max-height: none;
    display: block;
  }

  .rx-sheet { box-shadow: none; max-width: none; min-height: 0; width: 100%; }

  /* The ruling is a writing aid on screen; on paper it is somebody else's
   * lines printed under the dentist's words. */
  .rx-body { background-image: none; }
  .rx-body:empty::before { content: none; }

  @page { margin: 0; }
}

/* Adding somebody to the clinic: the two ways in, and the fields for each.
 * The panel is swapped rather than the modal reopened, so switching does not
 * lose what has already been typed into the fields the two have in common. */
.staff-modes { align-self: flex-start; }
.staff-fields { display: flex; flex-direction: column; gap: 14px; }
.form-row { display: flex; flex-wrap: wrap; gap: 12px; }
.form-note { line-height: 1.5; }

/* The clinic's mark and name at the foot of the rail. */
.rail-practice {
  padding: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.rail-practice .rail-clinic { padding: 0; border-top: 0; max-width: 100%; }

.rail-logo {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  object-fit: contain;
  background: #ffffff;
  padding: 3px;
}
