:root {
  --navy: #0A1D3A;
  --ink: #14213D;
  --copper: #C79356;
  --gilt: #D3A064;
  --cream: #F1ECDF;
  --offwhite: #F4F1EA;
  --slate: #46536B;
  --mist: #9FB0C4;
  --white: #FFFFFF;
  --danger-bg: #F8D7DA;
  --danger-text: #7A1F27;
  --ok-bg: #DCEEE0;
  --ok-text: #1F6B3A;
  --warn-bg: #FBEAD1;
  --warn-text: #7A4E14;

  --font-display: 'Space Grotesk', sans-serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--offwhite);
  color: var(--ink);
  font-family: var(--font-body);
}

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

:focus-visible {
  outline: 2px solid var(--copper);
  outline-offset: 2px;
}

.app {
  display: flex;
  min-height: 100vh;
}

/* ---------- Sidebar ---------- */

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--navy);
  color: var(--white);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  padding: 26px 20px 22px;
}

.brand-logo {
  width: 100%;
  max-width: 190px;
  height: auto;
  display: block;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px 12px;
  margin-top: 8px;
}

.nav-item {
  display: flex;
  align-items: center;
  text-align: left;
  background: transparent;
  border: none;
  color: var(--mist);
  padding: 11px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 500;
  transition: background 0.12s ease, color 0.12s ease;
}
.nav-item:hover { background: rgba(255,255,255,0.06); color: var(--white); }
.nav-item.active {
  background: rgba(199,147,86,0.16);
  color: var(--gilt);
  font-weight: 600;
}

.sidebar-footer {
  margin-top: auto;
  padding: 16px 20px 20px;
  position: relative;
}

.contour {
  height: 90px;
  margin-bottom: 10px;
  opacity: 0.5;
  background-image: url("/assets/state-outline.png");
  background-repeat: no-repeat;
  background-position: left center;
  background-size: contain;
}

.whoami {
  font-size: 11px;
  color: var(--mist);
  word-break: break-all;
}

/* ---------- Main ---------- */

.main {
  flex: 1;
  padding: 28px 36px 60px;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 22px;
}

.topbar h1 {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 600;
  margin: 0;
  color: var(--ink);
}

.btn {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 13.5px;
  padding: 9px 16px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  transition: filter 0.12s ease;
}
.btn:hover { filter: brightness(0.94); }
.btn-primary { background: var(--navy); color: var(--white); }
.btn-secondary { background: transparent; color: var(--ink); border: 1px solid var(--mist); }
.btn-danger-text { background: transparent; color: var(--danger-text); }

.status-banner {
  padding: 10px 14px;
  border-radius: 6px;
  margin-bottom: 16px;
  font-size: 13.5px;
  background: var(--danger-bg);
  color: var(--danger-text);
}
.status-banner.ok { background: var(--ok-bg); color: var(--ok-text); }

/* ---------- Dashboard cards ---------- */

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}

.card {
  background: var(--white);
  border: 1px solid #E4DECD;
  border-radius: 10px;
  padding: 16px 18px;
}
.card-group {
  grid-column: 1 / -1;
  margin-top: 6px;
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--copper);
  padding-bottom: 2px;
  border-bottom: 1px solid #E4DECD;
}
.card-label {
  font-size: 12.5px;
  color: var(--slate);
  margin-bottom: 6px;
}
.card-value {
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 700;
  color: var(--ink);
}
.card-value.alert { color: var(--danger-text); }

/* ---------- Tables ---------- */

.table-wrap {
  background: var(--white);
  border: 1px solid #E4DECD;
  border-radius: 10px;
  overflow-x: auto;
}

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }

thead th {
  text-align: left;
  background: var(--navy);
  color: var(--white);
  font-weight: 600;
  font-size: 11.5px;
  letter-spacing: 0.02em;
  padding: 10px 12px;
  white-space: normal;
  line-height: 1.25;
  max-width: 130px;
}

tbody td {
  padding: 9px 12px;
  border-bottom: 1px solid #EFE9DA;
  white-space: nowrap;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #FAF7EF; }
tbody tr.overdue { background: var(--danger-bg); }
tbody tr.overdue:hover { background: #f3c7cb; }

.pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
}
.pill-neutral { background: #E9E4D6; color: var(--slate); }
.pill-progress { background: var(--warn-bg); color: var(--warn-text); }
.pill-good { background: var(--ok-bg); color: var(--ok-text); }
.pill-dead { background: #E4DECD; color: var(--slate); text-decoration: line-through; }

.row-actions {
  white-space: nowrap;
}
.row-actions button {
  background: none;
  border: none;
  color: var(--navy);
  font-weight: 600;
  cursor: pointer;
  font-size: 12.5px;
  padding: 4px 8px;
}
.row-actions button:hover { color: var(--copper); }
.row-actions button + button {
  border-left: 1px solid #E4DECD;
}

.empty-row td {
  text-align: center;
  color: var(--slate);
  padding: 30px;
}

/* ---------- Record page ---------- */

.record-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}
.record-actions { display: flex; gap: 10px; }

.record-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.record-panel {
  background: var(--white);
  border: 1px solid #E4DECD;
  border-radius: 10px;
  padding: 20px 22px;
}
.record-panel h3 {
  font-family: var(--font-display);
  font-size: 15px;
  margin: 0 0 14px;
  color: var(--ink);
}

.record-panel .form-actions {
  justify-content: flex-start;
  margin-top: 8px;
}

.record-journal {
  display: flex;
  flex-direction: column;
  max-height: 640px;
}

.journal-entries {
  overflow-y: auto;
  flex: 1;
  min-height: 120px;
  max-height: 440px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 14px;
  padding-right: 2px;
}

.journal-empty {
  color: var(--slate);
  font-size: 13px;
  padding: 12px 0;
}

.journal-entry {
  background: var(--offwhite);
  border: 1px solid #EFE9DA;
  border-radius: 8px;
  padding: 10px 12px;
}
.journal-entry-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 11px;
  color: var(--slate);
  margin-bottom: 5px;
}
.journal-entry-text {
  font-size: 13.5px;
  color: var(--ink);
  white-space: pre-wrap;
  line-height: 1.4;
}

.journal-add textarea {
  width: 100%;
  border: 1px solid #D9D2BE;
  border-radius: 6px;
  padding: 9px 10px;
  font-size: 13.5px;
  background: var(--offwhite);
  color: var(--ink);
  resize: vertical;
  margin-bottom: 8px;
}

@media (max-width: 900px) {
  .record-layout { grid-template-columns: 1fr; }
  .record-journal { max-height: none; }
  .journal-entries { max-height: 320px; }
}

/* ---------- Table controls (search / filter) ---------- */

.table-controls {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.table-controls input[type="search"] {
  flex: 1;
  min-width: 180px;
  border: 1px solid #D9D2BE;
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 13.5px;
  background: var(--white);
  color: var(--ink);
}
.table-controls select {
  border: 1px solid #D9D2BE;
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 13.5px;
  background: var(--white);
  color: var(--ink);
}

/* ---------- Dashboard: Today's Follow-Ups ---------- */

.followups-panel {
  margin-bottom: 20px;
}
.followups-panel:empty { display: none; }

.followups-card {
  background: var(--white);
  border: 1px solid #E4DECD;
  border-left: 3px solid var(--danger-text);
  border-radius: 10px;
  padding: 16px 18px;
}
.followups-card h3 {
  font-family: var(--font-display);
  font-size: 14px;
  margin: 0 0 10px;
  color: var(--ink);
}
.followup-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px solid #EFE9DA;
  cursor: pointer;
}
.followup-item:last-child { border-bottom: none; }
.followup-item:hover .followup-name { color: var(--copper); }
.followup-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.followup-name { font-weight: 600; font-size: 13.5px; color: var(--ink); }
.followup-business { font-size: 12px; color: var(--slate); }
.followup-due {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--danger-text);
  white-space: nowrap;
}
.followup-due.due-today { color: var(--warn-text); }

/* ---------- Modal ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10,29,58,0.45);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px;
  overflow-y: auto;
  z-index: 50;
}
.modal-backdrop[hidden] {
  display: none;
}

.modal {
  background: var(--white);
  border-radius: 10px;
  width: 100%;
  max-width: 560px;
  padding: 24px 26px 26px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.modal-header h2 {
  font-family: var(--font-display);
  font-size: 18px;
  margin: 0;
}
.modal-close {
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--slate);
  line-height: 1;
}

.field { margin-bottom: 14px; display: flex; flex-direction: column; gap: 5px; }
.field label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--slate);
}
.field input, .field select, .field textarea {
  border: 1px solid #D9D2BE;
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 13.5px;
  color: var(--ink);
  background: var(--offwhite);
}
.field textarea { resize: vertical; min-height: 60px; }
.field.readonly input {
  background: #ECE8DC;
  color: var(--slate);
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

@media (max-width: 760px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: relative; }
  .nav { flex-direction: row; overflow-x: auto; }
  .contour, .whoami { display: none; }
  .main { padding: 20px; }
}
