/* Dental clinic appointment manager — RTL-first, no framework. */

:root {
  --bg: #f3f6f8;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e4e9ef;
  --border-strong: #d4dbe3;
  --text: #0f172a;
  --text-2: #334155;
  --muted: #64748b;
  --primary: #0f766e;
  --primary-hover: #115e59;
  --primary-50: #ecfdf8;
  --primary-100: #ccfbf1;
  --danger: #dc2626;
  --warn: #d97706;
  --ok: #16a34a;
  --wa: #1a9e4b;
  --wa-hover: #158740;
  --line: #eef2f6;
  --line-strong: #dfe5ec;
  --gutter: 64px;
  --radius: 12px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.12);
  --shadow-lg: 0 24px 60px rgba(15, 23, 42, 0.22);
}

* { box-sizing: border-box; }

html, body { margin: 0; height: 100%; }

body {
  font-family: 'IBM Plex Sans Arabic', 'Segoe UI', Tahoma, system-ui, sans-serif;
  font-size: 14.5px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  height: 100vh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { line-height: 1.3; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
[hidden] { display: none !important; }
.ic { flex-shrink: 0; }
.muted { color: var(--muted); }
.sm { font-size: 12.5px; }
.center { text-align: center; }
.spacer { flex: 1; }
code { background: #f1f5f9; padding: 1px 6px; border-radius: 6px; font-size: 12px; font-family: inherit; }

kbd {
  font-family: inherit;
  font-size: 11px;
  line-height: 1;
  padding: 3px 6px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.2);
}

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-2);
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s;
}
.btn:hover { background: var(--surface-2); border-color: #c3ccd6; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-wa { background: var(--wa); border-color: var(--wa); color: #fff; }
.btn-wa:hover { background: var(--wa-hover); border-color: var(--wa-hover); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-ghost-danger { background: transparent; border-color: transparent; color: var(--danger); }
.btn-ghost-danger:hover { background: #fef2f2; border-color: #fecaca; }
.btn-sm { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn-xs { padding: 3px 8px; font-size: 12px; border-radius: 7px; gap: 3px; }
.btn.block { width: 100%; }
.btn.is-today { border-color: var(--primary); color: var(--primary); background: var(--primary-50); }

.icon-btn {
  width: 36px;
  height: 36px;
  display: inline-grid;
  place-items: center;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-2);
  padding: 0;
  transition: background 0.15s;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn.sm { width: 28px; height: 28px; border-radius: 8px; border-color: transparent; }
.btn-group { display: flex; gap: 4px; }

.link {
  background: none;
  border: 0;
  padding: 0;
  color: var(--primary);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* ---------- top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  color: #fff;
  background: linear-gradient(140deg, #2dd4bf, #0f766e);
  box-shadow: 0 4px 12px rgba(15, 118, 110, 0.3);
  flex-shrink: 0;
}
.brand-name { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 240px; }
.brand-sub { font-size: 12px; color: var(--muted); }

.tabs { display: flex; gap: 4px; }
.tab {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
}
.tab:hover { background: var(--surface-2); color: var(--text-2); }
.tab.active { background: var(--primary-50); color: var(--primary); }

.search { position: relative; flex: 1; max-width: 440px; margin-inline-start: auto; }
.search > .ic { position: absolute; inset-inline-start: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search input {
  width: 100%;
  padding: 9px 12px;
  padding-inline: 38px 40px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: #f1f4f7;
  outline: none;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.search input:focus { background: #fff; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12); }
.search-kbd {
  position: absolute;
  inset-inline-end: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: #fff;
  border: 1px solid var(--border-strong);
  color: var(--muted);
}
.search input:focus ~ .search-kbd { display: none; }
.search.sm { max-width: 260px; margin: 0; }

.dropdown {
  position: absolute;
  top: calc(100% + 6px);
  inset-inline: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 6px;
  z-index: 60;
  max-height: 380px;
  overflow: auto;
}
.dd-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  text-align: start;
}
.dd-item:hover, .dd-item.active { background: #f1f5f9; }
.dd-main { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.dd-main small { color: var(--muted); text-align: right; }
.dd-new { color: var(--primary); font-weight: 600; }

/* ---------- layout ---------- */

.layout { display: grid; grid-template-columns: 300px minmax(0, 1fr); min-height: 0; }

.sidebar {
  overflow: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  border-inline-end: 1px solid var(--border);
}

.main {
  overflow: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  box-shadow: var(--shadow-sm);
}
.card-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 700;
  font-size: 14px;
  margin-bottom: 10px;
}
.card-title > span:first-child { display: inline-flex; align-items: center; gap: 6px; }
.count { background: var(--primary-50); color: var(--primary); border-radius: 99px; padding: 0 9px; font-size: 12px; font-weight: 700; }

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--primary-100);
  color: var(--primary);
  font-weight: 700;
  flex-shrink: 0;
}
.avatar.sm { width: 30px; height: 30px; font-size: 13px; }
.avatar.lg { width: 46px; height: 46px; font-size: 18px; }

.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--c, var(--primary)); flex-shrink: 0; }

.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 9px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.tag.sm { font-size: 11px; padding: 1px 7px; }
.tag.teal { background: var(--primary-100); color: #115e59; }
.tag.red { background: #fee2e2; color: #991b1b; }
.tag.amber { background: #fef3c7; color: #92400e; white-space: normal; }

/* ---------- sidebar: calendar, stats, waiting room ---------- */

.cal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.cal-wd { text-align: center; font-size: 11px; color: var(--muted); padding: 4px 0; font-weight: 600; }
.cal-cell {
  aspect-ratio: 1;
  border: 0;
  border-radius: 9px;
  background: transparent;
  font-size: 13px;
  position: relative;
  display: grid;
  place-items: center;
  padding: 0;
}
.cal-cell:hover:not(.empty) { background: #f1f5f9; }
.cal-cell.off { color: #b6c0cc; }
.cal-cell.today { box-shadow: inset 0 0 0 1.5px var(--primary); color: var(--primary); font-weight: 700; }
.cal-cell.selected { background: var(--primary); color: #fff; font-weight: 700; }
.cal-cell.selected:hover { background: var(--primary-hover); }
.load { position: absolute; bottom: 4px; height: 4px; border-radius: 99px; background: #14b8a6; }
.load.l1 { width: 4px; }
.load.l2 { width: 10px; }
.load.l3 { width: 16px; background: #f59e0b; }
.cal-cell.selected .load { background: #fff; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.stat { background: var(--surface-2); border-radius: 10px; padding: 8px 4px; text-align: center; }
.stat b { display: block; font-size: 20px; line-height: 1.2; }
.stat span { font-size: 11.5px; color: var(--muted); }
.stat.ok b { color: var(--ok); }
.stat.warn b { color: var(--warn); }
.stat.bad b { color: var(--danger); }
.stats.inline { margin-bottom: 16px; }
.stats.inline .stat b { font-size: 15px; }
.revenue {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--border-strong);
  font-size: 13.5px;
  color: var(--muted);
}
.revenue b { color: var(--primary); font-size: 15px; }

.wait-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.wait-sep { font-size: 11.5px; color: var(--muted); font-weight: 600; margin-top: 2px; }
.wait-item { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 10px; background: var(--surface-2); }
.wait-main { flex: 1; min-width: 0; display: flex; flex-direction: column; text-align: start; border: 0; background: none; padding: 0; }
.wait-main small { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wait-time { font-weight: 700; font-size: 12.5px; color: #92400e; background: #fef3c7; padding: 2px 8px; border-radius: 99px; white-space: nowrap; }
.wait-time.late { background: #fee2e2; color: #b91c1c; }
.pulse-dot { width: 9px; height: 9px; border-radius: 50%; background: #22c55e; box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.6); animation: pulse 1.8s infinite; flex-shrink: 0; }
@keyframes pulse { 70% { box-shadow: 0 0 0 7px rgba(34, 197, 94, 0); } 100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); } }

.empty-note { color: var(--muted); font-size: 13px; margin: 0; line-height: 1.7; }
.rem-text { margin: 0 0 10px; font-size: 13.5px; color: var(--text-2); }
.rem-text.ok { color: var(--ok); display: flex; align-items: center; gap: 6px; font-weight: 600; }

/* ---------- schedule ---------- */

.banner {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  padding: 14px 16px;
  margin-bottom: 14px;
  border-radius: 14px;
  background: linear-gradient(135deg, #f0fdfa, #eff6ff);
  border: 1px solid #a7f3d0;
}
.banner-icon { width: 42px; height: 42px; border-radius: 12px; background: #fff; color: var(--primary); display: grid; place-items: center; box-shadow: var(--shadow-sm); }
.banner-text { flex: 1; min-width: 220px; display: flex; flex-direction: column; }
.banner-text span { color: var(--muted); font-size: 13.5px; }

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.date-nav { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.date-title { display: flex; align-items: center; gap: 8px; }
.date-title h1 { font-size: 20px; margin: 0; font-weight: 700; }
.rel { background: var(--primary-50); color: var(--primary); padding: 2px 10px; border-radius: 99px; font-size: 12.5px; font-weight: 700; }
.rel.off { background: #fee2e2; color: var(--danger); }
.toolbar-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.sub-note { font-size: 12.5px; color: var(--muted); margin: -4px 0 8px; }

.segmented { display: inline-flex; background: #eaeff3; padding: 3px; border-radius: 11px; gap: 2px; flex-wrap: wrap; }
.segmented button {
  border: 0;
  background: transparent;
  padding: 6px 12px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 13.5px;
  color: #475569;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.segmented button:hover { color: var(--text); }
.segmented button.active { background: #fff; color: var(--text); box-shadow: 0 1px 3px rgba(15, 23, 42, 0.1); }
.segmented.full { display: flex; }
.segmented.full button { flex: 1; justify-content: center; padding: 8px 12px; }

.sched-wrap {
  flex: 1;
  min-height: 320px;
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-sm);
  position: relative;
}
.sched { min-width: min-content; }
.sched-head {
  display: grid;
  position: sticky;
  top: 0;
  z-index: 6;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.corner { position: sticky; inset-inline-start: 0; background: var(--surface); z-index: 2; }
.doc-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-inline-start: 1px solid var(--border);
  box-shadow: inset 0 3px 0 var(--c);
}
.doc-head .avatar { color: #fff; }
.doc-head > div { display: flex; flex-direction: column; min-width: 0; }
.doc-head b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-head small { color: var(--muted); font-size: 12px; }

.sched-body { display: grid; position: relative; }
.gutter { position: sticky; inset-inline-start: 0; z-index: 3; background: var(--surface); }
.hour {
  position: absolute;
  inset-inline-end: 10px;
  transform: translateY(3px);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  display: flex;
  align-items: baseline;
  gap: 2px;
}
.hour small { font-size: 10.5px; color: var(--muted); font-weight: 500; }

.col {
  position: relative;
  border-inline-start: 1px solid var(--border);
  background-image:
    linear-gradient(to bottom, var(--line-strong) 1px, transparent 1px),
    linear-gradient(to bottom, var(--line) 1px, transparent 1px);
  background-size: 100% calc(var(--row) * var(--per-hour)), 100% var(--row);
  background-position: 0 var(--hour-offset), 0 0;
  cursor: copy;
}

.ghost {
  position: absolute;
  inset-inline: 4px;
  display: flex;
  align-items: center;
  padding: 0 8px;
  border: 1.5px dashed var(--primary);
  border-radius: 8px;
  background: rgba(15, 118, 110, 0.06);
  color: var(--primary);
  font-size: 12px;
  font-weight: 700;
  pointer-events: none;
  z-index: 1;
}
.ghost.drop { align-items: flex-start; padding-top: 3px; background: rgba(15, 118, 110, 0.1); }

.appt {
  position: absolute;
  z-index: 2;
  overflow: hidden;
  padding: 4px 8px 4px 8px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--c) 12%, #fff);
  border: 1px solid color-mix(in srgb, var(--c) 28%, #fff);
  border-inline-start: 4px solid var(--c);
  font-size: 12.5px;
  line-height: 1.35;
  cursor: pointer;
  transition: box-shadow 0.15s, transform 0.15s, opacity 0.15s;
}
.appt:hover, .appt:focus-visible { box-shadow: 0 6px 16px rgba(15, 23, 42, 0.14); z-index: 4; outline: none; }
.appt-line { display: flex; align-items: center; gap: 6px; min-width: 0; }
.appt-line b { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 13px; }
.appt-time { font-weight: 700; font-size: 11.5px; white-space: nowrap; color: color-mix(in srgb, var(--c) 75%, #000); }
.appt-name { font-weight: 700; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appt-proc { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 12px; }
.appt-proc .appt-time { margin-inline-end: 4px; }
.appt-notes { color: var(--muted); font-size: 11.5px; margin-top: 2px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.appt.compact { display: flex; align-items: center; padding-top: 0; padding-bottom: 0; }
.appt.compact .appt-line { width: 100%; }

.badge {
  margin-inline-start: auto;
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 1px 6px;
  border-radius: 99px;
  font-size: 10.5px;
  font-weight: 700;
  white-space: nowrap;
  flex-shrink: 0;
}
.b-confirmed { background: #fff; color: var(--c); padding: 2px; }
.b-arrived { background: #fef3c7; color: #92400e; }
.b-chair { background: #dcfce7; color: #166534; }
.b-done { background: #fff; color: #475569; padding: 2px; }
.b-noshow { background: #fee2e2; color: #991b1b; }

.appt.st-done { opacity: 0.6; filter: saturate(0.6); }
.appt.st-no_show {
  background: repeating-linear-gradient(-45deg, #fff 0 6px, #fef2f2 6px 12px);
  border-color: #fecaca;
  border-inline-start-color: #f87171;
}
.appt.st-no_show .appt-name, .appt.st-no_show b { text-decoration: line-through; text-decoration-color: #f87171; }
.appt.st-arrived { box-shadow: 0 0 0 2px #fbbf24; }
.appt.st-in_chair { box-shadow: 0 0 0 2px #22c55e; }
.appt.dragging { opacity: 0.35; }
.appt.flash { animation: flash 1.6s ease-out; }
@keyframes flash {
  0%, 40% { box-shadow: 0 0 0 4px rgba(15, 118, 110, 0.45); transform: scale(1.02); }
  100% { box-shadow: 0 0 0 0 rgba(15, 118, 110, 0); transform: none; }
}

.now-line {
  position: absolute;
  inset-inline-start: var(--gutter);
  inset-inline-end: 0;
  border-top: 2px solid #ef4444;
  z-index: 5;
  pointer-events: none;
}
.now-line::before {
  content: '';
  position: absolute;
  inset-inline-start: -5px;
  top: -6px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #ef4444;
}
.now-line span {
  position: absolute;
  inset-inline-end: 100%;
  top: -11px;
  margin-inline-end: 4px;
  background: #ef4444;
  color: #fff;
  font-size: 10.5px;
  font-weight: 700;
  padding: 2px 5px;
  border-radius: 6px;
  white-space: nowrap;
}

.empty-state { margin: auto; text-align: center; color: var(--muted); padding: 40px; }
.empty-state h2 { color: var(--text); margin: 12px 0 4px; }

/* ---------- modals ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(2px);
  opacity: 0;
  transition: opacity 0.15s;
}
.modal-backdrop.open { opacity: 1; }
.modal {
  width: 100%;
  max-width: 560px;
  max-height: calc(100vh - 48px);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-radius: 18px;
  box-shadow: var(--shadow-lg);
  transform: translateY(10px) scale(0.98);
  transition: transform 0.18s ease-out;
}
.modal-backdrop.open .modal { transform: none; }
.modal.modal-lg { max-width: 740px; }
.modal.modal-md { max-width: 600px; }
.modal.modal-sm { max-width: 420px; }
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 18px 24px 4px; }
.modal-head h2 { margin: 0; font-size: 19px; }
.modal-head .icon-btn, .detail-head .icon-btn { border-color: transparent; background: transparent; }
.modal-head .icon-btn:hover, .detail-head .icon-btn:hover { background: #f1f5f9; }
.modal-body { padding: 16px 24px; overflow: auto; }
.modal-foot { display: flex; align-items: center; gap: 8px; padding: 14px 24px; border-top: 1px solid var(--border); }
.modal-foot.wrap { flex-wrap: wrap; }
.ph-title { display: flex; align-items: center; gap: 12px; }

.confirm { text-align: center; padding-top: 28px; }
.confirm h2 { margin: 0 0 6px; font-size: 18px; }
.confirm p { margin: 0; color: var(--muted); line-height: 1.7; }
.confirm-icon { width: 54px; height: 54px; border-radius: 50%; display: grid; place-items: center; margin: 0 auto 12px; }
.confirm-icon.warn { background: #fef3c7; color: var(--warn); }
.confirm-icon.danger { background: #fee2e2; color: var(--danger); }

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

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; position: relative; min-width: 0; }
.field > span { font-size: 13px; font-weight: 600; color: var(--text-2); }
.row { display: grid; gap: 12px; }
.row.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.row.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }

input:where(:not([type='checkbox']):not([type='color'])), select, textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  background: #fff;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input[dir='ltr'] { text-align: right; }
textarea { resize: vertical; line-height: 1.7; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12); }
input[type='color'] { width: 40px; height: 38px; padding: 3px; border: 1px solid var(--border-strong); border-radius: 9px; background: #fff; cursor: pointer; }
.field.invalid input { border-color: var(--danger); box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.12); animation: shake 0.3s; }
@keyframes shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
.hint { font-size: 12px; color: var(--muted); }
.hint.error { color: var(--danger); }
.date-hint { font-size: 12.5px; color: var(--muted); margin: -8px 0 12px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 99px;
  background: #fff;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s, border-color 0.15s;
}
.chip small { color: var(--muted); font-size: 11.5px; }
.chip:hover { background: var(--surface-2); }
.chip.active {
  border-color: var(--c, var(--primary));
  background: color-mix(in srgb, var(--c, var(--primary)) 10%, #fff);
  box-shadow: inset 0 0 0 1px var(--c, var(--primary));
  font-weight: 600;
}
.chip.check input { display: none; }

.alert { padding: 10px 12px; border-radius: 10px; font-size: 13.5px; margin-bottom: 10px; line-height: 1.6; }
.alert > .ic, .alert > div > .ic { vertical-align: -3px; }
.alert ul { margin: 6px 0 10px; padding-inline-start: 22px; }
.alert.ok { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }
.alert.warn { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }
.alert.info { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }
.alert.danger { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }

.patient-field .dropdown { top: calc(100% + 2px); }
.pchip {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 12px;
  margin: -4px 0 14px;
  border-radius: 12px;
  background: var(--primary-50);
  border: 1px solid #a7f3d0;
}
.pchip.new { background: var(--surface-2); border: 1px dashed var(--border-strong); color: #475569; font-size: 13.5px; }
.pchip-main { flex: 1; min-width: 160px; display: flex; flex-direction: column; }
.pchip-main small { color: var(--muted); }

/* ---------- details ---------- */

.detail-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: 20px 24px 16px;
  border-radius: 18px 18px 0 0;
  border-top: 5px solid var(--c);
  background: linear-gradient(180deg, color-mix(in srgb, var(--c) 10%, #fff), #fff);
}
.detail-head h2 { margin: 4px 0; font-size: 22px; }
.detail-proc { display: flex; align-items: center; gap: 6px; font-weight: 700; font-size: 13px; color: color-mix(in srgb, var(--c) 80%, #000); }
.detail-meta { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; color: #475569; font-size: 13.5px; }

.status-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.status-btn {
  padding: 8px 6px;
  border-radius: 9px;
  border: 1px solid var(--border-strong);
  background: #fff;
  font-weight: 600;
  font-size: 13px;
  color: var(--text-2);
}
.status-btn:hover { background: var(--surface-2); }
.status-btn.active { box-shadow: inset 0 0 0 1px currentColor; border-color: currentColor; }
.status-btn.active.s-scheduled { background: #e0f2fe; color: #075985; }
.status-btn.active.s-confirmed { background: var(--primary-100); color: #115e59; }
.status-btn.active.s-arrived { background: #fef3c7; color: #92400e; }
.status-btn.active.s-in_chair { background: #dcfce7; color: #166534; }
.status-btn.active.s-done { background: #e2e8f0; color: #1e293b; }
.status-btn.active.s-no_show { background: #fee2e2; color: #991b1b; }
.status-btn.active.s-cancelled { background: #f1f5f9; color: #64748b; }

.info-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.info-grid > div { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; display: flex; flex-direction: column; gap: 2px; }
.info-grid span { font-size: 12px; color: var(--muted); }
.info-grid a { color: var(--primary); font-weight: 700; text-decoration: none; text-align: right; }
.info-grid em { color: #94a3b8; font-style: normal; }
.info-grid .ok { color: var(--ok); display: inline-flex; align-items: center; gap: 4px; }
.notes-box { margin-top: 10px; background: #fffbeb; border: 1px solid #fde68a; border-radius: 10px; padding: 10px 12px; }
.notes-box span { font-size: 12px; color: #92400e; font-weight: 600; }
.notes-box p { margin: 2px 0 0; }

.pill { font-size: 11.5px; padding: 2px 9px; border-radius: 99px; font-weight: 600; white-space: nowrap; }
.pill.s-scheduled { background: #e0f2fe; color: #075985; }
.pill.s-confirmed { background: var(--primary-100); color: #115e59; }
.pill.s-arrived { background: #fef3c7; color: #92400e; }
.pill.s-in_chair { background: #dcfce7; color: #166534; }
.pill.s-done { background: #e2e8f0; color: #334155; }
.pill.s-no_show { background: #fee2e2; color: #991b1b; }
.pill.s-cancelled { background: #f1f5f9; color: #94a3b8; text-decoration: line-through; }

.history { list-style: none; padding: 0; margin: 0; max-height: 260px; overflow: auto; border: 1px solid var(--border); border-radius: 12px; }
.history button {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 0;
  border-bottom: 1px solid #f1f5f9;
  background: #fff;
  text-align: start;
}
.history li:last-child button { border-bottom: 0; }
.history button:hover { background: var(--surface-2); }
.h-date { width: 92px; font-weight: 600; font-size: 13px; flex-shrink: 0; }
.h-date small { color: var(--muted); font-weight: 400; }
.h-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.h-main small { color: var(--muted); }

/* ---------- reminders ---------- */

.progress { height: 6px; background: #e2e8f0; border-radius: 99px; overflow: hidden; margin: 14px 0 6px; }
.progress i { display: block; height: 100%; background: var(--wa); transition: width 0.3s; }
.rem-list { list-style: none; padding: 0; margin: 0 0 12px; }
.rem-list li { display: flex; align-items: center; gap: 12px; padding: 10px 2px; border-bottom: 1px solid #f1f5f9; }
.rem-list li.sent { opacity: 0.6; }
.r-time { width: 74px; font-weight: 700; color: var(--primary); font-size: 13.5px; flex-shrink: 0; }
.r-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.r-main small { color: var(--muted); }

/* ---------- pages ---------- */

.page { width: 100%; max-width: 1200px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { margin: 0; font-size: 22px; }
.page-head p { margin: 2px 0 0; }
.page-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.table-card { padding: 0; overflow: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th {
  text-align: start;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  padding: 12px 16px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table td { padding: 10px 16px; border-bottom: 1px solid #f1f5f9; vertical-align: middle; }
.table tbody tr[data-action] { cursor: pointer; }
.table tbody tr[data-action]:hover td { background: var(--surface-2); }
.cell-patient { display: flex; align-items: center; gap: 10px; }
.cell-patient > div { display: flex; flex-direction: column; }
.cell-patient small.amber { color: #b45309; font-size: 12px; }
.phone-cell { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.row-actions { text-align: end; }
.empty-cell { padding: 48px 16px !important; color: var(--muted); }

.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.settings-grid .span-2 { grid-column: 1 / -1; }
.settings h3 { margin: 0 0 14px; font-size: 16px; }
.card-h { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.card-h h3 { margin: 0; }
.edit-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.edit-list li { display: grid; grid-template-columns: 40px minmax(0, 1fr) 30px; gap: 8px; align-items: center; }
.edit-list.procs li, .edit-head { grid-template-columns: 40px minmax(0, 1fr) 76px 100px 30px; }
.edit-head { display: grid; gap: 8px; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.wa-preview {
  white-space: pre-wrap;
  background: #dcf8c6;
  border: 1px solid #c4ecaa;
  border-radius: 14px 14px 14px 4px;
  padding: 12px 14px;
  font-size: 14px;
  line-height: 1.75;
  min-height: 140px;
}
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- toasts ---------- */

.toasts {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 120;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: min(92vw, 560px);
  padding: 10px 14px;
  border-radius: 12px;
  background: #0f172a;
  color: #fff;
  font-size: 14px;
  box-shadow: var(--shadow);
  border-inline-start: 4px solid #94a3b8;
  animation: toast-in 0.2s ease-out;
  transition: opacity 0.3s, transform 0.3s;
}
.toast.success { border-inline-start-color: #34d399; }
.toast.error { border-inline-start-color: #f87171; }
.toast.leaving { opacity: 0; transform: translateY(6px); }
.toast-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 0;
  border-radius: 8px;
  padding: 5px 10px;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  white-space: nowrap;
}
.toast-btn:hover { background: rgba(255, 255, 255, 0.24); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ---------- responsive ---------- */

@media (max-width: 1180px) {
  .layout { grid-template-columns: 270px minmax(0, 1fr); }
  .tab span { display: none; }
}

@media (max-width: 900px) {
  body { display: block; height: auto; overflow: auto; }
  .topbar { flex-wrap: wrap; gap: 10px; padding: 10px 16px; position: sticky; top: 0; }
  .brand-sub, .btn-new kbd, .search-kbd { display: none; }
  .tabs { margin-inline-start: auto; }
  .search { order: 5; flex-basis: 100%; max-width: none; margin: 0; }
  .btn-new span { display: none; }
  .layout { display: flex; flex-direction: column; }
  .main { order: 1; overflow: visible; padding: 14px 16px; }
  .sidebar { order: 2; overflow: visible; border: 0; padding: 0 16px 24px; }
  .sched-wrap { flex: none; height: 72vh; }
  .date-title h1 { font-size: 17px; }
  .toolbar-actions .btn span { display: none; }
  .row.two, .row.three, .settings-grid { grid-template-columns: 1fr; }
  .status-grid { grid-template-columns: repeat(3, 1fr); }
  .modal-backdrop { padding: 0; align-items: flex-end; }
  .modal { max-height: 94vh; border-radius: 18px 18px 0 0; }
  .detail-head { border-radius: 18px 18px 0 0; }
  .modal-body, .modal-head, .modal-foot, .detail-head { padding-inline: 16px; }
  .table th:nth-child(4), .table td:nth-child(4) { display: none; }
}

/* ---------- printing ---------- */

.print-only { display: none; }
@media print {
  body { display: block; height: auto; overflow: visible; background: #fff; }
  body > *:not(#print-area) { display: none !important; }
  #print-area { display: block; font-size: 12px; }
  #print-area h1 { font-size: 18px; margin: 0; }
  #print-area h2 { font-size: 14px; margin: 4px 0 12px; font-weight: 600; }
  #print-area table { width: 100%; border-collapse: collapse; }
  #print-area th, #print-area td { border: 1px solid #999; padding: 5px 7px; text-align: right; }
  #print-area th { background: #eee; }
  .print-foot { margin-top: 10px; }
}
