:root {
  --brand: #038387;
  --brand-dark: #026569;
  --brand-light: #e6f4f4;
  --navy: #0b1f2a;
  --gray-50: #f7f9fa;
  --gray-100: #eef1f3;
  --gray-200: #dfe4e8;
  --gray-400: #9aa6ad;
  --gray-600: #5b6b73;
  --text: #16232a;
  --bg: #ffffff;
  --surface: #ffffff;
  --border: var(--gray-200);
  --success: #1a8754;
  --danger: #c0392b;
  --amber: #b8860b;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(11,31,42,0.08), 0 1px 2px rgba(11,31,42,0.06);
  --font: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  font-size: 15px;
  line-height: 1.5;
}
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 .75em; }
a { color: var(--brand); }
.muted { color: var(--gray-600); }

button, input, select, textarea { font-family: inherit; font-size: inherit; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5em;
  padding: .6em 1.1em; border-radius: 999px; border: 1px solid transparent;
  cursor: pointer; font-weight: 600; transition: background .15s, box-shadow .15s;
}
.btn:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, .nav-link:focus-visible {
  outline: 2px solid var(--brand); outline-offset: 2px;
}
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-secondary { background: var(--gray-100); color: var(--text); }
.btn-secondary:hover { background: var(--gray-200); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-block { width: 100%; }
.link-btn { background: none; border: none; color: var(--brand); cursor: pointer; padding: .2em .4em; font-weight: 600; }
.icon-btn { background: none; border: none; cursor: pointer; padding: .4em; border-radius: 8px; color: var(--text); }
.icon-btn:hover { background: var(--gray-100); }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.25rem; margin-bottom: 1rem; box-shadow: var(--shadow);
}

.input, textarea.input, select.input {
  width: 100%; padding: .65em .8em; border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); color: var(--text); margin-bottom: .25rem;
}
textarea.input { min-height: 5em; resize: vertical; }
.input-sm { padding: .35em .5em; width: auto; }

.form-field { display: flex; flex-direction: column; margin-bottom: .75rem; }
.form-field label { font-weight: 600; margin-bottom: .35rem; font-size: .9rem; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: .5rem 1.25rem; }
.form-actions { display: flex; gap: .75rem; grid-column: 1 / -1; margin-top: .5rem; }
.form-error { color: var(--danger); font-weight: 600; min-height: 1.2em; grid-column: 1/-1; }
.form-warning { background: #fff8e6; border: 1px solid #f0d78c; border-radius: 8px; padding: .75rem 1rem; grid-column: 1/-1; }
.checkbox-row { display: flex; align-items: center; gap: .5em; grid-column: 1/-1; }
.inline-form { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin-top: .5rem; }

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--radius); overflow: hidden; }
.table th, .table td { text-align: left; padding: .7em .9em; border-bottom: 1px solid var(--border); }
.table th { background: var(--gray-50); font-size: .85rem; text-transform: uppercase; letter-spacing: .03em; color: var(--gray-600); }
.row-link { cursor: pointer; }
.row-link:hover { background: var(--brand-light); }

.badge { display: inline-block; padding: .2em .7em; border-radius: 999px; font-size: .78rem; font-weight: 700; background: var(--gray-100); color: var(--gray-600); }
.badge-demo { background: #fdecea; color: #b03a2e; margin-left: .4em; }
.badge-success, .badge-green { background: #e5f6ee; color: var(--success); }
.badge-amber, .badge-orange { background: #fff4e0; color: var(--amber); }
.badge-red { background: #fdecea; color: var(--danger); }
.badge-gray, .badge-muted { background: var(--gray-100); color: var(--gray-600); }
.badge-blue { background: #e8f1fb; color: #2266bb; }
.badge-teal { background: var(--brand-light); color: var(--brand-dark); }
.badge-purple { background: #f1e8fb; color: #7a3fbf; }

.page { padding: 1.5rem; max-width: 1200px; margin: 0 auto; }
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px,1fr)); gap: .75rem; margin-bottom: 1.5rem; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); }
.stat-value { font-size: 1.6rem; font-weight: 700; color: var(--brand-dark); }
.stat-label { color: var(--gray-600); font-size: .85rem; }
.quick-actions { display: flex; flex-wrap: wrap; gap: .6rem; }

.detail-row { display: flex; justify-content: space-between; padding: .4em 0; border-bottom: 1px dashed var(--border); }
.list-item { padding: .5em 0; border-bottom: 1px solid var(--border); }

.toast-container { position: fixed; top: 1rem; right: 1rem; z-index: 999; display: flex; flex-direction: column; gap: .5rem; }
.toast { background: var(--navy); color: #fff; padding: .7em 1.1em; border-radius: 8px; box-shadow: var(--shadow); }
.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
.toast-warning { background: var(--amber); }

.auth-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(160deg, var(--brand-light), var(--bg)); padding: 1rem; }
.auth-card { max-width: 380px; width: 100%; text-align: center; }
.auth-form { text-align: left; margin-top: 1rem; }
.brand-mark-lg { width: 64px; height: 64px; border-radius: 16px; background: var(--brand); color: #fff; font-size: 2rem; font-weight: 800; display: flex; align-items: center; justify-content: center; margin: 0 auto 1rem; }
.footnote { color: var(--gray-400); font-size: .8rem; margin-top: 1.5rem; }

.setup-page { min-height: 100vh; display: flex; align-items: flex-start; justify-content: center; background: var(--gray-50); padding: 2rem 1rem; }
.setup-card { max-width: 720px; width: 100%; }
.setup-progress { display: flex; gap: .35rem; margin-bottom: 1rem; }
.step-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--gray-200); }
.step-dot.active { background: var(--brand); }
.step-dot.done { background: var(--brand-light); border: 1px solid var(--brand); }
.setup-nav { display: flex; justify-content: space-between; margin-top: 1.5rem; }
.setup-list-row { display: flex; gap: .5rem; align-items: center; margin-bottom: .5rem; }
.hours-grid { display: flex; flex-direction: column; gap: .75rem; }
.hours-row { display: flex; gap: 1rem; align-items: flex-start; padding: .5rem 0; border-bottom: 1px solid var(--border); }
.day-toggle { display: flex; align-items: center; gap: .5em; width: 120px; font-weight: 600; }
.period-row { display: flex; align-items: center; gap: .4rem; margin-bottom: .3rem; }
.dup-warning:empty { display: none; }
.dup-item { display: flex; justify-content: space-between; align-items: center; padding: .3em 0; }

.app-shell { display: flex; min-height: 100vh; }
.sidebar { width: 240px; background: var(--navy); color: #fff; display: flex; flex-direction: column; padding: 1rem .75rem; flex-shrink: 0; }
.brand { display: flex; align-items: center; gap: .6rem; padding: .5rem; margin-bottom: 1rem; }
.brand-mark { width: 32px; height: 32px; border-radius: 8px; background: var(--brand); color: #fff; font-weight: 800; display: flex; align-items: center; justify-content: center; }
.brand-name { font-weight: 700; }
.nav-list { display: flex; flex-direction: column; gap: .15rem; flex: 1; }
.nav-link { display: flex; align-items: center; gap: .7rem; padding: .6rem .7rem; border-radius: 8px; color: #cfe3e3; text-decoration: none; font-size: .92rem; }
.nav-link:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav-link.active { background: var(--brand); color: #fff; }
.sidebar-footer { font-size: .78rem; color: #9db3b3; padding: .75rem .5rem 0; border-top: 1px solid rgba(255,255,255,.1); margin-top: .75rem; }

.main-col { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; padding: .75rem 1.25rem; border-bottom: 1px solid var(--border); background: var(--bg); position: sticky; top: 0; z-index: 5; }
.topbar-title { font-weight: 700; }
.topbar-actions { display: flex; align-items: center; gap: .6rem; }
.user-chip { display: flex; align-items: center; gap: .6rem; font-size: .88rem; }
.theme-select { padding: .3em .5em; border-radius: 8px; border: 1px solid var(--border); }
.content { flex: 1; }
.app-footer { text-align: center; padding: 1rem; font-size: .8rem; color: var(--gray-400); border-top: 1px solid var(--border); }
.bottom-nav { display: none; }

.lock-overlay { position: fixed; inset: 0; background: rgba(11,31,42,.85); display: flex; align-items: center; justify-content: center; z-index: 1000; }
.lock-card { max-width: 320px; text-align: center; }

.filters-row { display: flex; gap: .6rem; flex-wrap: wrap; margin-bottom: 1rem; }
.slots-grid { display: flex; flex-wrap: wrap; gap: .4rem; }
.slot-btn { padding: .4em .8em; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); cursor: pointer; }
.slot-btn.selected { background: var(--brand); color: #fff; border-color: var(--brand); }

.queue-columns { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px,1fr)); gap: 1rem; }
.queue-item { display: flex; justify-content: space-between; align-items: center; padding: .5em 0; border-bottom: 1px solid var(--border); gap: .5rem; flex-wrap: wrap; }
.action-btns { display: flex; gap: .4rem; flex-wrap: wrap; }

.patient-header { background: var(--brand-light); }
.alert-badge { display: inline-block; margin-top: .4rem; background: #fdecea; color: var(--danger); padding: .3em .7em; border-radius: 8px; font-weight: 600; }
.consultation-workspace .card h3 { border-bottom: 1px solid var(--border); padding-bottom: .5rem; }

.tab-bar { display: flex; gap: .3rem; margin-bottom: 1rem; flex-wrap: wrap; border-bottom: 1px solid var(--border); }
.tab-btn { padding: .6em 1em; background: none; border: none; cursor: pointer; border-bottom: 2px solid transparent; font-weight: 600; color: var(--gray-600); }
.tab-btn.active { color: var(--brand); border-bottom-color: var(--brand); }

@media print {
  .sidebar, .topbar, .bottom-nav, .app-footer, .nav, .btn, .toast-container { display: none !important; }
  body { background: #fff; }
  .app-shell, .content { display: block; }
}
