:root {
  /* Pebble Square palette: corporate blue -> navy/indigo */
  --bg: #f4f6f9;
  --bg-grad: radial-gradient(1200px 420px at 100% -10%, rgba(32,123,200,.12), transparent 60%),
             radial-gradient(1000px 380px at -10% 0%, rgba(40,57,144,.08), transparent 55%);
  --card: #ffffff;
  --ink: #16202e;
  --muted: #6b7688;
  --line: #e3e8ef;
  --soft: #f5f7fa;

  --brand: #207bc8;         /* --main-color */
  --brand-mid: #1656a0;     /* --mid-color */
  --brand-deep: #0b3177;    /* --deep-color */
  --brand-sub: #283990;     /* --sub-color */
  /* aliases kept so existing rules resolve to the brand palette */
  --purple: #207bc8;
  --pink: #1656a0;
  --blue: #207bc8;
  --grad: linear-gradient(135deg, #207bc8, #1656a0);

  /* speakers: blue vs green (distinct people); red is reserved for risk */
  --agent: #207bc8; --agent-bg: #e8f1fb;
  --customer: #0e9f6e; --customer-bg: #e6f6ee;
  --pos: #16a37b; --pos-bg: #e7f7f1;
  --neu: #8a93ab; --neu-bg: #eef1f6;
  --neg: #ef4444; --neg-bg: #fdecec;
  --warn-bg: #fff8e6; --warn-ink: #8a5a00;
  --err-bg: #fdecec; --err-ink: #b42318;

  --shadow: 0 14px 34px rgba(11,49,119,.10);
  --shadow-sm: 0 4px 14px rgba(11,49,119,.07);
  --r: 22px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c1017;
    --bg-grad: radial-gradient(1200px 420px at 100% -10%, rgba(32,123,200,.20), transparent 60%),
               radial-gradient(1000px 380px at -10% 0%, rgba(40,57,144,.14), transparent 55%);
    --card: #141b26; --ink: #e8eef6; --muted: #93a0b5; --line: #26303f; --soft: #1a212d;
    --agent-bg: #12253c; --customer-bg: #102c22;
    --pos-bg: #12302a; --neu-bg: #232c3a; --neg-bg: #3a1d1d;
    --warn-bg: #3a2f14; --warn-ink: #f0c674; --err-bg: #3a1d1d; --err-ink: #f2a7a0;
    --shadow: 0 14px 34px rgba(0,0,0,.45); --shadow-sm: 0 4px 14px rgba(0,0,0,.32);
  }
}

* { box-sizing: border-box; }
body {
  margin: 0; color: var(--ink);
  background: var(--bg-grad), var(--bg); background-attachment: fixed;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, "PingFang SC", "Microsoft YaHei", sans-serif;
  line-height: 1.5;
}

/* Top bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 18px 32px; position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--card) 82%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.ui-lang { display: flex; align-items: center; gap: 7px; flex-shrink: 0; }
.ui-lang .globe { font-size: 16px; }
#ui-language { min-width: auto; padding: 8px 12px; }
.brand { display: flex; align-items: center; gap: 14px; }
.brand-icon {
  width: 42px; height: 42px; border-radius: 13px; display: grid; place-items: center;
  font-size: 20px; background: var(--grad); box-shadow: 0 6px 16px rgba(32,123,200,.35);
}
.topbar h1 { font-size: 19px; font-weight: 800; margin: 0; letter-spacing: -.01em; }

.layout {
  display: grid; gap: 20px; max-width: 1300px; margin: 26px auto; padding: 0 22px;
  grid-template-columns: 268px minmax(0, 1fr);
  grid-template-areas: "sidebar upload" "sidebar results";
  align-items: start;
}
#sidebar { grid-area: sidebar; }
#upload-card { grid-area: upload; }
#results { grid-area: results; }
.sidebar {
  width: 268px; flex-shrink: 0; position: sticky; top: 88px;
  max-height: calc(100vh - 108px); overflow-y: auto;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r);
  padding: 16px; box-shadow: var(--shadow);
}
.side-head { font-weight: 800; font-size: 14px; display: flex; align-items: center; gap: 9px; margin-bottom: 12px; }
@media (max-width: 860px) {
  /* stack: upload (collapsed) first, then history, then results */
  .layout { grid-template-columns: 1fr; grid-template-areas: "upload" "sidebar" "results"; }
  .sidebar { width: 100%; position: static; max-height: 260px; }
}

/* Phone layout */
@media (max-width: 600px) {
  .topbar { padding: 12px 14px; gap: 10px; }
  .brand { flex: 1; min-width: 0; gap: 10px; }
  .brand-icon { width: 36px; height: 36px; font-size: 17px; flex-shrink: 0; }
  .topbar h1 { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .ui-lang { flex-shrink: 0; }
  #ui-language { padding: 7px 8px; font-size: 13px; }

  .layout { margin: 14px auto; padding: 0 12px; gap: 14px; }
  .card { padding: 16px; border-radius: 16px; }
  .sidebar { max-height: 44vh; padding: 13px; }

  .upload-head h2 { font-size: 16px; }
  .upload-head .sub { font-size: 13px; }
  .uploader { padding: 22px 14px; }
  .controls { flex-direction: column; align-items: stretch; gap: 12px; }
  .ctrl { width: 100%; }
  select { min-width: 0; width: 100%; }
  .btn.primary { margin-left: 0; width: 100%; }

  .stat-row { grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; }
  .tile { padding: 12px 14px; border-radius: 14px; }
  .tile .t-value { font-size: 18px; }
  .results-grid { gap: 14px; }
  .card-head { flex-wrap: wrap; gap: 8px; }
  .turn-main { max-width: 86%; }
  .bubble { font-size: 14px; }
  .gauge-wrap { gap: 14px; }
  .summary .value, .summary li { font-size: 14px; }
}

/* Cards */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r);
  padding: 24px; box-shadow: var(--shadow);
}
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.card-head h2, .upload-head h2 { margin: 0; font-size: 17px; font-weight: 800; display: flex; align-items: center; gap: 10px; }
.chip-ico { width: 32px; height: 32px; border-radius: 10px; display: grid; place-items: center; font-size: 16px; }
.ico-chat { background: var(--agent-bg); }
.ico-ai { background: var(--customer-bg); }
.accent-bar { height: 4px; border-radius: 3px; background: var(--grad); margin: 14px 0 16px; opacity: .85; }

/* Upload */
.upload-card { position: relative; overflow: hidden; }
.upload-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.upload-head h2 { font-size: 18px; }
.upload-head .sub { margin: 6px 0 16px; color: var(--muted); font-size: 14px; }
.upload-card .chevron { flex-shrink: 0; font-size: 18px; color: var(--muted); cursor: pointer;
  transition: transform .2s; padding: 2px 6px; user-select: none; display: none; }
.upload-card.collapsible .upload-head { cursor: pointer; }
.upload-card.collapsible .chevron { display: block; }
.upload-card.collapsed .chevron { transform: rotate(180deg); }
.upload-card.collapsed .sub { display: none; }
.upload-card.collapsed h2 { margin-bottom: 0; }
.upload-card.collapsed #upload-body { display: none; }
.uploader {
  border: 2px dashed var(--line); border-radius: 18px; padding: 34px; text-align: center;
  cursor: pointer; transition: border-color .15s, background .15s, transform .1s; background: var(--soft);
}
.uploader:hover, .uploader.drag { border-color: var(--purple); background: color-mix(in srgb, var(--purple) 7%, var(--soft)); }
.up-icon { font-size: 30px; }
.uploader p { margin: 6px 0; }
.hint { color: var(--muted); font-size: 13px; }
.picked { color: var(--purple); font-weight: 700; }

.controls { display: flex; gap: 14px; align-items: flex-end; margin-top: 18px; flex-wrap: wrap; }
.ctrl { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; display: flex; flex-direction: column; gap: 6px; }
select {
  padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--card);
  color: var(--ink); font-size: 14px; font-weight: 600; text-transform: none; letter-spacing: 0; min-width: 190px;
}
select:focus { outline: none; border-color: var(--purple); box-shadow: 0 0 0 3px rgba(32,123,200,.14); }
.btn {
  padding: 12px 22px; border-radius: 13px; border: 1px solid var(--line); background: var(--card);
  color: var(--ink); font-size: 14px; font-weight: 800; cursor: pointer; transition: transform .12s, box-shadow .2s, filter .2s;
}
.btn.primary { background: var(--grad); color: #fff; border: none; box-shadow: 0 8px 20px rgba(32,123,200,.32); margin-left: auto; }
.btn.primary:disabled { opacity: .5; cursor: not-allowed; box-shadow: none; }
.btn:not(:disabled):hover { transform: translateY(-2px); }

.progress { margin-top: 18px; display: flex; gap: 12px; align-items: center; }
.bar { flex: 1; height: 9px; background: var(--line); border-radius: 99px; overflow: hidden; }
.bar-fill { height: 100%; width: 0; background: var(--grad); transition: width .35s ease; }
#stage { font-size: 13px; color: var(--muted); white-space: nowrap; font-weight: 600; }

.banner { padding: 12px 15px; border-radius: 13px; font-size: 14px; }
.banner.error { background: var(--err-bg); color: var(--err-ink); margin-top: 14px; }
.banner.warn { background: var(--warn-bg); color: var(--warn-ink); }

/* KPI tiles */
.stat-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 20px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 16px 18px; box-shadow: var(--shadow-sm); display: flex; flex-direction: column; gap: 6px; }
.tile .t-label { font-size: 11px; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.tile .t-value { font-size: 22px; font-weight: 800; letter-spacing: -.02em; }
.tile .t-ico { position: absolute; }
.tile.accent { background: var(--grad); color: #fff; border: none; }
.tile.accent .t-label { color: rgba(255,255,255,.85); }

/* Results grid */
.results-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 20px; align-items: stretch; }
.summary-card, .transcript-card { display: flex; flex-direction: column; }
/* chat fills the card so there's no empty space below it; scrolls if long */
.transcript-card .chat { flex: 1 1 auto; min-height: 220px; max-height: none; overflow-y: auto; }
.summary-card .summary { flex: 1 1 auto; }
@media (max-width: 980px) { .results-grid { grid-template-columns: 1fr; } .stat-row { grid-template-columns: repeat(2,1fr); } }

/* Player + timeline */
#player { width: 100%; margin-bottom: 4px; }
.timeline-wrap { margin: 14px 0 6px; }
.timeline-label { font-size: 11px; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 6px; }
.timeline { position: relative; height: 22px; background: var(--soft); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.timeline .seg { position: absolute; top: 3px; bottom: 3px; border-radius: 4px; cursor: pointer; opacity: .9; }
.timeline .seg:hover { opacity: 1; outline: 2px solid var(--purple); }
.timeline .seg.pos { background: var(--pos); }
.timeline .seg.neu { background: var(--neu); }
.timeline .seg.neg { background: var(--neg); }
.timeline .cursor { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--purple); box-shadow: 0 0 0 2px rgba(32,123,200,.25); }

/* Chat */
.chat { display: flex; flex-direction: column; gap: 14px; max-height: 60vh; overflow-y: auto; padding: 4px 6px 4px 2px; margin-top: 14px; }
.chat::-webkit-scrollbar { width: 7px; }
.chat::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }
.turn { display: flex; gap: 11px; animation: fade .3s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.turn.customer { flex-direction: row-reverse; }
.avatar { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; color: #fff; font-size: 14px; flex-shrink: 0; box-shadow: var(--shadow-sm); }
.turn.agent .avatar { background: linear-gradient(135deg, #207bc8, #1656a0); }
.turn.customer .avatar { background: linear-gradient(135deg, #0e9f6e, #0a7d55); }
.turn.neutral .avatar { background: linear-gradient(135deg, #6b7688, #283990); }
.turn-main { max-width: 78%; display: flex; flex-direction: column; gap: 4px; }
.turn.customer .turn-main { align-items: flex-end; }
.who { font-size: 12px; color: var(--muted); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.who .name { font-weight: 800; color: var(--ink); }
.who .time { cursor: pointer; color: var(--purple); font-weight: 600; }
.bubble { padding: 11px 14px; border-radius: 16px; font-size: 14.5px; background: var(--soft); cursor: pointer; }
.turn { cursor: pointer; }
.turn.agent .bubble { border-top-left-radius: 5px; background: var(--agent-bg); }
.turn.customer .bubble { border-top-right-radius: 5px; background: var(--customer-bg); }
.turn.neutral .turn-main { max-width: 100%; }
.turn.playing .bubble { outline: 2px solid var(--purple); }

/* emotion chips */
.emos { display: flex; gap: 6px; flex-wrap: wrap; }
.emo { font-size: 11px; padding: 2px 9px; border-radius: 99px; font-weight: 700; white-space: nowrap; }
.emo.sent.pos { background: var(--pos-bg); color: var(--pos); }
.emo.sent.neg { background: var(--neg-bg); color: var(--neg); }
.emo.sent.neu { background: var(--neu-bg); color: var(--muted); }
.emo.voice { background: var(--agent-bg); color: var(--agent); }

/* Gauge */
.gauge-wrap { display: flex; align-items: center; gap: 18px; padding: 6px 4px 16px; }
.gauge-wrap svg { flex-shrink: 0; }
.gauge-meta .g-title { font-size: 11px; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.gauge-meta .g-label { font-size: 20px; font-weight: 800; margin-top: 2px; }
.gauge-meta .g-sub { font-size: 13px; color: var(--muted); margin-top: 2px; }

/* Summary fields */
.summary .field { margin-bottom: 15px; }
.summary .label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 4px; font-weight: 800; }
.summary .value { font-size: 14.5px; }
.summary ul { margin: 4px 0 0; padding-left: 18px; }
.summary li { margin: 4px 0; font-size: 14px; }
.tags { display: flex; flex-wrap: wrap; gap: 7px; }
.tag { font-size: 12px; padding: 4px 11px; border-radius: 99px; background: var(--soft); font-weight: 700; }
.tag.risk { background: var(--neg-bg); color: var(--neg); }
.badge { display: inline-block; padding: 4px 13px; border-radius: 99px; font-size: 13px; font-weight: 800; }
.badge.pos { background: var(--pos-bg); color: var(--pos); }
.badge.neg { background: var(--neg-bg); color: var(--neg); }
.badge.neu { background: var(--neu-bg); color: var(--muted); }
.badge.res-ok { background: var(--pos-bg); color: var(--pos); }
.badge.res-no { background: var(--neg-bg); color: var(--neg); }
.badge.res-follow { background: var(--warn-bg); color: var(--warn-ink); }

.sent-bar { display: flex; height: 9px; border-radius: 99px; overflow: hidden; background: var(--line); margin-bottom: 6px; }
.sent-bar .seg.pos { background: var(--pos); }
.sent-bar .seg.neu { background: var(--neu); }
.sent-bar .seg.neg { background: var(--neg); }

/* History (left sidebar) */
.ico-hist { background: var(--soft); }
.hist-filter { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.hist-filter .flt {
  font-size: 12px; font-weight: 700; padding: 5px 11px; border-radius: 99px;
  border: 1px solid var(--line); background: var(--card); color: var(--muted); cursor: pointer;
  transition: all .12s;
}
.hist-filter .flt:hover { border-color: var(--brand); color: var(--brand); }
.hist-filter .flt.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.history-list { display: flex; flex-direction: column; gap: 4px; }
.hist-row {
  display: flex; flex-direction: column; gap: 3px;
  padding: 10px 11px; border-radius: 12px; cursor: pointer; transition: background .12s;
  border: 1px solid transparent;
}
.hist-row { position: relative; }
.hist-row:hover { background: var(--soft); border-color: var(--line); }
.hist-row.active { background: var(--agent-bg); border-color: var(--agent); }
/* right-click delete menu */
.ctx-menu {
  position: fixed; z-index: 200; background: var(--card); border: 1px solid var(--line);
  border-radius: 10px; box-shadow: var(--shadow); padding: 4px; min-width: 130px;
}
.ctx-item {
  display: flex; align-items: center; gap: 8px; width: 100%; border: none;
  background: transparent; padding: 8px 12px; border-radius: 7px; cursor: pointer;
  font-size: 13px; font-weight: 700; color: var(--neg); text-align: left;
}
.ctx-item:hover { background: var(--neg-bg); }
.hist-row.processing { cursor: default; }
.hist-row.processing .h-meta { color: var(--brand); font-weight: 700; }
.spin {
  display: inline-block; width: 10px; height: 10px; vertical-align: -1px;
  border: 2px solid var(--line); border-top-color: var(--brand); border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spin { animation: none; } }
/* mini indeterminate bar inside a processing history row */
.hbar { grid-column: 1 / -1; height: 3px; border-radius: 99px; background: var(--line); overflow: hidden; margin-top: 2px; }
.hbar-fill { height: 100%; width: 40%; border-radius: 99px; background: var(--brand); animation: indet 1.2s ease-in-out infinite; }
@keyframes indet { 0% { margin-left: -40%; } 100% { margin-left: 100%; } }

/* processing view in the results area */
.proc-view { text-align: center; padding: 48px 24px; }
.proc-view .proc-icon { font-size: 40px; }
.proc-view h2 { margin: 12px 0 4px; font-size: 18px; word-break: break-all; }
.proc-stage { color: var(--brand); font-weight: 700; margin: 6px 0 18px; }
.proc-bar { max-width: 420px; margin: 0 auto 14px; height: 8px; border-radius: 99px; background: var(--line); overflow: hidden; }
.proc-bar-fill { height: 100%; width: 35%; border-radius: 99px; background: var(--grad); animation: indet 1.3s ease-in-out infinite; }

/* live "in call" indicator */
.live-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #ef4444; margin-right: 3px; animation: pulse 1.2s infinite; }
.hist-row.recording .h-meta { color: #ef4444; font-weight: 800; }
.proc-view.live .proc-icon { animation: pulse 1.4s infinite; }
@keyframes pulse { 0% { opacity: 1; transform: scale(1); } 50% { opacity: .3; transform: scale(1.35); } 100% { opacity: 1; transform: scale(1); } }
@media (prefers-reduced-motion: reduce) { .live-dot, .proc-view.live .proc-icon { animation: none; } }
.hist-row .h-file { font-weight: 700; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hist-row .h-meta { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.hist-row .h-res { align-self: flex-start; margin-top: 2px; }

.hidden { display: none !important; }
