/* ---------- design tokens ---------- */
:root {
  color-scheme: light;
  --surface-1:      #fcfcfb;
  --surface-2:      #f9f9f7;
  --surface-3:      #f2f1ed;
  --text-primary:   #0b0b0b;
  --text-secondary: #52514e;
  --text-muted:     #898781;
  --gridline:       #e1e0d9;
  --border:         rgba(11,11,11,0.10);
  --baseline:       #c3c2b7;

  --series-1: #2a78d6; /* blue */
  --series-2: #eb6834; /* orange */
  --series-3: #1baf7a; /* aqua */
  --series-4: #eda100; /* yellow */
  --series-5: #e87ba4; /* magenta */
  --series-6: #008300; /* green */
  --series-7: #4a3aa7; /* violet */
  --series-8: #e34948; /* red */

  --status-good:     #0ca30c;
  --status-warning:  #fab219;
  --status-serious:  #ec835a;
  --status-critical: #d03b3b;

  --radius-lg: 14px;
  --radius-md: 10px;
  --radius-sm: 7px;
  --shadow-1: 0 1px 2px rgba(11,11,11,0.06), 0 1px 1px rgba(11,11,11,0.04);
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface-1:      #1a1a19;
    --surface-2:      #0d0d0d;
    --surface-3:      #232322;
    --text-primary:   #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted:     #898781;
    --gridline:       #2c2c2a;
    --border:         rgba(255,255,255,0.10);
    --baseline:       #383835;

    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --series-7: #9085e9;
    --series-8: #e66767;

    --status-good:     #0ca30c;
    --status-warning:  #fab219;
    --status-serious:  #ec835a;
    --status-critical: #d03b3b;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1:      #1a1a19;
  --surface-2:      #0d0d0d;
  --surface-3:      #232322;
  --text-primary:   #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted:     #898781;
  --gridline:       #2c2c2a;
  --border:         rgba(255,255,255,0.10);
  --baseline:       #383835;

  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --series-6: #008300;
  --series-7: #9085e9;
  --series-8: #e66767;
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--surface-2);
  color: var(--text-primary);
  overflow-x: hidden;
}
button { font-family: inherit; }
svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.app {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

/* ---------- sidebar ---------- */
.sidebar {
  background: var(--surface-1);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px 22px;
}
.brand-mark {
  width: 34px; height: 34px;
  border-radius: var(--radius-sm);
  background: var(--series-1);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.02em;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text strong { font-size: 14px; }
.brand-text span { font-size: 12px; color: var(--text-muted); }

.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 13.5px;
  text-align: left;
  cursor: pointer;
}
.nav-item svg { flex-shrink: 0; opacity: 0.8; }
.nav-item:hover { background: var(--surface-3); color: var(--text-primary); }
.nav-item.is-active { background: var(--series-1); color: #fff; }
.nav-item.is-active svg { opacity: 1; }

.sidebar-footer {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.theme-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-secondary);
  font-size: 12.5px;
  cursor: pointer;
}
.theme-toggle:hover { color: var(--text-primary); }
.generated-at { font-size: 11px; color: var(--text-muted); padding: 0 2px; }

/* ---------- main / topbar ---------- */
.main { min-width: 0; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 28px;
  background: color-mix(in srgb, var(--surface-2) 88%, transparent);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.search-wrap {
  position: relative;
  width: min(420px, 46vw);
}
.search-wrap svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--text-muted); }
.search-wrap input {
  width: 100%;
  padding: 9px 12px 9px 34px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-primary);
  font-size: 13px;
}
.search-wrap input:focus { outline: 2px solid var(--series-1); outline-offset: -1px; }
.pill {
  font-size: 11.5px;
  color: var(--text-muted);
  border: 1px dashed var(--border);
  border-radius: 999px;
  padding: 5px 11px;
  white-space: nowrap;
}

.views { padding: 22px 28px 60px; }
.view { display: none; }
.view.is-active { display: block; }

/* ---------- KPI cards ---------- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}
.kpi-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  box-shadow: var(--shadow-1);
}
.kpi-card .kpi-label { font-size: 12px; color: var(--text-muted); margin-bottom: 8px; }
.kpi-card .kpi-value { font-size: 26px; font-weight: 650; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.kpi-card .kpi-sub { font-size: 12px; color: var(--text-secondary); margin-top: 4px; }
.kpi-card.accent { border-color: color-mix(in srgb, var(--series-1) 40%, var(--border)); }
.kpi-card.accent .kpi-value { color: var(--series-1); }

/* ---------- cards / charts ---------- */
.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 18px 18px;
  box-shadow: var(--shadow-1);
}
.card-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 12px; gap: 10px; }
.card-head h3 { margin: 0; font-size: 14px; font-weight: 600; }
.muted { color: var(--text-muted); font-size: 12px; }

.charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 14px;
}
.chart { display: flex; flex-direction: column; gap: 9px; }

.hbar-row { display: grid; grid-template-columns: 118px 1fr 42px; align-items: center; gap: 10px; font-size: 12.5px; }
.hbar-label { color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hbar-track { position: relative; height: 10px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.hbar-fill { position: absolute; inset: 0 auto 0 0; border-radius: 999px; transition: width .3s ease; }
.hbar-value { text-align: right; font-variant-numeric: tabular-nums; color: var(--text-secondary); }

.donut-wrap { display: flex; align-items: center; gap: 18px; }
.donut-svg { flex-shrink: 0; width: 112px; height: 112px; }
.donut-legend { display: flex; flex-direction: column; gap: 7px; font-size: 12.5px; }
.legend-row { display: flex; align-items: center; gap: 8px; }
.legend-swatch { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
.legend-label { color: var(--text-secondary); }
.legend-value { margin-left: auto; font-variant-numeric: tabular-nums; color: var(--text-primary); font-weight: 600; padding-left: 10px;}

/* ---------- view head / tabs ---------- */
.view-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; margin-bottom: 14px; }
.view-head h2 { margin: 0; font-size: 18px; font-weight: 650; }
.view-head h2 .muted { font-size: 13px; font-weight: 400; margin-left: 4px; }

.tabs { display: flex; gap: 4px; background: var(--surface-3); padding: 3px; border-radius: 999px; }
.tab {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 12.5px;
  padding: 6px 13px;
  border-radius: 999px;
  cursor: pointer;
}
.tab.is-active { background: var(--surface-1); color: var(--text-primary); box-shadow: var(--shadow-1); font-weight: 600; }

.table-toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.table-search {
  flex: 1;
  max-width: 320px;
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-primary);
  font-size: 12.5px;
}
.row-count { font-size: 12px; color: var(--text-muted); }
.btn-ghost {
  margin-left: auto;
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-size: 12px;
  cursor: pointer;
}
.btn-ghost:hover { color: var(--text-primary); border-color: var(--series-1); }

/* ---------- tables ---------- */
.table-wrap {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: auto;
  max-height: 62vh;
}
table { border-collapse: collapse; width: max-content; min-width: 100%; font-size: 12.5px; }
thead th {
  position: sticky; top: 0; z-index: 2;
  background: var(--surface-1);
  text-align: left;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  font-size: 10.5px;
  letter-spacing: 0.04em;
  padding: 10px 14px;
  border-bottom: 1px solid var(--gridline);
  cursor: pointer;
  white-space: nowrap;
}
thead th:hover { color: var(--text-primary); }
thead th .sort-arrow { margin-left: 4px; opacity: 0.5; }
tbody td {
  padding: 9px 14px;
  border-bottom: 1px solid var(--gridline);
  color: var(--text-secondary);
  white-space: nowrap;
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
}
tbody td.wrap { white-space: normal; }
tbody tr:hover td { background: var(--surface-2); }
tbody td.strong { color: var(--text-primary); font-weight: 550; }
.table-empty { padding: 30px; text-align: center; color: var(--text-muted); font-size: 13px; }

/* badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-ready, .badge-send_now, .badge-high  { color: var(--status-good); background: color-mix(in srgb, var(--status-good) 14%, transparent); }
.badge-review, .badge-review_context, .badge-medium { color: var(--status-warning); background: color-mix(in srgb, var(--status-warning) 20%, transparent); }
.badge-defer, .badge-low { color: var(--text-muted); background: var(--surface-3); }
.badge-hamburg_core { color: var(--series-1); background: color-mix(in srgb, var(--series-1) 14%, transparent); }
.badge-north_germany_expand { color: var(--series-7); background: color-mix(in srgb, var(--series-7) 14%, transparent); }
.badge-outside_target { color: var(--text-muted); background: var(--surface-3); }

/* outreach status badges */
.badge-sent, .badge-awaiting { color: var(--status-warning); background: color-mix(in srgb, var(--status-warning) 20%, transparent); }
.badge-replied_positive, .badge-meeting_booked { color: var(--status-good); background: color-mix(in srgb, var(--status-good) 14%, transparent); }
.badge-replied_negative { color: var(--status-serious); background: color-mix(in srgb, var(--status-serious) 18%, transparent); }
.badge-bounced, .badge-do_not_contact { color: var(--status-critical); background: color-mix(in srgb, var(--status-critical) 14%, transparent); }
.badge-no_response, .badge-not_contacted, .badge-__none__ { color: var(--text-muted); background: var(--surface-3); }
.badge-not_contacted::before, .badge-__none__::before { display: none; }

.pill-new {
  display: inline-flex;
  align-items: center;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: var(--series-1);
  background: color-mix(in srgb, var(--series-1) 16%, transparent);
  border-radius: 999px;
  padding: 2px 7px;
  margin-left: 6px;
  vertical-align: middle;
}

/* ---------- outreach KPI + actions ---------- */
.btn-log {
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--series-1);
  border-radius: var(--radius-sm);
  padding: 5px 10px;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.btn-log:hover { border-color: var(--series-1); background: color-mix(in srgb, var(--series-1) 8%, var(--surface-1)); }

/* ---------- modal ---------- */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(11,11,11,0.45);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  z-index: 50;
}
.modal-overlay.hidden { display: none; }
.modal {
  width: min(640px, 100%);
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
}
.modal-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--gridline);
  flex-shrink: 0;
}
.modal-head h3 { margin: 0 0 3px; font-size: 15.5px; }
.modal-close {
  border: none; background: transparent; color: var(--text-muted);
  cursor: pointer; padding: 4px; border-radius: var(--radius-sm);
}
.modal-close:hover { color: var(--text-primary); background: var(--surface-3); }
.modal-body { padding: 18px 20px 20px; overflow-y: auto; }

.timeline { display: flex; flex-direction: column; gap: 10px; margin-bottom: 18px; }
.timeline-empty { font-size: 12.5px; color: var(--text-muted); }
.timeline-item {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 11px 13px;
  background: var(--surface-2);
}
.timeline-item .ti-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; flex-wrap: wrap; }
.timeline-item .ti-date { font-size: 11.5px; color: var(--text-muted); margin-left: auto; }
.timeline-item .ti-subject { font-size: 12.5px; font-weight: 600; color: var(--text-primary); margin-bottom: 4px; }
.timeline-item .ti-body { font-size: 12.5px; color: var(--text-secondary); white-space: pre-wrap; margin-bottom: 6px; }
.timeline-item .ti-feedback { font-size: 12px; color: var(--text-secondary); border-top: 1px dashed var(--gridline); padding-top: 6px; }
.timeline-item .ti-feedback strong { color: var(--text-primary); }

.log-form { display: flex; flex-direction: column; gap: 12px; border-top: 1px solid var(--gridline); padding-top: 16px; }
.log-form h4 { margin: 0; font-size: 13px; }
.log-form label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--text-secondary); }
.log-form input, .log-form select, .log-form textarea {
  font-family: inherit;
  font-size: 12.5px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-primary);
  resize: vertical;
}
.log-form input:focus, .log-form select:focus, .log-form textarea:focus { outline: 2px solid var(--series-1); outline-offset: -1px; }
.log-form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.log-form-actions { display: flex; align-items: center; gap: 12px; }
.btn-primary {
  margin-left: auto;
  border: none;
  background: var(--series-1);
  color: #fff;
  border-radius: var(--radius-sm);
  padding: 8px 16px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}
.btn-primary:hover { opacity: 0.92; }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- compliance ---------- */
.compliance-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 14px; }
.compliance-grid .table-wrap { max-height: 46vh; }

/* ---------- drafts ---------- */
.drafts-layout { display: grid; grid-template-columns: 300px 1fr; gap: 14px; align-items: start; }
.drafts-list { display: flex; flex-direction: column; gap: 8px; }
.draft-item {
  text-align: left;
  border: 1px solid var(--border);
  background: var(--surface-1);
  border-radius: var(--radius-md);
  padding: 11px 13px;
  cursor: pointer;
}
.draft-item:hover { border-color: var(--series-1); }
.draft-item.is-active { border-color: var(--series-1); background: color-mix(in srgb, var(--series-1) 8%, var(--surface-1)); }
.draft-item .dcompany { font-size: 13px; font-weight: 600; color: var(--text-primary); }
.draft-item .dmeta { font-size: 11.5px; color: var(--text-muted); margin-top: 3px; }
.draft-preview { min-height: 320px; white-space: pre-wrap; font-size: 13px; line-height: 1.6; color: var(--text-secondary); }
.draft-preview .dp-head { font-size: 13px; font-weight: 650; color: var(--text-primary); margin-bottom: 10px; }

@media (max-width: 880px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .drafts-layout { grid-template-columns: 1fr; }
}
