:root {
  --bg: #f5f2ec;
  --bg-soft: #faf7f2;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --line: #e7ddd2;
  --primary: #1f2937;
  --primary-soft: #efe8de;
  --accent: #8c6f52;
  --accent-2: #b99b7a;
  --success-bg: #dcfce7;
  --success-text: #166534;
  --danger: #b91c1c;
  --shadow: 0 10px 30px rgba(34, 25, 16, 0.08);
  --radius: 20px;
}
* { box-sizing: border-box; }
body { margin:0; font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif; background:linear-gradient(180deg, var(--bg-soft) 0%, var(--bg) 100%); color:var(--text); }
.topbar { position:sticky; top:0; z-index:20; display:flex; justify-content:space-between; align-items:center; gap:16px; padding:18px 22px; background:rgba(250,247,242,.92); backdrop-filter:blur(12px); border-bottom:1px solid var(--line); }
.brand { font-weight:900; font-size:1.25rem; letter-spacing:.01em; }
.nav { display:flex; gap:10px; flex-wrap:wrap; }
.nav a { color:var(--text); text-decoration:none; font-weight:700; padding:8px 10px; border-radius:12px; } .nav a:hover { background:var(--primary-soft); }
.container { max-width:1180px; margin:0 auto; padding:26px 22px 40px; }
.page-head { display:flex; justify-content:space-between; align-items:end; gap:16px; margin-bottom:20px; }
.page-head h1 { margin:0 0 6px; font-size:2rem; }
.muted { color:var(--muted); margin:0; }
.card { background:var(--card); border:1px solid var(--line); border-radius:var(--radius); box-shadow:var(--shadow); padding:20px; }
.card-list { display:grid; gap:14px; }
.patient-card { display:grid; grid-template-columns:1.2fr 1fr; gap:16px; text-decoration:none; color:inherit; }
.card-meta { display:grid; grid-template-columns:repeat(3, 1fr); gap:12px; }
.label { display:block; font-size:.78rem; color:var(--muted); margin-bottom:6px; text-transform:uppercase; letter-spacing:.04em; }
.button { appearance:none; display:inline-flex; align-items:center; justify-content:center; min-height:44px; padding:0 16px; border-radius:14px; border:1px solid var(--line); background:#fff; color:var(--text); text-decoration:none; font-weight:700; cursor:pointer; }
.button.primary { background:linear-gradient(135deg, var(--primary) 0%, #111827 100%); color:#fff; border-color:var(--primary); }
.button.danger { color:#fff; background:var(--danger); border-color:var(--danger); }
.searchbar { display:flex; gap:12px; margin-bottom:14px; align-items:stretch; }
.searchbar input { flex:1; }
.form { display:grid; gap:14px; }
.form.compact { grid-template-columns:repeat(2,minmax(0,1fr)); }
.form label { display:grid; gap:8px; font-weight:600; }
.form .full { grid-column:1 / -1; }
.split { display:grid; grid-template-columns:1fr 1fr; gap:14px; } .split-phone { grid-template-columns:180px minmax(0,1fr); } .field-compact input { text-align:center; font-weight:800; letter-spacing:.02em; }
input, select, textarea { width:100%; min-height:52px; padding:13px 15px; border:1px solid var(--line); border-radius:16px; background:#fff; font:inherit; } input:focus, select:focus, textarea:focus { outline:none; border-color: var(--accent-2); box-shadow:0 0 0 4px rgba(185,155,122,.16); }
textarea { min-height:120px; resize:vertical; }
.actions { display:flex; justify-content:flex-end; gap:12px; flex-wrap:wrap; }
.grid { display:grid; grid-template-columns:.95fr 1.05fr; gap:18px; margin-bottom:18px; }
.summary-grid, .visit-grid { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:14px; }
.notes { white-space:pre-wrap; font-family:inherit; background:#f9fafb; border:1px solid var(--line); border-radius:14px; padding:14px; }
.visit-list { display:grid; gap:14px; }
.visit-item { border:1px solid var(--line); border-radius:16px; padding:14px; background:#fff; }
.visit-top { display:flex; justify-content:space-between; align-items:center; margin-bottom:12px; }
.pill { background:#eef2ff; color:#3730a3; border-radius:999px; padding:6px 10px; font-size:.85rem; font-weight:700; }
.visit-notes { margin:12px 0 0; color:var(--text); }
.empty-state { text-align:center; padding:30px; }
.dashboard-grid { display:grid; grid-template-columns:repeat(4,1fr); gap:12px; margin-bottom:16px; }
.dash-card { text-decoration:none; color:inherit; }
.view-tabs { display:flex; gap:10px; margin-bottom:14px; flex-wrap:wrap; }
.tab { padding:10px 14px; border-radius:999px; text-decoration:none; color:var(--text); border:1px solid var(--line); background:#fff; font-weight:700; }
.tab.active { background:var(--primary); color:#fff; border-color:var(--primary); }
.photo-row { display:flex; gap:12px; margin-top:12px; flex-wrap:wrap; }
.photo-row img { width:140px; height:140px; object-fit:cover; border-radius:14px; border:1px solid var(--line); }
.login-body { display:grid; place-items:center; min-height:100vh; background:var(--bg); }
.login-wrap { width:min(100%, 420px); padding:20px; }
.login-card h1 { margin:0; }
.error { background:#fee2e2; color:#991b1b; padding:10px 12px; border-radius:12px; }
@media (max-width: 900px) {
  .grid, .patient-card, .card-meta, .summary-grid, .visit-grid, .form.compact, .split, .dashboard-grid { grid-template-columns:1fr; }
  .page-head, .searchbar, .topbar { align-items:stretch; flex-direction:column; }
  .actions { justify-content:stretch; }
  .button { width:100%; }
}

.success { background:#dcfce7; color:#166534; padding:10px 12px; border-radius:12px; }
.quick-actions {
  display:flex;
  gap:12px;
  flex-wrap:wrap;
  margin-bottom:18px;
}
.sticky-actions {
  position: sticky;
  top: 78px;
  z-index: 8;
}
.dashboard-grid-large {
  grid-template-columns: repeat(4, 1fr);
}
.tall-card {
  min-height: 120px;
  display:flex;
  flex-direction:column;
  justify-content:center;
}
.tall-card strong {
  font-size: 1.6rem;
}
.table-wrap {
  overflow:auto;
}
.report-table {
  width:100%;
  border-collapse: collapse;
}
.report-table th,
.report-table td {
  padding: 12px 10px;
  border-bottom:1px solid var(--line);
  text-align:left;
  vertical-align: top;
}
.report-table th {
  position: sticky;
  top: 0;
  background: #fff;
}
@media (max-width: 900px) {
  .sticky-actions {
    top: 72px;
  }
  .quick-actions {
    display:grid;
    grid-template-columns:1fr 1fr;
  }
  .quick-actions .button {
    width:100%;
  }
}
@media (max-width: 640px) {
  .container {
    padding: 14px;
  }
  .card {
    padding: 16px;
    border-radius: 16px;
  }
  .page-head h1 {
    font-size: 1.6rem;
  }
  .quick-actions {
    grid-template-columns: 1fr;
  }
  .dash-card {
    min-height: 108px;
  }
  .report-table th, .report-table td {
    white-space: nowrap;
  }
}

.button.soft { background:#eef2ff; color:#111827; border-color:#dbe4ff; }
.stats-kpi-grid .tall-card strong { font-size:2.25rem; }
.kpi-row { margin-top:16px; }
.kpi-row .mini strong { font-size:1.5rem; }
.dashboard-two-col { display:grid; grid-template-columns:1fr 1fr; gap:18px; margin-bottom:18px; }
.section-head { display:flex; justify-content:space-between; align-items:end; gap:12px; margin-bottom:14px; }
.section-head h2 { margin:0; }
.week-board { display:grid; grid-template-columns:repeat(7, minmax(0,1fr)); gap:10px; }
.week-tile { border:1px solid var(--line); border-radius:16px; padding:14px; background:#fafbff; }
.week-label { font-weight:800; margin-bottom:10px; }
.week-metrics { display:grid; gap:8px; }
.badge { display:inline-flex; align-items:center; justify-content:center; min-height:34px; border-radius:999px; background:#e0f2fe; color:#075985; font-weight:800; padding:0 12px; }
.badge.alt { background:#ecfccb; color:#3f6212; }
.bar-stack { display:grid; gap:14px; }
.bar-row { display:grid; gap:8px; }
.bar-meta { display:flex; justify-content:space-between; gap:12px; font-weight:700; }
.bar-track { height:12px; background:#eef2f7; border-radius:999px; overflow:hidden; }
.bar-fill { height:100%; border-radius:999px; background:linear-gradient(90deg,#111827,#4b5563); }
.bar-fill.alt { background:linear-gradient(90deg,#0f766e,#14b8a6); }
.mini-list { display:grid; gap:10px; }
.mini-list-item { display:flex; align-items:center; justify-content:space-between; gap:12px; padding:12px 14px; border:1px solid var(--line); border-radius:14px; text-decoration:none; color:inherit; background:#fff; }
.active-pick { border-color:#111827; box-shadow:0 0 0 2px rgba(17,24,39,.08); }
.quick-add-grid { align-items:start; }
.selected-patient-banner { display:flex; justify-content:space-between; align-items:center; gap:10px; margin-bottom:16px; padding:12px 14px; border-radius:14px; background:#eef2ff; }
.catalog-grid { display:grid; gap:16px; }
.catalog-block h3 { margin:0 0 10px; }
.tag-wrap { display:flex; flex-wrap:wrap; gap:8px; }
.success { background:#dcfce7; color:#166534; padding:10px 12px; border-radius:12px; }
@media (max-width: 980px) {
  .dashboard-two-col, .grid { grid-template-columns:1fr; }
  .week-board { grid-template-columns:repeat(2,minmax(0,1fr)); }
}
@media (max-width: 720px) {
  .topbar { align-items:flex-start; }
  .nav { width:100%; overflow:auto; white-space:nowrap; padding-bottom:6px; }
  .container { padding:14px; }
  .page-head h1 { font-size:1.6rem; }
  .searchbar { flex-direction:column; }
  .patient-card, .card-meta, .summary-grid, .visit-grid, .form.compact, .split { grid-template-columns:1fr; }
  .sticky-actions { position:sticky; top:72px; z-index:8; }
  .week-board { grid-template-columns:1fr 1fr; }
}


.form-premium {
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #ffffff 0%, #fffdfa 100%);
}
.dashboard-grid .card,
.dash-card {
  min-height: 122px;
}
.dash-card .label {
  color: var(--accent);
  font-weight: 800;
}
.success { background:var(--success-bg); color:var(--success-text); padding:10px 12px; border-radius:12px; }
.kpi-strong { font-size: 2rem; font-weight: 900; letter-spacing: -.02em; }
.quick-actions-sticky {
  position: sticky;
  top: 78px;
  z-index: 8;
}
@media (max-width: 1024px) {
  .container { padding: 20px 16px 30px; }
  .dashboard-grid { grid-template-columns: repeat(2, 1fr); }
  .grid { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .topbar { align-items:flex-start; }
  .nav { gap:8px; }
  .page-head { align-items:start; }
  .page-head h1 { font-size: 1.65rem; }
  .split, .split-phone, .patient-card, .card-meta, .summary-grid, .visit-grid, .form.compact {
    grid-template-columns: 1fr !important;
  }
  .button { width: 100%; }
  .actions { justify-content: stretch; }
  .searchbar { flex-direction: column; }
  .dashboard-grid { grid-template-columns: 1fr; }
  input, select, textarea { min-height: 50px; }
}

.button.danger { background:#b91c1c; color:#fff; border:1px solid #b91c1c; }
.button.danger:hover { background:#991b1b; border-color:#991b1b; }
.button.soft, .button.primary.soft { background:var(--primary-soft); color:var(--text); border-color:var(--line); }
.actions { display:flex; gap:10px; flex-wrap:wrap; align-items:center; }
.section-head { display:flex; justify-content:space-between; align-items:center; gap:12px; margin-bottom:12px; }
.stack-list { display:grid; gap:10px; }
.stack-row { display:flex; justify-content:space-between; align-items:center; padding:12px 14px; border:1px solid var(--line); border-radius:14px; background:#fffdfa; }
.week-board-grid { display:grid; grid-template-columns: repeat(7, 1fr); gap:10px; }
.week-day-card { border:1px solid var(--line); border-radius:16px; padding:12px; background:#fffdfa; }
.week-day-top { display:flex; flex-direction:column; gap:3px; margin-bottom:8px; }
.week-metrics { display:grid; gap:8px; }
.bar-head { display:flex; justify-content:space-between; gap:8px; margin-bottom:6px; font-size:.95rem; }
.bar-track { height:10px; background:#efe7dc; border-radius:999px; overflow:hidden; }
.bar-fill { height:100%; background:linear-gradient(90deg, var(--accent), var(--accent-2)); border-radius:999px; }
.bar-fill.alt { background:linear-gradient(90deg, #2f4858, #5a7184); }
.bars { display:grid; gap:14px; }
.catalog-item-advanced { border:1px solid var(--line); border-radius:14px; padding:10px; display:grid; gap:10px; margin-bottom:10px; background:#fffdfa; }
.catalog-actions { display:grid; gap:8px; }
.catalog-inline-form { display:flex; gap:8px; flex-wrap:wrap; }
.catalog-inline-form input { min-height:44px; flex:1; }
.notes { white-space:pre-wrap; }
@media (max-width: 900px) {
  .week-board-grid { grid-template-columns: repeat(2, 1fr); }
}

/* Alert / error banner */
.alert { padding:12px 16px; border-radius:12px; margin-bottom:16px; font-size:.95rem; }
.alert-error { background:#fef2f2; border:1px solid #fca5a5; color:#991b1b; }
.alert-error a { color:#991b1b; font-weight:600; text-decoration:underline; }

.hidden { display:none !important; }
.phone-check {
  border:1px solid var(--line);
  border-radius:14px;
  padding:12px 14px;
  background:#fffdfa;
  display:grid;
  gap:10px;
}
.phone-check-warning {
  background:#fff7ed;
  border-color:#fdba74;
  color:#9a3412;
}
.phone-check-ok {
  background:#f0fdf4;
  border-color:#86efac;
  color:#166534;
}
.phone-match-list {
  display:grid;
  gap:8px;
}
.phone-match-row {
  display:flex;
  justify-content:space-between;
  gap:12px;
  align-items:center;
  text-decoration:none;
  color:inherit;
  padding:10px 12px;
  border:1px solid rgba(0,0,0,.08);
  border-radius:12px;
  background:#fff;
}
.phone-match-row small {
  display:block;
  margin-top:3px;
  color:var(--muted);
}
.import-result {
  margin-bottom:18px;
}
.import-result h2,
.import-result h3 {
  margin:0 0 12px;
}
.import-stats {
  display:grid;
  grid-template-columns:repeat(3, minmax(0, 1fr));
  gap:12px;
  margin-bottom:16px;
}
.import-stats > div,
.helper-box {
  border:1px solid var(--line);
  border-radius:14px;
  padding:14px;
  background:#fffdfa;
}
.import-stats strong {
  display:block;
  font-size:1.6rem;
}
.plain-list {
  margin:0 0 14px;
  padding-left:20px;
}
@media (max-width: 720px) {
  .phone-match-row,
  .import-stats {
    grid-template-columns:1fr;
  }
  .phone-match-row {
    display:grid;
  }
}

/* Nationality fieldset */
.fieldset-nationality { border:1px solid var(--line); border-radius:14px; padding:14px 16px; margin:0; }
.fieldset-nationality legend { font-weight:600; font-size:.9rem; padding:0 6px; color:var(--muted); }
.radio-group { display:flex; gap:20px; flex-wrap:wrap; align-items:center; }
.radio-label { display:flex; align-items:center; gap:7px; font-size:.95rem; cursor:pointer; font-weight:500; }
.radio-label input[type=radio] { width:17px; height:17px; accent-color:var(--accent); cursor:pointer; }
