:root {
  --brand: #0b5fa5;
  --brand-dark: #08447a;
  --bg: #f4f6f8;
  --card: #ffffff;
  --border: #d8dee4;
  --text: #1c2833;
  --muted: #6b7785;
  --danger: #c0392b;
  --ok: #1e8449;
}

* { box-sizing: border-box; }

body {
  font-family: Arial, Helvetica, sans-serif;
  background: var(--bg);
  color: var(--text);
  margin: 0;
  padding: 0;
}

.hidden { display: none !important; }

/* ── Login ── */
#loginScreen.screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-box {
  background: var(--card);
  padding: 2rem 2.5rem;
  border-radius: 10px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.08);
  text-align: center;
  width: 320px;
}
.login-box h1 { font-size: 1.2rem; margin-bottom: 0.5rem; }
.login-box input { width: 100%; padding: 0.6rem; margin: 0.75rem 0; border: 1px solid var(--border); border-radius: 6px; }

/* ── System alert banner ── */
.banner-alert {
  background: var(--danger);
  color: white;
  padding: 0.6rem 1.2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.9rem;
  font-weight: 600;
}
.banner-dismiss {
  background: transparent;
  border: none;
  color: white;
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 0.4rem;
  width: auto;
}
.banner-dismiss:hover { background: rgba(255,255,255,0.15); }

/* ── Header ── */
header {
  background: var(--brand);
  color: white;
  padding: 0.9rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
header h1 { font-size: 1.15rem; margin: 0; }
.header-actions { display: flex; gap: 0.5rem; align-items: center; }
.current-user { font-size: 0.82rem; opacity: 0.85; margin-right: 0.4rem; }

#appScreen { padding: 1.25rem 1.5rem 3rem; max-width: 1200px; margin: 0 auto; }

/* ── Buttons ── */
button {
  background: var(--brand);
  color: white;
  border: none;
  padding: 0.55rem 1rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
}
button:hover { background: var(--brand-dark); }
button.secondary { background: #eef1f4; color: var(--text); border: 1px solid var(--border); }
button.secondary:hover { background: #e2e6ea; }
button.danger { background: var(--danger); }
button.danger:hover { background: #96281c; }
button:disabled, button:disabled:hover { opacity: 0.5; cursor: not-allowed; }

/* ── Toolbar ── */
.toolbar {
  display: flex;
  gap: 0.6rem;
  margin: 1rem 0;
  flex-wrap: wrap;
}
.toolbar input[type="text"] { flex: 1; min-width: 220px; padding: 0.55rem; border: 1px solid var(--border); border-radius: 6px; }
.toolbar select { padding: 0.55rem; border-radius: 6px; border: 1px solid var(--border); }

/* ── Tables ── */
table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
th, td {
  padding: 0.55rem 0.7rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 0.88rem;
}
th { background: #eef2f6; color: var(--muted); font-weight: 600; }
tbody tr:hover { background: #f8fafc; cursor: pointer; }
#plotsTable tbody tr:hover { cursor: default; }
#plotsTable input[type="date"] {
  width: 140px;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 0.85rem;
  color: var(--text);
  background: white;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
}
#plotsTable input.plot-notes {
  width: 320px;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 0.85rem;
  color: var(--text);
  background: white;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
}
.balancing-date-cell, .begin-chasing-cell { position: relative; }
.fill-handle {
  position: absolute;
  right: 3px;
  bottom: 3px;
  width: 7px;
  height: 7px;
  background: var(--brand);
  border: 1px solid white;
  cursor: ns-resize;
}
#plotsTable tr.fill-target { background: rgba(11, 95, 165, 0.12); }

/* ── Detail view ── */
.detail-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.9rem;
  background: var(--card);
  padding: 1.1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
}
.detail-grid label { display: flex; flex-direction: column; font-size: 0.82rem; color: var(--muted); gap: 0.3rem; }
.detail-grid label.wide { grid-column: 1 / -1; }
.detail-grid input, .detail-grid select {
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.9rem;
  color: var(--text);
}
.detail-actions { display: flex; align-items: center; gap: 1rem; margin-bottom: 1rem; }
.pct-badge { background: #eaf6ee; color: var(--ok); padding: 0.4rem 0.8rem; border-radius: 20px; font-weight: 600; font-size: 0.85rem; }
.next-chaser-badge { background: #eaf1fb; color: var(--brand-dark); }
.next-chaser-badge:empty { display: none; }

/* ── Customer replies (review queue) ── */
.customer-replies:empty, .customer-replies.hidden { display: none; }
.reply-card { background: var(--card); border: 1px solid var(--border); border-left: 4px solid var(--brand); border-radius: 8px; padding: 0 1rem; margin-bottom: 0.8rem; }
.reply-card[open] { padding-bottom: 1rem; }
.reply-card-summary { padding: 0.8rem 0; font-size: 0.9rem; cursor: pointer; list-style-position: outside; }
.reply-card[open] .reply-card-summary { border-bottom: 1px solid var(--border); margin-bottom: 0.7rem; }
.reply-card-body { padding-top: 0.2rem; }
.reply-card-header { font-size: 0.82rem; color: var(--muted); margin-bottom: 0.5rem; }
.reply-body { background: #f8fafc; border-radius: 6px; padding: 0.7rem; font-size: 0.85rem; white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word; margin-bottom: 0.7rem; max-height: 160px; overflow-y: auto; overflow-x: hidden; }
.suggestion-row { display: flex; align-items: center; justify-content: space-between; gap: 0.6rem; padding: 0.5rem 0; border-top: 1px solid var(--border); flex-wrap: wrap; transition: background-color 0.3s; }
.suggestion-row:first-of-type { border-top: none; }
.suggestion-row-highlight { background-color: #fff3cd; }
.suggestion-text { font-size: 0.85rem; flex: 1; min-width: 220px; }
.suggestion-actions { display: flex; gap: 0.4rem; }
.suggestion-actions button { width: auto; padding: 0.35rem 0.6rem; font-size: 0.8rem; }
.confidence-low { color: var(--danger); font-weight: 600; }
.reply-card-footer { display: flex; justify-content: flex-end; margin-top: 0.6rem; }
.reply-card-footer button { width: auto; }
.project-asterisk { color: var(--danger); font-weight: 700; margin-left: 0.3rem; cursor: help; }
.plot-pending-flag { margin-right: 0.35rem; cursor: pointer; }
.save-status { font-size: 0.85rem; color: var(--muted); min-width: 110px; }
.save-status.saving { color: var(--brand); }
.save-status.error { color: var(--danger); cursor: pointer; text-decoration: underline; }

.drop-zone {
  border: 2px dashed var(--border);
  border-radius: 8px;
  padding: 1.4rem;
  text-align: center;
  color: var(--muted);
  margin-bottom: 1rem;
  cursor: pointer;
  background: var(--card);
}
.drop-zone.dragover { border-color: var(--brand); background: #eaf3fb; color: var(--brand-dark); }

.plot-actions { display: flex; align-items: center; gap: 0.6rem; margin-bottom: 0.8rem; }
.hide-balanced-toggle { display: flex; align-items: center; gap: 0.35rem; margin-left: auto; font-size: 0.88rem; white-space: nowrap; }
.hide-balanced-toggle input { margin: 0; }
#hiddenBalancedCount { color: var(--muted); }

/* ── Modals ── */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.modal-content {
  background: var(--card);
  padding: 1.5rem;
  border-radius: 10px;
  width: 420px;
  max-width: 90vw;
  max-height: 85vh;
  overflow-y: auto;
}
.modal-content.wide { width: 640px; }
.modal-content h2 { margin-top: 0; font-size: 1.05rem; }
.modal-content button { margin: 0.3rem 0.3rem 0 0; width: 100%; }
.modal-content input[type="text"] { width: 100%; padding: 0.55rem; border: 1px solid var(--border); border-radius: 6px; margin-bottom: 0.5rem; }
.coordinator-add { display: flex; gap: 0.4rem; margin-top: 0.8rem; }
.coordinator-add input[type="text"], .coordinator-add input[type="email"] {
  flex: 1; width: auto; min-width: 0; padding: 0.5rem; border: 1px solid var(--border); border-radius: 6px; margin-bottom: 0;
}
.coordinator-add button { flex: 0 0 auto; width: auto; }
#coordinatorsTable th:first-child, #coordinatorsTable td:first-child { min-width: 170px; white-space: nowrap; }
.hint { font-size: 0.78rem; color: var(--muted); }
.confirm-message { white-space: pre-wrap; }

.error { color: var(--danger); font-size: 0.85rem; min-height: 1.2em; }

/* ── Templates modal ── */
.templates-tabs { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 0.8rem; }
.templates-tabs button { width: auto; background: #eef1f4; color: var(--text); border: 1px solid var(--border); padding: 0.4rem 0.7rem; font-size: 0.82rem; }
.templates-tabs button.active { background: var(--brand); color: white; border-color: var(--brand); }
.template-editor label { display: flex; flex-direction: column; font-size: 0.82rem; color: var(--muted); gap: 0.3rem; margin-bottom: 0.7rem; }
.template-editor input {
  padding: 0.5rem; border: 1px solid var(--border); border-radius: 6px; font-family: inherit; font-size: 0.85rem; color: var(--text);
}
.template-editor-actions { display: flex; gap: 0.5rem; }
.template-editor-actions button { width: auto; }

/* Body editors show the email as normal formatted text (like Outlook), not raw HTML markup —
   contenteditable rendering the actual tags, rather than a textarea showing them as source. */
.rich-body-editor {
  min-height: 180px;
  max-height: 340px;
  overflow-y: auto;
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: white;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--text);
}
.rich-body-editor:focus { outline: 2px solid var(--brand); outline-offset: -1px; }
.rich-body-editor p { margin: 0 0 0.8em; }
.rich-body-editor p:last-child { margin-bottom: 0; }
.rich-body-editor ul { margin: 0 0 0.8em; padding-left: 1.4em; }

/* ── Audit log ── */
.audit-details { margin-top: 1.2rem; background: var(--card); border-radius: 8px; padding: 0.8rem 1rem; box-shadow: 0 1px 4px rgba(0,0,0,0.06); }
.audit-details summary { cursor: pointer; font-weight: 600; color: var(--muted); font-size: 0.9rem; }
.audit-details table { margin-top: 0.7rem; box-shadow: none; }

.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: white;
  padding: 0.7rem 1.2rem;
  border-radius: 8px;
  font-size: 0.85rem;
  z-index: 100;
}
.toast.error { background: var(--danger); }
