:root {
  --bg: #0e1117;
  --panel: #161b24;
  --panel2: #1d2431;
  --border: #2a3345;
  --text: #e6ebf4;
  --muted: #8b96ab;
  --accent: #4f8cff;
  --green: #2ecc71;
  --yellow: #f1c40f;
  --red: #e74c3c;
  --agent: #4f8cff;
  --customer: #2ecc71;
  --unknown: #8b96ab;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

.badge.completed { background: rgba(79,140,255,.15); color: var(--accent); }

.sr-file {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

#calls-list.drop-active .panel.filters,
#calls-list.drop-active h1 { outline: 2px dashed var(--accent); outline-offset: 6px; border-radius: 8px; }

.drop-hint { color: var(--muted); font-size: 12px; margin: -8px 0 12px; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 10px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { font-size: 18px; font-weight: 700; }
.brand span { color: var(--accent); }

#nav { display: flex; gap: 6px; }
#nav button {
  background: transparent;
  color: var(--muted);
  border: none;
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
}
#nav button.active { background: var(--panel2); color: var(--text); }
#nav button:hover { color: var(--text); }

.right { margin-left: auto; }

main { padding: 20px; max-width: 1280px; margin: 0 auto; }

.view { display: none; }
.view.active { display: block; }

h1 { font-size: 20px; margin: 8px 0 16px; }
h3 { margin: 0 0 10px; font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 16px;
}

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; }
.card .label { color: var(--muted); font-size: 12px; }
.card .value { font-size: 26px; font-weight: 700; margin-top: 4px; }
.card .value.small { font-size: 18px; }

.grid2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
@media (max-width: 900px) { .grid2, .grid3 { grid-template-columns: 1fr; } }

.row { display: flex; align-items: center; }
.between { justify-content: space-between; }
.gap8 { gap: 8px; }
.right-align { justify-content: flex-end; }
.muted { color: var(--muted); }

.btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  font-size: 13px;
}
.btn.ghost { background: var(--panel2); color: var(--text); border: 1px solid var(--border); }
.btn.danger { background: var(--red); }
.btn:hover { filter: brightness(1.1); }

input, select, textarea {
  background: var(--panel2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }

.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.inline { display: flex; align-items: center; gap: 6px; white-space: nowrap; }

.table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.table th, .table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); }
.table th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; user-select: none; white-space: nowrap; }
.table th[data-sort] { cursor: pointer; position: relative; padding-right: 24px; }
.table th[data-sort]::after { content: ""; position: absolute; right: 8px; top: 50%; transform: translateY(-50%); width: 0; height: 0; border-left: 5px solid transparent; border-right: 5px solid transparent; opacity: 0.3; }
.table th[data-sort]::after { border-bottom: 6px solid var(--muted); margin-top: -3px; }
.table th[data-sort].sorted-asc::after { border-bottom: none; border-top: 6px solid var(--accent); margin-top: 3px; opacity: 1; }
.table th[data-sort].sorted-desc::after { border-top: none; border-bottom: 6px solid var(--accent); margin-top: -3px; opacity: 1; }
.table tbody tr { cursor: pointer; }
.table tbody tr:hover { background: var(--panel2); }

.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge.GREEN { background: rgba(46,204,113,.15); color: var(--green); }
.badge.YELLOW { background: rgba(241,196,15,.15); color: var(--yellow); }
.badge.RED { background: rgba(231,76,60,.18); color: var(--red); }
.badge.done { background: rgba(79,140,255,.15); color: var(--accent); }
.badge.failed { background: rgba(231,76,60,.18); color: var(--red); }
.badge.queued, .badge.processing { background: rgba(139,150,171,.15); color: var(--muted); }

.pager { margin-top: 12px; color: var(--muted); }

.chip { cursor: pointer; }

.daily-chart { display: flex; align-items: flex-end; gap: 4px; height: 180px; padding-top: 8px; }
.daily-chart .bar-wrap { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; }
.daily-chart .bar { width: 100%; max-width: 36px; background: linear-gradient(180deg, var(--accent), #2a5fd0); border-radius: 4px 4px 0 0; min-height: 2px; }
.daily-chart .bar-label { font-size: 10px; color: var(--muted); transform: rotate(-45deg); white-space: nowrap; }

.donut-wrap { display: flex; align-items: center; gap: 20px; }
.donut { width: 140px; height: 140px; border-radius: 50%; position: relative; background: var(--panel2); }
.donut::after { content: ""; position: absolute; inset: 32px; background: var(--panel); border-radius: 50%; }
#donut-center { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; z-index: 1; font-weight: 700; }
.legend { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.legend li { display: flex; align-items: center; gap: 8px; }
.legend .dot { width: 10px; height: 10px; border-radius: 50%; }

.ranklist { list-style: none; margin: 0; padding: 0; }
.ranklist li { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px dashed var(--border); }
.ranklist li:last-child { border-bottom: none; }

.fail-list { list-style: none; margin: 0; padding: 0; }
.fail-list li { padding: 8px 0; border-bottom: 1px dashed var(--border); color: var(--muted); }
.fail-list code { color: var(--red); }

.bubble { max-width: 78%; margin-bottom: 10px; padding: 10px 14px; border-radius: 14px; line-height: 1.55; }
.bubble .meta { font-size: 11px; opacity: .75; margin-bottom: 4px; }
.bubble.AGENT { background: rgba(79,140,255,.12); border-right: 3px solid var(--agent); margin-left: auto; }
.bubble.CUSTOMER { background: rgba(46,204,113,.1); border-left: 3px solid var(--customer); margin-right: auto; text-align: left; }
.bubble.UNKNOWN { background: rgba(139,150,171,.1); border-left: 3px solid var(--unknown); }

.score-row {
  background: var(--panel2);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 10px;
}
.score-row.sc-green { border-left-color: var(--green); }
.score-row.sc-yellow { border-left-color: var(--yellow); }
.score-row.sc-red { border-left-color: var(--red); }
.score-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; font-size: 13px; gap: 8px; }
.score-val { font-size: 18px; font-weight: 700; }
.score-row.sc-green .score-val { color: var(--green); }
.score-row.sc-yellow .score-val { color: var(--yellow); }
.score-row.sc-red .score-val { color: var(--red); }
.score-bar { height: 8px; background: rgba(255,255,255,.06); border-radius: 999px; overflow: hidden; }
.score-fill { height: 100%; border-radius: 999px; background: var(--accent); }
.score-row.sc-green .score-fill { background: var(--green); }
.score-row.sc-yellow .score-fill { background: var(--yellow); }
.score-row.sc-red .score-fill { background: var(--red); }
.score-evidence { color: var(--muted); font-style: italic; margin-top: 8px; font-size: 12.5px; }

.compliance-banner { padding: 12px 16px; border-radius: 10px; margin-bottom: 16px; font-weight: 600; }
.compliance-banner.RED { background: rgba(231,76,60,.15); border: 1px solid var(--red); }
.compliance-banner.YELLOW { background: rgba(241,196,15,.1); border: 1px solid var(--yellow); }
.compliance-banner.GREEN { background: rgba(46,204,113,.1); border: 1px solid var(--green); }

.meta-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; margin-bottom: 16px; }
.meta-item { background: var(--panel2); border-radius: 8px; padding: 8px 12px; }
.meta-item .k { color: var(--muted); font-size: 11px; }
.meta-item .v { margin-top: 2px; word-break: break-all; }

.objection-card { background: var(--panel2); border-radius: 10px; padding: 10px 14px; margin-bottom: 8px; }
.objection-card .q { font-style: italic; color: var(--muted); }

audio { width: 100%; margin-bottom: 16px; }

.toast { position: fixed; bottom: 20px; right: 20px; background: var(--panel2); border: 1px solid var(--border); padding: 12px 18px; border-radius: 10px; z-index: 100; box-shadow: 0 8px 30px rgba(0,0,0,.4); }

.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; z-index: 200; }
.modal { width: 360px; }

.setting-group { margin-bottom: 20px; }
.setting-group h3 { margin-bottom: 12px; }
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 8px 0; border-bottom: 1px dashed var(--border); }
.setting-row label { flex: 1; }
textarea.wide { width: 100%; min-height: 70px; resize: vertical; }
.weights-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; }
.weight-item { display: flex; justify-content: space-between; align-items: center; gap: 10px; background: var(--panel2); padding: 8px 12px; border-radius: 8px; }
.weight-item input { width: 80px; }

/* Sale-development tags */
.tags-row { display: flex; flex-wrap: wrap; gap: 6px; }
.tag-chip {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(99,102,241,.12);
  color: #a5b4fc;
  border: 1px solid rgba(99,102,241,.3);
  font-size: 12px;
  line-height: 1.6;
}


/* Back to top */
#back-to-top {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--accent);
  color: #fff;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0,0,0,.35);
  z-index: 900;
  transition: opacity .2s, transform .2s;
}
#back-to-top:hover { transform: translateY(-2px); }

/* Call detail tabs */
.dtabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin: 16px 0 14px;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
  padding-top: 4px;
}
.dtab {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  padding: 9px 14px;
  cursor: pointer;
  margin-bottom: -1px;
}
.dtab:hover { color: var(--text); }
.dtab.active { color: var(--accent); border-bottom-color: var(--accent); }
.dpane { animation: fadeIn .15s ease; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* Pager */
.row.gap4 { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.pg { min-width: 34px; padding: 6px 8px; }
.pg-gap { padding: 0 4px; color: var(--muted); }
.pg-goto { font-size: 12px; margin: 0 4px; }
#calls-goto { width: 56px; padding: 6px 8px; background: var(--panel2); border: 1px solid var(--border); border-radius: 8px; color: var(--text); }

/* Sub-Status editor + badge */
.ss-head, .ss-row { display: grid; grid-template-columns: 70px 70px 1fr 32px; gap: 8px; align-items: center; }
.ss-head { margin: 6px 0 4px; font-size: 12px; color: var(--muted); }
.ss-row { margin-bottom: 6px; }
.ss-row input { width: 100%; }
.ss-del { border: 1px solid var(--border); background: transparent; color: var(--red); border-radius: 6px; cursor: pointer; height: 32px; }
.ss-del:hover { background: var(--red); color: #fff; }
.sub-grp { font-size: 11px; padding: 1px 7px; border-radius: 999px; margin-left: 6px; color: #fff; }
.sub-grp.g1 { background: #d97706; }
.sub-grp.g2 { background: #6b7280; }
.sub-grp.g3 { background: #16a34a; }

/* Sub-Status dashboard funnel + table */
.ss-funnel { display: flex; gap: 4px; margin: 10px 0 16px; min-height: 56px; }
.ss-fseg { display: flex; flex-direction: column; justify-content: center; align-items: center;
  border-radius: 8px; color: #fff; padding: 8px 6px; min-width: 60px; text-align: center; overflow: hidden; }
.ss-fseg .ss-fl { font-size: 12px; opacity: .95; }
.ss-fseg .ss-fn { font-size: 15px; font-weight: 700; }
.ss-fseg.g1 { background: #d97706; }
.ss-fseg.g2 { background: #6b7280; }
.ss-fseg.g3 { background: #16a34a; }
.ss-table { width: 100%; border-collapse: collapse; }
.ss-table td { padding: 6px 8px; border-bottom: 1px solid var(--border); font-size: 14px; }
.ss-table .ss-num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.ss-bar-cell { width: 40%; }
.ss-bar { height: 10px; border-radius: 999px; min-width: 2px; }
.ss-bar.g1 { background: #d97706; }
.ss-bar.g2 { background: #6b7280; }
.ss-bar.g3 { background: #16a34a; }

/* Agent Analyze */
.data-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.data-table th, .data-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; }
.data-table th { font-size: 12px; color: var(--muted); font-weight: 600; white-space: nowrap; }
.data-table td.num, .data-table th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
#ag-table tbody tr:hover { background: var(--panel2); }
#ag-detail h4 { margin: 0 0 6px; font-size: 14px; }

/* sortable table headers */
.data-table th[data-agsort] { user-select: none; }
.data-table th[data-agsort]:hover { color: var(--text); }
.data-table th.sorted-asc::after { content: " \2191"; color: var(--green); }
.data-table th.sorted-desc::after { content: " \2193"; color: var(--green); }

/* LLM Prompt editor */
.btn-sm { padding: 3px 10px; font-size: 12px; line-height: 1.6; }
textarea.prompt-ta {
  width: 100%;
  resize: vertical;
  font-family: "Sarabun", ui-sans-serif, system-ui, sans-serif;
  font-size: 13px;
  line-height: 1.55;
}
.prompt-preview {
  margin-top: 12px;
  padding: 12px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  max-height: 420px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.5;
  color: var(--text);
}
