/* Field App styles.
   Tokens follow Conversational Care's staff palette (app_new_design.css):
   brand blue #0369a1 on slate surfaces, DM Sans when installed.
   Touch-first: every control is at least 44px tall for tablet use. */

:root {
  --brand-primary: #0369a1;    /* sky-700, 5.7:1 on white */
  --brand-secondary: #075985;  /* sky-800, hover/pressed */
  --brand-light: #f0f9ff;      /* sky-50 */
  --surface-background: #f8fafc;
  --card-background: #ffffff;
  --text-primary: #1e293b;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --border-color: #e2e8f0;
  --danger: #b91c1c;
  --success: #047857;
  --radius: 12px;
  --tap: 44px;
  --sidebar-w: 232px;
  font-family: "DM Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--surface-background);
  color: var(--text-primary);
  font-size: 16px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--brand-primary); text-decoration: none; }
a:hover { color: var(--brand-secondary); }
h1 { font-size: 1.6rem; margin: 0 0 .25rem; }
h2 { font-size: 1.15rem; margin: 0 0 .75rem; }
.muted { color: var(--text-secondary); }
.small { font-size: .875rem; }

/* ── Layout: sidebar on wide screens, top bar + bottom tabs on narrow ───── */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--card-background);
  border-right: 1px solid var(--border-color);
  padding: 20px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  font-weight: 700; font-size: 1.1rem; color: var(--text-primary);
  padding: 0 10px 18px;
}
.brand img { width: 32px; height: 32px; border-radius: 8px; }
.nav-link {
  display: flex; align-items: center; gap: 10px;
  min-height: var(--tap); padding: 0 12px; border-radius: 10px;
  color: var(--text-secondary); font-weight: 500;
}
.nav-link svg { width: 20px; height: 20px; flex: none; }
.nav-link:hover { background: var(--surface-background); color: var(--text-primary); }
.nav-link.active { background: var(--brand-light); color: var(--brand-primary); }
.sidebar .spacer { flex: 1; }
.sidebar form { margin: 0; }
button.nav-link { width: 100%; border: 0; background: none; cursor: pointer; font: inherit; }
.sidebar .user { padding: 8px 12px; font-size: .875rem; color: var(--text-secondary); }

main { flex: 1; min-width: 0; padding: 32px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }

@media (max-width: 820px) {
  .layout { flex-direction: column; }
  .sidebar {
    position: fixed; bottom: 0; top: auto; left: 0; right: 0; z-index: 10;
    width: auto; height: auto; flex-direction: row; justify-content: space-around;
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    border-right: 0; border-top: 1px solid var(--border-color);
  }
  .sidebar .brand, .sidebar .spacer, .sidebar .user, .sidebar .nav-secondary { display: none; }
  .nav-link, button.nav-link { flex-direction: column; justify-content: center; gap: 2px; font-size: .75rem; padding: 6px 10px; }
  main { padding: 20px 16px 96px; }
}

/* ── Cards, lists, tables ─────────────────────────────────────────────── */
.card {
  background: var(--card-background);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.stat { font-size: 2rem; font-weight: 700; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { border-top: 1px solid var(--border-color); }
.list li:first-child { border-top: 0; }
.list a, .list .row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 56px; padding: 8px 4px; color: var(--text-primary);
}
.list a:hover { background: var(--surface-background); }
.badge {
  display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .75rem; font-weight: 600;
  background: var(--brand-light); color: var(--brand-primary);
}
.badge.grey { background: #f1f5f9; color: var(--text-secondary); }
dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: 8px 20px; margin: 0; }
dl.facts dt { color: var(--text-secondary); }
dl.facts dd { margin: 0; white-space: pre-line; }

/* ── Buttons & forms ──────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 0 18px; border-radius: 10px;
  font: inherit; font-weight: 600; cursor: pointer;
  border: 1px solid var(--border-color); background: var(--card-background); color: var(--text-primary);
}
.btn:hover { background: var(--surface-background); color: var(--text-primary); }
.btn.primary { background: var(--brand-primary); border-color: var(--brand-primary); color: #fff; }
.btn.primary:hover { background: var(--brand-secondary); }
.btn.icon { padding: 0; width: var(--tap); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.field { margin-bottom: 18px; }
.field > label, .field > .label { display: block; font-weight: 600; margin-bottom: 6px; }
.prompt p { margin: 0 0 .4em; }
.prompt p:last-of-type { margin-bottom: 0; display: inline; }
.prompt .req { color: var(--danger); margin-left: 4px; }
.field .help { font-size: .85rem; color: var(--text-secondary); margin-top: 4px; }
.errorlist { color: var(--danger); margin: 4px 0 0; padding-left: 18px; font-size: .9rem; }
input[type=text], input[type=number], input[type=date], input[type=tel], input[type=search],
input[type=password], select, textarea {
  width: 100%; min-height: var(--tap); padding: 10px 12px;
  font: inherit; color: inherit; background: #fff;
  border: 1px solid #cbd5e1; border-radius: 10px;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-primary); outline-offset: 1px; border-color: transparent; }
input[type=checkbox], input[type=radio] { width: 22px; height: 22px; accent-color: var(--brand-primary); vertical-align: middle; }
.check { display: flex; align-items: center; gap: 10px; min-height: var(--tap); }

/* Radio/checkbox groups rendered by Django as <div><div><label>… */
.options > div { display: grid; gap: 8px; }
.options > div label {
  display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 0 14px;
  border: 1px solid var(--border-color); border-radius: 10px; background: #fff; cursor: pointer; font-weight: 500;
}
.options > div label:has(input:checked) { border-color: var(--brand-primary); background: var(--brand-light); }

/* ── Questionnaire editor ─────────────────────────────────────────────── */
.question-card { position: relative; }
.question-card.is-deleted { opacity: .45; }
.question-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.question-number {
  display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 999px;
  background: var(--brand-light); color: var(--brand-primary); font-weight: 700;
}
.question-head .spacer { flex: 1; }
.two-col { display: grid; gap: 0 16px; grid-template-columns: 1fr 1fr; }
@media (max-width: 600px) { .two-col { grid-template-columns: 1fr; } }

.messages { list-style: none; padding: 0; margin: 0 0 16px; }
.messages li { padding: 12px 16px; border-radius: 10px; background: var(--brand-light); color: var(--brand-secondary); }

/* ── Login ─────────────────────────────────────────────────────────────── */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth .card { width: 100%; max-width: 380px; }

/* ── Settings, profile, consent ───────────────────────────────────────── */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border-color); margin-bottom: 20px; overflow-x: auto; }
.tabs a {
  display: inline-flex; align-items: center; min-height: var(--tap); padding: 0 16px;
  color: var(--text-secondary); font-weight: 600; border-bottom: 2px solid transparent; white-space: nowrap;
}
.tabs a.active { color: var(--brand-primary); border-bottom-color: var(--brand-primary); }
h3 { font-size: 1rem; margin: 22px 0 6px; display: flex; align-items: center; gap: 8px; }
.step {
  display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 999px;
  background: var(--brand-light); color: var(--brand-primary); font-size: .75rem; font-weight: 700;
}
.code { position: relative; margin: 8px 0; }
.code pre {
  margin: 0; padding: 14px 16px; padding-right: 90px; overflow-x: auto;
  background: #0f172a; color: #e2e8f0; border-radius: 10px; font-size: .85rem; line-height: 1.6;
}
.code .copy-btn { position: absolute; top: 8px; right: 8px; min-height: 32px; padding: 0 10px; font-size: .8rem; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .9em; overflow-wrap: anywhere; }
.copy-row { display: flex; gap: 8px; }
.copy-row input { flex: 1; min-width: 0; }
.copy-row input[readonly] { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85rem; }
.secret { border-color: #fcd34d; background: #fffbeb; }
.app-row { padding: 14px 0; }
.app-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.app-head form { margin: 0; }
.consent { max-width: 480px; }
.consent h1 { font-size: 1.3rem; margin-bottom: .5rem; }
.perm-list { padding-left: 20px; }
.perm-list li { margin: 6px 0; }
@media (max-width: 600px) { dl.facts { grid-template-columns: 1fr; gap: 2px; } dl.facts dd { margin-bottom: 10px; } }
