/* Warddesk — plain CSS, mobile friendly */
:root {
  --primary: #1f5fa8;
  --primary-dark: #174a83;
  --danger: #c0392b;
  --danger-dark: #a03024;
  --bg: #f4f6f9;
  --surface: #ffffff;
  --border: #dde3ea;
  --text: #1d2733;
  --muted: #5d6b7a;
  --success-bg: #e6f4ea; --success-text: #1e6b34;
  --warning-bg: #fff4e0; --warning-text: #8a5a00;
  --error-bg: #fdecea;   --error-text: #a12a1f;
  --info-bg: #e8f1fb;    --info-text: #1f4f86;
  --radius: 8px;
  --sidebar-width: 220px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
}
a { color: var(--primary); }
h1 { font-size: 22px; margin: 0 0 16px; }
h2 { font-size: 17px; margin: 28px 0 12px; }
.muted { color: var(--muted); }
.center-screen { display: flex; min-height: 100vh; align-items: center; justify-content: center; color: var(--muted); padding: 16px; text-align: center; }

/* Layout */
.layout {
  min-height: 100vh;
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  grid-template-rows: 56px 1fr;
  grid-template-areas: "top top" "side main";
}
.topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  background: var(--primary);
  color: #fff;
}
.brand { color: #fff; font-weight: 700; font-size: 18px; text-decoration: none; }
.topbar-user { margin-left: auto; display: flex; align-items: center; gap: 10px; font-size: 14px; }
.topbar .badge { background: rgba(255, 255, 255, 0.18); color: #fff; }
.menu-toggle {
  display: none;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.5);
  color: #fff;
  border-radius: 6px;
  padding: 2px 10px;
  font-size: 18px;
  cursor: pointer;
}
.sidebar { grid-area: side; background: var(--surface); border-right: 1px solid var(--border); padding: 12px 0; }
.sidebar a {
  display: block;
  padding: 10px 20px;
  color: var(--text);
  text-decoration: none;
  border-left: 3px solid transparent;
}
.sidebar a:hover { background: var(--bg); }
.sidebar a.active { border-left-color: var(--primary); background: var(--info-bg); color: var(--primary); font-weight: 600; }
.content { grid-area: main; padding: 24px; min-width: 0; }
.view-header { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.view-header h1 { margin: 0; }
.survey-toolbar { align-items: center; }
.import-panel { margin: 0 0 16px; padding: 18px; background: #fff; border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 4px 16px rgba(25, 48, 76, .04); }
.import-panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.import-panel-heading h2 { margin: 0; }
.import-panel-heading p { margin: 4px 0 0; }
.import-map { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px 14px; margin: 12px 0 16px; }
.import-map-field { font-size: 13px; }
.import-map-field select { font-size: 14px; }
.import-summary { white-space: pre-wrap; overflow-wrap: anywhere; margin-top: 12px; padding: 10px 12px; border-radius: 6px; }
.import-summary:empty { display: none; }
.import-summary.error { color: var(--error-text); background: var(--error-bg); }
.import-summary.success { color: var(--success-text); background: var(--success-bg); }

/* Cards */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; }
.card-label { color: var(--muted); font-size: 13px; }
.card-value { font-size: 28px; font-weight: 700; margin-top: 4px; }

/* Tables */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.table { width: 100%; border-collapse: collapse; min-width: 640px; }
.table th, .table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { background: #f8fafc; font-size: 13px; color: var(--muted); font-weight: 600; white-space: nowrap; }
.table tbody tr:last-child td { border-bottom: 0; }
.table td.empty { text-align: center; color: var(--muted); padding: 24px; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.pager { display: flex; align-items: center; justify-content: center; gap: 14px; margin-top: 14px; }

/* Buttons */
.btn {
  display: inline-block;
  padding: 8px 16px;
  border: 1px solid var(--primary);
  border-radius: 6px;
  background: var(--primary);
  color: #fff;
  font: inherit;
  font-weight: 600;
  line-height: 1.4;
  text-decoration: none;
  cursor: pointer;
}
.btn:hover { background: var(--primary-dark); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-light { background: var(--surface); color: var(--primary); border-color: var(--border); }
.btn-light:hover { background: var(--bg); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-dark); }
.btn-sm { padding: 4px 10px; font-size: 13px; }
.btn-block { width: 100%; margin-top: 18px; }

/* Badges and messages */
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--bg); color: var(--muted); }
.badge-success { background: var(--success-bg); color: var(--success-text); }
.badge-warning { background: var(--warning-bg); color: var(--warning-text); }
.badge-muted { background: #eceff3; color: var(--muted); }
.flash { padding: 12px 14px; border-radius: var(--radius); margin-bottom: 16px; border: 1px solid transparent; }
.flash-success { background: var(--success-bg); color: var(--success-text); border-color: #c7e6d0; }
.flash-error { background: var(--error-bg); color: var(--error-text); border-color: #f5c6c1; }
.flash-info { background: var(--info-bg); color: var(--info-text); border-color: #c9dcf3; }

/* Forms */
.form { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; max-width: 820px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px 18px; margin-bottom: 14px; }
label { display: block; font-size: 14px; font-weight: 600; }
input, select, textarea {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
  font-weight: 400;
  background: #fff;
  color: var(--text);
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 0; border-color: var(--primary); }
input[readonly] { background: var(--bg); color: var(--muted); }
.checkbox-label { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.checkbox-label input { width: auto; margin: 0; }
.hint { display: block; font-weight: 400; color: var(--muted); font-size: 13px; margin-top: 4px; }
.form-actions { display: flex; gap: 10px; margin-top: 18px; flex-wrap: wrap; }

/* Filters */
.filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
  align-items: end;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}
.filters label { font-weight: 400; font-size: 13px; color: var(--muted); }
.filter-buttons { display: flex; gap: 8px; }

/* Person details */
.person-details-header { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-bottom: 20px; }
.person-details-heading { display: flex; align-items: center; gap: 18px; min-width: 0; }
.person-details-heading h1 { margin: 0; color: #172b43; font-size: 27px; letter-spacing: -.025em; }
.detail-record-meta { margin: 4px 0 0; color: var(--muted); font-size: 14px; }
.detail-back { flex: 0 0 auto; }
.detail-actions { flex: 0 0 auto; }
.person-profile-card { display: grid; grid-template-columns: 190px minmax(0, 1fr); align-items: center; gap: 28px; padding: 24px; margin-bottom: 18px; background: #fff; border: 1px solid #e5eaf0; border-radius: 14px; box-shadow: 0 5px 20px rgba(25, 48, 76, .055); }
.profile-photo-link, .profile-photo { display: block; width: 190px; height: 190px; border-radius: 12px; }
.profile-photo { object-fit: contain; background: #f2f6fa; border: 1px solid #e5ebf2; }
.profile-copy { min-width: 0; }
.profile-eyebrow { margin: 0 0 5px; color: var(--primary); font-size: 12px; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; }
.profile-copy h2 { margin: 0; color: #172b43; font-size: 28px; line-height: 1.25; overflow-wrap: anywhere; }
.profile-serial { margin: 7px 0 14px; color: var(--muted); font-size: 14px; }
.profile-badges { display: flex; flex-wrap: wrap; gap: 8px; }
.person-status-pill, .party-pill { display: inline-flex; align-items: center; min-height: 28px; padding: 4px 11px; border-radius: 999px; font-size: 13px; font-weight: 700; }
.person-status-pill.is-alive { color: #17643a; background: #e8f6ed; }
.person-status-pill.is-deceased { color: #923e39; background: #fbeeed; }
.person-status-pill.is-unknown, .party-pill { color: #315a83; background: #edf4fb; }
.person-detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; gap: 16px; }
.detail-card { min-width: 0; padding: 20px 22px; background: #fff; border: 1px solid #e5eaf0; border-radius: 12px; box-shadow: 0 3px 14px rgba(25, 48, 76, .04); }
.detail-card-record { grid-column: 1 / -1; }
.detail-card-heading { display: flex; align-items: center; gap: 12px; padding-bottom: 15px; margin-bottom: 15px; border-bottom: 1px solid #edf0f4; }
.detail-card-icon { display: grid; flex: 0 0 34px; width: 34px; height: 34px; place-items: center; color: var(--primary); background: #edf4fb; border-radius: 10px; font-size: 11px; font-weight: 800; }
.detail-card-heading h2 { margin: 0; color: #203a56; font-size: 16px; }
.detail-card-heading p { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.detail-fields { display: grid; grid-template-columns: minmax(115px, .75fr) minmax(0, 1.25fr); gap: 11px 16px; margin: 0; }
.detail-fields dt { color: #68798b; font-size: 13px; font-weight: 600; }
.detail-fields dd { min-width: 0; margin: 0; color: #23374b; font-size: 14px; font-weight: 500; white-space: pre-wrap; overflow-wrap: anywhere; }
.detail-fields dd.is-empty { color: #98a3af; font-weight: 400; font-style: italic; }
.photo-thumb-link { display: inline-flex; align-items: center; }
.photo-thumb { display: block; width: 52px; height: 52px; object-fit: cover; border: 1px solid var(--border); border-radius: 6px; }

/* Login */
.login-body { display: flex; min-height: 100vh; align-items: center; justify-content: center; padding: 16px; }
.login-wrap { width: 100%; max-width: 380px; }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 28px; box-shadow: 0 4px 20px rgba(29, 39, 51, 0.08); }
.login-card label { margin-top: 14px; }
.login-title { color: var(--primary); margin-bottom: 4px; }

/* Mobile */
@media (max-width: 800px) {
  .survey-toolbar { width: 100%; }
  .survey-toolbar > * { flex: 1 1 auto; text-align: center; }
  .layout { grid-template-columns: 1fr; grid-template-areas: "top" "main"; }
  .menu-toggle { display: inline-block; }
  .sidebar {
    display: none;
    position: fixed;
    top: 56px; left: 0; right: 0;
    z-index: 10;
    border-right: 0;
    border-bottom: 1px solid var(--border);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.08);
  }
  .menu-open .sidebar { display: block; }
  .content { padding: 16px; }
  #user-name { display: none; }
  .person-details-header { align-items: flex-start; flex-direction: column; }
  .person-details-heading { align-items: flex-start; flex-wrap: wrap; }
  .person-detail-grid { grid-template-columns: 1fr; }
  .detail-card-record { grid-column: auto; }
}

@media (max-width: 520px) {
  .person-details-heading { gap: 12px; }
  .person-details-heading h1 { font-size: 23px; }
  .person-profile-card { grid-template-columns: 1fr; justify-items: center; gap: 18px; padding: 18px; text-align: center; }
  .profile-photo-link, .profile-photo { width: min(100%, 220px); height: 220px; }
  .profile-badges { justify-content: center; }
  .detail-card { padding: 17px; }
  .detail-fields { grid-template-columns: 1fr; gap: 3px; }
  .detail-fields dd { margin-bottom: 9px; }
}

@media print {
  @page { margin: 14mm; }
  body * { visibility: hidden !important; }
  #view-survey-detail, #view-survey-detail * { visibility: visible !important; }
  #view-survey-detail { display: block !important; position: absolute; inset: 0; width: 100%; padding: 0; background: #fff; }
  .detail-actions, .detail-back { display: none !important; }
  .person-profile-card, .detail-card { box-shadow: none; border-color: #ccd4de; break-inside: avoid; }
  .person-detail-grid { gap: 10px; }
  .profile-photo-link, .profile-photo { max-width: 150px; max-height: 150px; }
}
