/* CRD IT percutánea - estilo limpio, accesible */
#net-banner {
  position: sticky;
  top: 0;
  z-index: 2000;
  background: #fef3c7;
  color: #92400e;
  text-align: center;
  font-weight: 600;
  font-size: 13px;
  padding: 8px 12px;
  border-bottom: 1px solid #fcd34d;
}
#net-banner.offline {
  background: #fee2e2;
  color: #991b1b;
  border-bottom-color: #fca5a5;
}
#pilot-banner {
  background: #fee2e2;
  color: #991b1b;
  text-align: center;
  font-weight: 600;
  font-size: 13px;
  padding: 6px 12px;
  letter-spacing: 0.05em;
  position: sticky;
  top: 0;
  z-index: 1000;
  border-bottom: 1px solid #fca5a5;
}
:root {
  --bg: #f7f9fc;
  --surface: #ffffff;
  --border: #d8dee9;
  --border-strong: #b0bac6;
  --text: #1f2933;
  --muted: #5b6573;
  --primary: #1f6feb;
  --primary-dark: #1656b8;
  --accent: #0e9f6e;
  --danger: #cf2230;
  --warning: #d97706;
  --readonly: #eef2f7;
  --readonly-text: #4b5563;
  --shadow: 0 1px 3px rgba(15,23,42,.06), 0 4px 12px rgba(15,23,42,.04);
  --radius: 8px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14.5px;
  line-height: 1.45;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

button {
  font: inherit;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  border-radius: var(--radius);
  padding: 8px 14px;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
button:hover { background: #f0f4fa; }
button.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
button.primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
button.ghost { background: transparent; border-color: transparent; color: var(--muted); }
button.danger { color: var(--danger); border-color: var(--danger); }
button:disabled { opacity: .5; cursor: not-allowed; }

input, select, textarea {
  font: inherit;
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--primary);
  outline-offset: -1px;
  border-color: var(--primary);
}
input[readonly], input.readonly, .readonly input, .readonly select, .readonly textarea {
  background: var(--readonly);
  color: var(--readonly-text);
  border-color: var(--border);
  cursor: not-allowed;
}

/* ---------- Layout ---------- */
header.appbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 10px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 10;
}
header.appbar .brand { font-weight: 700; font-size: 15px; }
header.appbar .spacer { flex: 1; }
header.appbar .pill {
  background: #eaf2ff; color: var(--primary);
  border-radius: 999px; padding: 4px 10px; font-size: 12px;
}

main { padding: 24px; max-width: 1280px; margin: 0 auto; }

/* ---------- Login ---------- */
.login-wrap {
  min-height: calc(100vh - 60px);
  display: flex; align-items: center; justify-content: center;
  padding: 40px 16px;
}
.login-card {
  background: var(--surface);
  width: 100%; max-width: 420px;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px;
  box-shadow: var(--shadow);
}
.login-card h1 { margin: 0 0 4px; font-size: 18px; }
.login-card p.subtitle { margin: 0 0 20px; color: var(--muted); font-size: 13px; }
.login-card .field { margin-bottom: 14px; }
.login-card label { font-size: 12px; color: var(--muted); display: block; margin-bottom: 4px; }
.login-card .actions { margin-top: 16px; display: flex; justify-content: flex-end; }
.login-card .note { margin-top: 14px; font-size: 12px; color: var(--muted); }

/* ---------- Dashboard ---------- */
.toolbar {
  display: flex; gap: 10px; align-items: center; margin-bottom: 16px;
  flex-wrap: wrap;
}
.toolbar input[type=search] { max-width: 320px; }
table.patients {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  border-collapse: collapse;
  overflow: hidden;
}
table.patients th, table.patients td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}
table.patients th { background: #eef2f7; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
table.patients tr:last-child td { border-bottom: 0; }
table.patients tr:hover td { background: #f5f8fc; }
.status-dot {
  display: inline-block; width: 10px; height: 10px; border-radius: 50%;
  margin-right: 6px; vertical-align: middle;
}
.status-done { background: var(--accent); }
.status-pending { background: var(--border-strong); }
.status-event { background: var(--warning); }

/* ---------- Form ---------- */
.form-shell { display: grid; grid-template-columns: 220px 1fr; gap: 24px; align-items: start; }
.form-nav {
  position: sticky; top: 80px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  font-size: 13px;
  max-height: calc(100vh - 120px);
  overflow-y: auto;
}
.form-nav h3 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; color: var(--muted); letter-spacing: .03em; }
.form-nav a {
  display: block; padding: 4px 8px; border-radius: 4px; color: var(--text);
}
.form-nav a:hover { background: #eef2f7; text-decoration: none; }
.form-nav a.active { background: #eaf2ff; color: var(--primary); font-weight: 600; }

.form-main { min-width: 0; }
.section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 20px;
}
.section h2 {
  margin: 0 0 16px; font-size: 15px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.section h2 .badge {
  background: #eef2f7; color: var(--muted);
  font-size: 11px; padding: 2px 8px; border-radius: 999px;
  font-weight: 500; text-transform: uppercase; letter-spacing: .03em;
}

.fields {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
}
.field { display: flex; flex-direction: column; }
.field label {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 4px;
  display: flex; align-items: center; gap: 6px;
}
.field label .req { color: var(--danger); }
.field label .unit { color: var(--muted); font-size: 11px; }
.field .help { font-size: 11px; color: var(--muted); margin-top: 4px; }
.field.hidden { display: none; }

.field-pair {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
  padding: 10px;
  border-radius: 6px;
  background: #fafbfd;
  border: 1px solid var(--border);
}
.field-pair .col-label {
  grid-column: 1 / -1;
  font-size: 12px;
  color: var(--muted);
}
.field-pair .col-b > label,
.field-pair .col-3m > label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: 4px;
}
.field-pair .col-b input { background: var(--readonly); color: var(--readonly-text); }

.form-footer {
  position: sticky; bottom: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 12px 20px;
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 24px;
  border-radius: var(--radius);
  box-shadow: 0 -4px 12px rgba(15,23,42,.04);
}
.form-footer .status { color: var(--muted); font-size: 12px; }
.form-footer .actions { display: flex; gap: 10px; }

.warn-banner {
  background: #fff7ed; border: 1px solid #fdba74;
  color: #7c2d12; padding: 10px 14px; border-radius: var(--radius);
  font-size: 13px; margin-bottom: 16px;
}

@media (max-width: 800px) {
  .form-shell { grid-template-columns: 1fr; }
  .form-nav { position: static; max-height: none; }
}

/* Locked fields (completing an existing patient: already-filled = read-only) */
.field.locked label, .field-pair.locked .col-label { color: var(--muted); }
.field.locked input, .field.locked select, .field.locked textarea,
.field-pair.locked .col-3m input, .field-pair.locked .col-3m select {
  background: var(--readonly); color: var(--readonly-text);
  cursor: not-allowed; border-color: var(--border);
}
.lock-hint { color: var(--accent) !important; }

/* New-patient NHC modal */
.modal-overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(15,23,42,.45);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.modal-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 22px; width: 100%; max-width: 380px;
}
.modal-card .field { margin-bottom: 14px; }
.modal-card .actions { display: flex; margin-top: 16px; }
