:root {
  --bg: #0f1419; --card: #1a2027; --card2: #222b34; --line: #2d3742;
  --text: #e6edf3; --muted: #8b98a5; --primary: #2f81f7; --primary-d: #1f6feb;
  --green: #2ea043; --red: #f85149; --amber: #d29922;
  /* chart ink: grid/axes sit one shade off the surface so marks stay the loudest thing */
  --grid: #232c35; --axis: #3a4653;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 system-ui, "Segoe UI", Roboto, sans-serif;
}
header {
  padding: 14px 28px 0; background: #11181f; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.header-top { display: flex; justify-content: space-between; align-items: center; gap: 16px; }
h1 { font-size: 19px; margin: 0; }
h1 a { color: inherit; text-decoration: none; }
h2 { font-size: 17px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 16px 0 8px; }
.sub { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
main { max-width: 1180px; margin: 0 auto; padding: 24px; display: grid; gap: 20px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 20px; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.hint { color: var(--muted); font-size: 13px; margin: -4px 0 14px; }
.hint a, a { color: var(--primary); }
.muted { color: var(--muted); }
.page-title { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; flex-wrap: wrap; }
.page-title h2 { font-size: 20px; margin: 0; }

/* ------------------------------- top nav ------------------------------- */
.tabs { display: flex; gap: 4px; margin-top: 12px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a {
  display: flex; align-items: center; gap: 6px; white-space: nowrap; text-decoration: none;
  color: var(--muted); padding: 9px 14px; border-radius: 8px 8px 0 0; font-size: 14px;
  border: 1px solid transparent; border-bottom: none; position: relative; top: 1px;
}
.tabs a:hover { color: var(--text); background: #161d25; }
.tabs a.active {
  color: var(--text); background: var(--bg); border-color: var(--line); font-weight: 600;
}

/* ------------------------- dashboard link cards ------------------------- */
.nav-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.nav-card {
  display: block; text-decoration: none; color: inherit; background: var(--card);
  border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px;
}
.nav-card:hover { border-color: var(--primary); background: var(--card2); }
.nav-card .ico { font-size: 22px; }
.nav-card .t { font-weight: 600; margin: 6px 0 2px; }
.nav-card .d { color: var(--muted); font-size: 13px; }

/* ------------------------------ stat tiles ------------------------------ */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
.kpi .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.kpi .value { font-size: 27px; font-weight: 600; line-height: 1.2; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .foot { color: var(--muted); font-size: 12px; margin-top: 2px; }
.kpi.good .value { color: var(--green); } .kpi.warn .value { color: var(--amber); }
.kpi.bad .value { color: var(--red); } .kpi.info .value { color: var(--primary); }

.config { display: flex; gap: 6px; flex-wrap: wrap; }
.pill { background: var(--card2); border: 1px solid var(--line); border-radius: 20px; padding: 3px 10px; font-size: 12px; color: var(--muted); }
.pill.ok { color: var(--green); } .pill.bad { color: var(--red); border-color: var(--red); }

.form-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 14px; }
.form-grid.two { grid-template-columns: 1fr 1fr; }
.span2 { grid-column: 1 / -1; }
label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
label.inline { flex-direction: row; align-items: center; gap: 8px; }
input, select, textarea { background: var(--card2); border: 1px solid var(--line); color: var(--text); border-radius: 8px; padding: 9px 11px; font-size: 14px; font-family: inherit; }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); }
input[type="file"] { padding: 7px; }
.row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.divider { width: 1px; height: 26px; background: var(--line); }
.grow { flex: 1; }

/* filters sit in one row above the thing they filter */
.filters { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 14px; }
.filters label { font-size: 12px; }
.filters .spacer { flex: 1; }

/* dynamic "data to collect" editor */
.fields-head { display: flex; justify-content: space-between; align-items: center; margin: 4px 0 8px; font-size: 13px; color: var(--muted); }
.fields-editor { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.field-row { display: grid; grid-template-columns: 1fr 1.5fr auto; gap: 8px; align-items: center; }
.field-row .del { padding: 6px 11px; color: var(--muted); }
.field-row .del:hover { border-color: var(--red); color: var(--red); }
.fields-empty { color: var(--muted); font-size: 13px; }
.kv { display: inline-block; background: var(--card2); border: 1px solid var(--line); border-radius: 6px; padding: 1px 7px; margin: 2px 4px 2px 0; font-size: 12px; }
.kv b { color: var(--text); } .kv span { color: var(--muted); }

button { background: var(--card2); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 9px 14px; font-size: 14px; cursor: pointer; }
button:hover { border-color: var(--primary); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
button.primary:hover { background: var(--primary-d); }
button.danger { border-color: var(--red); color: var(--red); }
.actions button { padding: 5px 10px; font-size: 13px; margin-left: 6px; }
.linkbtn { display: inline-block; padding: 5px 10px; font-size: 13px; margin-left: 6px; border: 1px solid var(--line); border-radius: 8px; color: var(--text); text-decoration: none; background: var(--card2); }
.linkbtn:hover { border-color: var(--primary); }
.linkbtn.lead { margin-left: 0; padding: 9px 14px; font-size: 14px; }

.msg { margin-top: 12px; font-size: 13px; color: var(--green); min-height: 18px; }
.msg.bad { color: var(--red); }
.banner { border: 1px solid var(--line); border-left-width: 3px; border-radius: 8px; padding: 10px 14px; font-size: 13px; background: var(--bg); }
.banner.warn { border-left-color: var(--amber); }
.banner.bad { border-left-color: var(--red); }
.banner.info { border-left-color: var(--primary); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.row-bad td { background: rgba(248,81,73,.07); }

.status { padding: 2px 9px; border-radius: 20px; font-size: 12px; text-transform: capitalize; }
.status-completed { background: rgba(46,160,67,.15); color: var(--green); }
.status-in_progress { background: rgba(47,129,247,.15); color: var(--primary); }
.status-ringing { background: rgba(210,153,34,.15); color: var(--amber); }
.status-created { background: var(--card2); color: var(--muted); }
.status-no_answer, .status-failed, .status-cancelled { background: rgba(248,81,73,.15); color: var(--red); }
.status-pending { background: rgba(210,153,34,.15); color: var(--amber); }
.status-triggered { background: rgba(47,129,247,.15); color: var(--primary); }

/* ------------------------------- charts ------------------------------- */
.chart-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(330px, 1fr)); gap: 20px; }
.chart-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 4px; }
.chart-head h3 { margin: 0; font-size: 15px; }
.chart-note { color: var(--muted); font-size: 12px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; margin: 6px 0 10px; font-size: 12px; color: var(--muted); }
.legend-item { display: flex; align-items: center; gap: 6px; }
.swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.plot { position: relative; }
.plot svg { display: block; width: 100%; height: auto; overflow: visible; }
.empty-plot { color: var(--muted); font-size: 13px; padding: 26px 0; text-align: center; }

/* horizontal magnitude bars: label, track, value — the number is always visible */
.hbars { display: grid; gap: 9px; }
.hbar { display: grid; grid-template-columns: minmax(90px, 30%) 1fr auto; gap: 10px; align-items: center; font-size: 13px; }
.hbar .name { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar .track { background: var(--grid); border-radius: 4px; height: 10px; position: relative; }
.hbar .fill { background: var(--primary); border-radius: 4px; height: 100%; min-width: 2px; }
.hbar .fill.good { background: var(--green); }
.hbar .val { font-variant-numeric: tabular-nums; min-width: 42px; text-align: right; }

/* hourly columns */
.cols { display: flex; align-items: flex-end; gap: 2px; height: 130px; }
.cols .col { flex: 1; background: var(--primary); border-radius: 4px 4px 0 0; min-height: 2px; }
.cols .col.zero { background: var(--grid); }
.col-axis { display: flex; justify-content: space-between; color: var(--muted); font-size: 11px; margin-top: 6px; }

.tip {
  position: fixed; z-index: 40; pointer-events: none; background: #0b1016;
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; font-size: 12px;
  box-shadow: 0 6px 20px rgba(0,0,0,.5); white-space: nowrap;
}
.tip b { font-variant-numeric: tabular-nums; }

/* ------------------------------- bulk CSV ------------------------------- */
.dropzone {
  border: 1px dashed var(--line); border-radius: 10px; padding: 22px; text-align: center;
  color: var(--muted); font-size: 13px; background: var(--bg); cursor: pointer;
}
.dropzone.over { border-color: var(--primary); color: var(--text); }
.dropzone b { color: var(--text); }
.col-list { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 0; }
.col-chip { background: var(--card2); border: 1px solid var(--line); border-radius: 6px; padding: 2px 8px; font-size: 12px; font-family: ui-monospace, Consolas, monospace; }
.col-chip.req { border-color: var(--primary); color: var(--text); }
.errs { color: var(--red); font-size: 12px; white-space: normal; }

/* simulator */
.chat { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 12px; min-height: 80px; max-height: 320px; overflow-y: auto; margin: 12px 0; display: flex; flex-direction: column; gap: 8px; }
.bubble { padding: 8px 12px; border-radius: 10px; max-width: 80%; }
.bubble.assistant { background: var(--card2); align-self: flex-start; }
.bubble.farmer { background: var(--primary-d); align-self: flex-end; }
#simInputRow { gap: 8px; } #simInput { flex: 1; }
.lead-box { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin-top: 10px; font-size: 13px; }

/* modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 20; }
.modal.hidden { display: none; }
.modal-body { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 24px; max-width: 640px; width: 100%; max-height: 85vh; overflow-y: auto; position: relative; }
.close { position: absolute; top: 14px; right: 14px; background: none; border: none; font-size: 18px; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; font-size: 14px; }
.transcript { display: flex; flex-direction: column; gap: 6px; }
.turn { padding: 7px 10px; border-radius: 8px; background: var(--bg); font-size: 14px; }
.turn-farmer { border-left: 3px solid var(--primary); }
.turn-assistant { border-left: 3px solid var(--green); }

@media (max-width: 720px) {
  .form-grid { grid-template-columns: 1fr; }
  .header-top { flex-direction: column; align-items: flex-start; }
  header { padding: 14px 16px 0; }
  main { padding: 16px; }
  .hbar { grid-template-columns: minmax(70px, 40%) 1fr auto; }
}
