/* ===== Reset & Variables ===== */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg: #1a1a1a;
  --fg: #e8e0d4;
  --accent: #d4a574;
  --muted: #6b6560;
  --card-bg: #242220;
  --card-border: #3a3633;
  --danger: #c0564a;
  --success: #5a9e6f;
  --warning: #c9a84c;
  --sidebar-w: 220px;
}

/* ===== Login Gate ===== */
.login-gate {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}
.login-gate.hidden { display: none; }
.login-box {
  text-align: center;
  max-width: 320px;
  width: 100%;
  padding: 2rem;
}
.login-box h1 {
  color: var(--accent);
  font-family: Georgia, serif;
  font-size: 1.5rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  margin-bottom: 0.25rem;
}
.login-subtitle {
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 2rem;
}
#login-form {
  display: flex;
  gap: 0.5rem;
}
#login-password {
  flex: 1;
  padding: 0.6rem 1rem;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 6px;
  color: var(--fg);
  font-size: 1rem;
  outline: none;
}
#login-password:focus { border-color: var(--accent); }
.login-error {
  color: var(--danger);
  font-size: 0.85rem;
  margin-top: 1rem;
}
.login-error.hidden { display: none; }

/* ===== Base ===== */
html { font-size: 15px; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--fg);
  min-height: 100vh;
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
}

/* ===== Sidebar ===== */
#sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-w);
  height: 100vh;
  background: #141312;
  border-right: 1px solid var(--card-border);
  display: flex;
  flex-direction: column;
  z-index: 100;
  overflow-y: auto;
}

.sidebar-header {
  padding: 1.5rem 1.25rem 1rem;
  border-bottom: 1px solid var(--card-border);
}

.sidebar-header h1 {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 1.15rem;
  font-weight: 400;
  color: var(--accent);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.sidebar-subtitle {
  display: block;
  font-size: 0.7rem;
  color: var(--muted);
  margin-top: 0.2rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.nav-links {
  list-style: none;
  padding: 0.75rem 0;
}

.nav-link {
  display: block;
  padding: 0.6rem 1.25rem;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.85rem;
  transition: color 0.15s, background 0.15s;
  border-left: 3px solid transparent;
}

.nav-link:hover {
  color: var(--fg);
  background: rgba(212, 165, 116, 0.05);
}

.nav-link.active {
  color: var(--accent);
  border-left-color: var(--accent);
  background: rgba(212, 165, 116, 0.08);
}

/* ===== Main Content ===== */
#main-content {
  grid-column: 2;
  padding: 2rem 2.5rem;
  min-height: 100vh;
  overflow-x: hidden;
}

.content-section { display: none; }
.content-section.active { display: block; }

.section-header {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.section-header h2 {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 1.5rem;
  font-weight: 400;
  color: var(--fg);
}

.record-count {
  font-size: 0.8rem;
  color: var(--muted);
}

/* ===== Filters ===== */
.filters-row {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  align-items: center;
}

.filters-row select,
.filters-row input[type="text"] {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  color: var(--fg);
  padding: 0.45rem 0.65rem;
  border-radius: 6px;
  font-size: 0.8rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}

.filters-row select:focus,
.filters-row input[type="text"]:focus {
  border-color: var(--accent);
}

.filters-row input[type="text"] {
  min-width: 200px;
}

/* ===== Buttons ===== */
.btn {
  background: var(--accent);
  color: #1a1a1a;
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  font-size: 0.8rem;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}

.btn:hover { opacity: 0.85; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-small { padding: 0.4rem 0.75rem; font-size: 0.75rem; }

.btn-muted {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--card-border);
}
.btn-muted:hover { color: var(--fg); border-color: var(--muted); opacity: 1; }

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-outline {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
}
.btn-outline:hover { background: rgba(212, 165, 116, 0.1); opacity: 1; }

/* ===== Tables ===== */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--card-border);
  border-radius: 8px;
  background: var(--card-bg);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

thead th {
  text-align: left;
  padding: 0.7rem 0.75rem;
  background: #1e1c1a;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-bottom: 1px solid var(--card-border);
  white-space: nowrap;
  user-select: none;
}

thead th.sortable { cursor: pointer; }
thead th.sortable:hover { color: var(--accent); }
thead th.sort-asc::after { content: ' \25B2'; font-size: 0.6rem; }
thead th.sort-desc::after { content: ' \25BC'; font-size: 0.6rem; }

tbody tr {
  cursor: pointer;
  transition: background 0.1s;
}

tbody tr:hover { background: rgba(212, 165, 116, 0.05); }

tbody td {
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--card-border);
  vertical-align: top;
  line-height: 1.45;
}

tbody tr:last-child td { border-bottom: none; }

.col-content { min-width: 240px; max-width: 360px; }

td.content-cell {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 0.82rem;
  color: var(--fg);
}

/* ===== Tags / Badges ===== */
.tag {
  display: inline-block;
  background: rgba(212, 165, 116, 0.12);
  color: var(--accent);
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  font-size: 0.68rem;
  margin: 0.1rem 0.15rem 0.1rem 0;
  white-space: nowrap;
}

.badge {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 4px;
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.badge-complete { background: rgba(90, 158, 111, 0.15); color: var(--success); }
.badge-running  { background: rgba(201, 168, 76, 0.15); color: var(--warning); }
.badge-failed   { background: rgba(192, 86, 74, 0.15); color: var(--danger); }
.badge-pending  { background: rgba(107, 101, 96, 0.15); color: var(--muted); }

.badge-voice_response { background: rgba(130, 160, 210, 0.15); color: #82a0d2; }
.badge-manual         { background: rgba(212, 165, 116, 0.12); color: var(--accent); }
.badge-conversation   { background: rgba(160, 200, 160, 0.15); color: #a0c8a0; }

.badge-reached_out { background: rgba(90, 158, 111, 0.15); color: var(--success); }
.badge-skipped     { background: rgba(107, 101, 96, 0.15); color: var(--muted); }

.engagement-bar {
  display: inline-block;
  width: 50px;
  height: 6px;
  background: var(--card-border);
  border-radius: 3px;
  overflow: hidden;
  vertical-align: middle;
}

.engagement-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
}

/* ===== Pagination ===== */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  margin-top: 1.25rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.pagination button {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  color: var(--fg);
  padding: 0.35rem 0.8rem;
  border-radius: 5px;
  font-size: 0.78rem;
  cursor: pointer;
  transition: border-color 0.15s;
}

.pagination button:hover:not(:disabled) { border-color: var(--accent); }
.pagination button:disabled { opacity: 0.3; cursor: not-allowed; }

/* ===== Card List ===== */
.card-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 10px;
  padding: 1.25rem 1.4rem;
  cursor: pointer;
  transition: border-color 0.15s;
}

.card:hover { border-color: var(--accent); }

.card-title {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 1rem;
  line-height: 1.5;
  margin-bottom: 0.35rem;
}

.card-meta {
  font-size: 0.72rem;
  color: var(--muted);
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex-wrap: wrap;
}

.card-content-preview {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 0.88rem;
  line-height: 1.6;
  color: var(--fg);
  margin-top: 0.5rem;
  opacity: 0.85;
}

.card-expanded-content {
  display: none;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--card-border);
}

.card.expanded .card-expanded-content { display: block; }

.card-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
}

/* ===== Brief markdown content ===== */
.brief-rendered {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 0.92rem;
  line-height: 1.75;
}

.brief-rendered h1,
.brief-rendered h2,
.brief-rendered h3 {
  font-weight: 600;
  margin-top: 1.25rem;
  margin-bottom: 0.5rem;
  color: var(--accent);
}

.brief-rendered h1 { font-size: 1.2rem; }
.brief-rendered h2 { font-size: 1.05rem; }
.brief-rendered h3 { font-size: 0.95rem; }

.brief-rendered p { margin-bottom: 0.75rem; }

.brief-rendered blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 1rem;
  margin: 0.75rem 0;
  color: var(--muted);
  font-style: italic;
}

.brief-rendered strong { font-weight: 700; color: var(--fg); }
.brief-rendered em { font-style: italic; }

.brief-rendered ul, .brief-rendered ol {
  margin: 0.5rem 0 0.75rem 1.5rem;
}

.brief-rendered li { margin-bottom: 0.3rem; }

/* ===== Collision passages ===== */
.collision-section {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--card-border);
}

.collision-section h4 {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
  margin-bottom: 0.75rem;
}

.collision-passage {
  background: rgba(212, 165, 116, 0.04);
  border: 1px solid var(--card-border);
  border-radius: 6px;
  padding: 0.75rem 1rem;
  margin-bottom: 0.5rem;
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 0.85rem;
  line-height: 1.6;
}

.collision-passage .cp-source {
  font-size: 0.7rem;
  color: var(--muted);
  margin-top: 0.4rem;
  font-family: -apple-system, sans-serif;
}

/* ===== Search ===== */
.search-bar {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}

.search-bar input {
  flex: 1;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  color: var(--fg);
  padding: 0.7rem 1rem;
  border-radius: 8px;
  font-size: 1rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}

.search-bar input:focus { border-color: var(--accent); }

.search-bar .btn { padding: 0.7rem 1.5rem; font-size: 0.9rem; }

/* ===== Review Queue ===== */
.rq-transcript {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 0.88rem;
  line-height: 1.6;
  margin-bottom: 0.5rem;
  opacity: 0.85;
}

.rq-summary {
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.75rem;
}

.rq-candidates {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.75rem;
}

.rq-candidate-btn {
  background: rgba(212, 165, 116, 0.1);
  border: 1px solid var(--accent);
  color: var(--accent);
  padding: 0.35rem 0.7rem;
  border-radius: 5px;
  font-size: 0.78rem;
  cursor: pointer;
  transition: background 0.15s;
}

.rq-candidate-btn:hover { background: rgba(212, 165, 116, 0.25); }

/* ===== Daily 5 ===== */
.date-group-header {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 1rem;
  color: var(--accent);
  margin-top: 1.5rem;
  margin-bottom: 0.5rem;
  padding-bottom: 0.35rem;
  border-bottom: 1px solid var(--card-border);
}

.date-group-header:first-child { margin-top: 0; }

.d5-reason {
  font-size: 0.82rem;
  line-height: 1.5;
  margin-bottom: 0.35rem;
}

.d5-opener {
  font-family: Georgia, 'Times New Roman', serif;
  font-style: italic;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 0.5rem;
}

.d5-status-btns {
  display: flex;
  gap: 0.4rem;
}

.d5-status-btns button {
  padding: 0.3rem 0.6rem;
  border-radius: 4px;
  font-size: 0.7rem;
  cursor: pointer;
  border: 1px solid var(--card-border);
  background: transparent;
  color: var(--fg);
  transition: all 0.15s;
}

.d5-status-btns button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.d5-status-btns button.active-status {
  background: var(--accent);
  color: #1a1a1a;
  border-color: var(--accent);
  font-weight: 600;
}

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  z-index: 200;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 3rem 1rem;
  overflow-y: auto;
}

.modal-overlay.hidden { display: none; }

.modal {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  width: 100%;
  max-width: 720px;
  padding: 2rem;
  position: relative;
}

.modal-close {
  position: absolute;
  top: 1rem;
  right: 1.25rem;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
  transition: color 0.15s;
}

.modal-close:hover { color: var(--fg); }

.modal-body h3 {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 1.1rem;
  font-weight: 400;
  margin-bottom: 1.25rem;
  color: var(--accent);
}

.modal-body label {
  display: block;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 0.3rem;
  margin-top: 1rem;
}

.modal-body label:first-of-type { margin-top: 0; }

.modal-body input[type="text"],
.modal-body textarea,
.modal-body select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--card-border);
  color: var(--fg);
  padding: 0.55rem 0.75rem;
  border-radius: 6px;
  font-size: 0.85rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}

.modal-body input[type="text"]:focus,
.modal-body textarea:focus,
.modal-body select:focus {
  border-color: var(--accent);
}

.modal-body textarea {
  min-height: 100px;
  resize: vertical;
  font-family: Georgia, 'Times New Roman', serif;
  line-height: 1.6;
}

.modal-body .full-content {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 0.95rem;
  line-height: 1.75;
  padding: 1rem;
  background: var(--bg);
  border-radius: 8px;
  border: 1px solid var(--card-border);
  margin-bottom: 1rem;
  max-height: 300px;
  overflow-y: auto;
}

.modal-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1.5rem;
  justify-content: flex-end;
}

.modal-meta {
  font-size: 0.72rem;
  color: var(--muted);
  margin-top: 0.75rem;
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--card-bg);
  border: 1px solid var(--accent);
  color: var(--fg);
  padding: 0.6rem 1.2rem;
  border-radius: 8px;
  font-size: 0.82rem;
  z-index: 300;
  transition: opacity 0.3s;
}

.toast.hidden { opacity: 0; pointer-events: none; }
.toast.error { border-color: var(--danger); color: var(--danger); }

/* ===== Loading ===== */
.loading-indicator {
  text-align: center;
  padding: 2rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.empty-state {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.7;
}

/* ===== Scrollbars ===== */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--card-border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* ===== Responsive ===== */
@media (max-width: 900px) {
  :root { --sidebar-w: 180px; }
  #main-content { padding: 1.5rem 1.25rem; }
}

@media (max-width: 700px) {
  body { grid-template-columns: 1fr; }

  #sidebar {
    position: fixed;
    bottom: 0;
    top: auto;
    left: 0;
    width: 100%;
    height: auto;
    flex-direction: row;
    border-right: none;
    border-top: 1px solid var(--card-border);
  }

  .sidebar-header { display: none; }

  .nav-links {
    display: flex;
    overflow-x: auto;
    padding: 0;
    width: 100%;
  }

  .nav-link {
    border-left: none;
    border-top: 3px solid transparent;
    padding: 0.6rem 0.75rem;
    white-space: nowrap;
    font-size: 0.72rem;
  }

  .nav-link.active { border-left-color: transparent; border-top-color: var(--accent); }

  #main-content {
    grid-column: 1;
    padding: 1.25rem 1rem;
    padding-bottom: 4rem;
  }
}
