:root {
  --bg: #f7f7fb;
  --surface: #ffffff;
  --border: #e6e6ee;
  --border-strong: #d1d1dc;
  --text: #1e1e24;
  --text-muted: #6b6b78;
  --text-faint: #9a9aa8;
  --accent: #5b5fc7;
  --accent-hover: #4a4fb8;
  --accent-soft: #eef0ff;
  --success: #107c10;
  --success-soft: #e6f2e6;
  --danger: #b3261e;
  --danger-soft: #fdecec;
  --hover: #f0f0f6;
  --shadow-sm: 0 1px 2px rgba(20, 20, 40, .04);
  --shadow-md: 0 2px 8px rgba(20, 20, 40, .06);
  --shadow-lg: 0 8px 24px rgba(20, 20, 40, .08);
  --radius: 8px;
  --radius-sm: 5px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, system-ui, sans-serif; font-size: 14px; color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased; }

/* ---------- custom scrollbars ---------- */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(0,0,0,.14); border-radius: 5px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: rgba(0,0,0,.28); background-clip: padding-box; border: 2px solid transparent; }
::-webkit-scrollbar-corner { background: transparent; }

/* ---------- layout ---------- */
#app { display: grid; grid-template-rows: auto auto 1fr; height: 100vh; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 24px; background: var(--surface);
  border-bottom: 1px solid var(--border); box-shadow: var(--shadow-sm);
  gap: 24px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 8px;
  background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center;
}
.brand-title { font-weight: 600; font-size: 14px; letter-spacing: -0.01em; }
.brand-sub { font-size: 12px; color: var(--text-muted); }
.account { font-size: 12px; color: var(--text-muted); text-align: right; }
.account strong { color: var(--text); font-weight: 500; }

/* step indicator */
.steps {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 24px; background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.step-dot {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 5px 12px; border-radius: 999px;
  font-size: 12px; color: var(--text-faint);
  transition: all .2s;
}
.step-dot span {
  width: 20px; height: 20px; border-radius: 999px;
  background: var(--border); color: var(--surface);
  display: grid; place-items: center; font-size: 11px; font-weight: 600;
}
.step-dot.active { color: var(--text); }
.step-dot.active span { background: var(--accent); color: white; }
.step-dot.done { color: var(--text-muted); }
.step-dot.done span { background: var(--success); color: white; }
.step-dot.done span::before { content: '✓'; font-size: 12px; }
.step-dot.done span > * { display: none; }

/* step containers */
.step { padding: 32px; overflow-y: auto; min-height: 0; }
.step[hidden] { display: none !important; }
.center { max-width: 480px; margin: auto; padding: 40px 0; }

/* hero cards (sign in / done / failed) */
.hero-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 40px 32px; text-align: center;
  box-shadow: var(--shadow-md);
}
.hero-card h1 { margin: 0 0 8px; font-size: 22px; font-weight: 600; letter-spacing: -0.01em; }
.hero-card p { margin: 0 0 24px; color: var(--text-muted); }
.hero-card .fine { font-size: 12px; margin: 20px 0 0; color: var(--text-faint); }
.hero-icon {
  width: 56px; height: 56px; margin: 0 auto 16px;
  border-radius: 999px;
  background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center; font-size: 24px;
}
.hero-icon.success { background: var(--success-soft); color: var(--success); font-size: 32px; font-weight: 700; }
.hero-icon.failed { background: var(--danger-soft); color: var(--danger); font-size: 32px; font-weight: 700; }
.cta-row { display: flex; gap: 10px; justify-content: center; margin-top: 8px; flex-wrap: wrap; }

/* buttons */
.btn {
  padding: 8px 16px; font-size: 13px; font-weight: 500;
  border: 1px solid var(--border-strong); background: var(--surface);
  color: var(--text); border-radius: var(--radius-sm); cursor: pointer;
  transition: background .1s, border-color .1s;
  font-family: inherit;
}
.btn:hover:not(:disabled) { background: var(--hover); border-color: var(--text-faint); }
.btn:active:not(:disabled) { background: var(--border); }
.btn.subtle { border-color: transparent; color: var(--text-muted); background: transparent; }
.btn.subtle:hover:not(:disabled) { background: var(--hover); color: var(--text); }
.btn.primary { background: var(--accent); color: white; border-color: var(--accent); }
.btn.primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.big { padding: 11px 22px; font-size: 14px; }
.btn.mini { padding: 3px 10px; font-size: 11px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* pick step */
.pick-shell {
  max-width: 900px; margin: 0 auto; height: 100%;
  display: grid; grid-template-rows: auto 1fr auto; gap: 20px;
}
.pick-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.pick-header h2 { margin: 0 0 4px; font-size: 20px; font-weight: 600; letter-spacing: -0.01em; }
.pick-header p { margin: 0; font-size: 13px; color: var(--text-muted); }
.pick-header-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }

.search-wrap { position: relative; }
.search-wrap svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--text-faint); pointer-events: none; }
.search-wrap input {
  padding: 7px 10px 7px 32px; font-size: 13px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); outline: none; width: 220px; font-family: inherit;
  color: var(--text);
}
.search-wrap input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.chat-list-wrap {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-sm);
  overflow: hidden;
  display: flex; flex-direction: column; min-height: 0;
}
.chat-list { overflow-y: auto; padding: 6px 0; }
.loading { display: flex; align-items: center; gap: 10px; padding: 24px; color: var(--text-muted); font-size: 13px; }
.spinner { width: 16px; height: 16px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 999px; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.section-head {
  padding: 14px 20px 6px; font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .8px; color: var(--text-muted);
  display: flex; justify-content: space-between;
  position: sticky; top: 0; background: var(--surface);
  border-bottom: 1px solid var(--border); z-index: 1;
}
.section-head .count { font-weight: 500; color: var(--text-faint); }

.chat-row {
  display: flex; align-items: center; gap: 14px;
  padding: 9px 20px; cursor: pointer;
  border-left: 3px solid transparent;
}
.chat-row:hover { background: var(--hover); }
.chat-row input[type=checkbox] { flex-shrink: 0; margin: 0; width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }
.chat-row .avatar {
  width: 28px; height: 28px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center; font-size: 11px; font-weight: 600;
  flex-shrink: 0;
}
.chat-row .chat-info { flex: 1; min-width: 0; }
.chat-row .chat-name { font-size: 13px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-row .chat-meta { font-size: 11px; color: var(--text-muted); margin-top: 1px; }
.chat-row.selected { background: var(--accent-soft); border-left-color: var(--accent); }
.chat-row.selected:hover { background: #e4e7ff; }
.chat-row.hidden { display: none; }

.pick-footer {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 18px;
  box-shadow: var(--shadow-sm);
  display: flex; flex-direction: column; gap: 12px;
}
.pick-footer-line { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.pick-footer-line:first-child { justify-content: space-between; }
.pick-footer-line:last-child { justify-content: space-between; }
.folder-widget { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
.folder-widget .label { font-size: 12px; font-weight: 500; color: var(--text-muted); flex-shrink: 0; }
.folder-widget .folder-path {
  font-size: 12px; padding: 5px 10px; background: var(--bg);
  border-radius: var(--radius-sm); flex: 1;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-family: 'Consolas', 'Menlo', monospace;
}
.folder-widget .folder-path.set { color: var(--text); }

.options { position: relative; font-size: 12px; }
.options summary {
  cursor: pointer; color: var(--text-muted); user-select: none;
  padding: 5px 10px; border-radius: var(--radius-sm);
  list-style: none;
  display: inline-flex; align-items: center; gap: 6px;
}
.options summary::-webkit-details-marker { display: none; }
.options summary::after {
  content: '▾'; font-size: 10px; transition: transform .15s;
}
.options[open] summary::after { transform: rotate(180deg); }
.options summary:hover { color: var(--text); background: var(--hover); }
.options[open] summary { color: var(--text); background: var(--hover); }

.options-menu {
  position: absolute; right: 0; bottom: calc(100% + 6px);
  background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 14px; box-shadow: var(--shadow-lg);
  z-index: 10; min-width: 240px; white-space: nowrap;
}
.options-menu label { display: flex; gap: 8px; align-items: center; padding: 5px 0; cursor: pointer; font-size: 13px; color: var(--text); }
.options-menu input { accent-color: var(--accent); }

/* progress step */
.progress-shell { max-width: 700px; margin: 20px auto 0; display: grid; gap: 20px; }
.progress-shell h2 { margin: 0; font-size: 20px; font-weight: 600; }
.progress-shell > p { margin: 0; font-size: 14px; }
.progress-bar-wrap {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow-sm);
}
.progress-bar { height: 8px; background: var(--border); border-radius: 999px; overflow: hidden; }
#progress-fill { height: 100%; background: linear-gradient(90deg, var(--accent) 0%, #7175d8 100%); width: 0%; transition: width .3s ease; }
.progress-labels { display: flex; justify-content: space-between; margin-top: 10px; font-size: 12px; }

/* ---------- browse ---------- */
.step-full { padding: 0; overflow: hidden; display: grid; grid-template-rows: auto 1fr; }
.browse-topbar {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 20px;
  padding: 12px 20px; border-bottom: 1px solid var(--border); background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.browse-title-wrap { text-align: center; min-width: 0; }
.browse-title { font-weight: 600; font-size: 14px; }
.browse-subtitle { font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: 'Consolas', 'Menlo', monospace; }

.browse-grid { display: grid; grid-template-columns: 300px 1fr; overflow: hidden; }

.browse-sidebar { border-right: 1px solid var(--border); background: var(--bg); display: flex; flex-direction: column; overflow: hidden; }
.browse-sidebar-header { padding: 12px 12px 8px; border-bottom: 1px solid var(--border); background: var(--surface); }
.browse-sidebar-header .search-wrap input { width: 100%; }
.browse-conv-list { flex: 1; overflow-y: auto; padding: 6px 0; }

.browse-conv-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; cursor: pointer;
  border-left: 3px solid transparent;
}
.browse-conv-row:hover { background: var(--hover); }
.browse-conv-row.active { background: var(--surface); border-left-color: var(--accent); }
.browse-conv-row .avatar { width: 30px; height: 30px; }
.browse-conv-row .info { flex: 1; min-width: 0; }
.browse-conv-row .name { font-size: 13px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.browse-conv-row .meta { font-size: 11px; color: var(--text-muted); display: flex; gap: 6px; margin-top: 1px; }
.browse-conv-row .meta > * { white-space: nowrap; }
.browse-conv-row .badge { font-size: 10px; color: var(--text-faint); }

.browse-main { display: flex; flex-direction: column; overflow: hidden; background: var(--bg); }
.browse-welcome { margin: auto; text-align: center; padding: 40px; max-width: 400px; }
.browse-welcome h2 { margin: 0 0 6px; font-size: 20px; font-weight: 600; }
.browse-welcome .hero-icon { margin-bottom: 16px; }

.browse-conv { display: flex; flex-direction: column; overflow: hidden; height: 100%; }
.browse-conv-header {
  padding: 14px 24px; border-bottom: 1px solid var(--border);
  background: var(--surface);
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.browse-conv-title { font-weight: 600; font-size: 15px; }
.browse-conv-sub { font-size: 12px; margin-top: 2px; }

.browse-conv-messages { flex: 1; overflow-y: auto; padding: 20px 24px; }

/* messages */
.day-sep {
  text-align: center; margin: 20px 0 12px; font-size: 11px;
  color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: .5px;
}
.day-sep::before, .day-sep::after {
  content: ''; display: inline-block; width: 15%; height: 1px;
  background: var(--border); vertical-align: middle; margin: 0 12px;
}

.msg-group { display: flex; gap: 10px; margin-bottom: 14px; }
.msg-group.hidden { display: none; }
.msg-group.system { opacity: .8; }
.msg-group .avatar {
  width: 32px; height: 32px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center; font-size: 12px; font-weight: 600;
  flex-shrink: 0;
}
.msg-group.system .avatar { background: var(--border); color: var(--text-muted); }

.msg-body { flex: 1; min-width: 0; }
.msg-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 2px; }
.msg-author { font-weight: 600; font-size: 13px; }
.msg-time { font-size: 11px; color: var(--text-muted); }

.msg {
  padding: 8px 12px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); margin-bottom: 4px;
  font-size: 14px; line-height: 1.5; word-wrap: break-word;
  box-shadow: var(--shadow-sm); color: var(--text);
}
.msg.system { background: transparent; border: none; box-shadow: none; padding: 4px 0; color: var(--text-muted); font-style: italic; font-size: 13px; }
.msg p { margin: 0.4em 0; }
.msg p:first-child { margin-top: 0; }
.msg p:last-child { margin-bottom: 0; }
.msg img { max-width: 100%; height: auto; display: block; margin: 6px 0; border-radius: 4px; border: 1px solid var(--border); }
.msg pre, .msg code { font-family: 'Consolas', 'Menlo', monospace; font-size: 13px; }
.msg pre { background: #f4f4f7; padding: 10px; border-radius: 4px; overflow-x: auto; }
.msg blockquote {
  border-left: 3px solid var(--accent); padding: 6px 10px; margin: 6px 0;
  color: var(--text-muted); background: var(--accent-soft);
  border-radius: 0 4px 4px 0;
}
.msg .edited { font-size: 11px; color: var(--text-muted); margin-left: 6px; }

.attachment-list { display: flex; flex-direction: column; gap: 4px; margin-top: 6px; max-width: 520px; }
.attachment {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text); text-decoration: none; cursor: pointer;
  transition: background .1s;
  font-family: inherit; font-size: 13px; width: 100%; text-align: left;
}
.attachment:hover { background: var(--hover); }
.attachment .att-icon { font-size: 22px; flex-shrink: 0; }
.attachment .att-info { flex: 1; min-width: 0; }
.attachment .att-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachment .att-type { font-size: 11px; color: var(--text-muted); margin-top: 1px; }
.attachment.missing { opacity: .55; cursor: not-allowed; }
.attachment.missing::after { content: 'not downloaded'; font-size: 11px; color: var(--text-muted); flex-shrink: 0; }

.reactions { display: flex; gap: 4px; margin-top: 4px; flex-wrap: wrap; }
.reaction { font-size: 12px; padding: 2px 8px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; }

.recording {
  display: flex; flex-direction: column; gap: 6px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 12px; margin-top: 4px; max-width: 640px; box-shadow: var(--shadow-sm);
}
.recording .rec-title { font-weight: 600; font-size: 13px; }
.recording .rec-meta { font-size: 11px; color: var(--text-muted); }
.recording video { width: 100%; max-width: 640px; border-radius: 4px; margin-top: 6px; background: #000; }
.recording .rec-transcript { font-size: 12px; margin-top: 4px; }

.highlight { background: #fff2b8; }

.log-panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.log-header {
  padding: 8px 16px; display: flex; justify-content: space-between; align-items: center;
  font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px;
  border-bottom: 1px solid var(--border);
}
#log {
  background: #1e1e2e; color: #d4d4dc;
  padding: 12px 16px; height: 200px; overflow-y: auto; margin: 0;
  font-family: 'Consolas', 'Menlo', monospace; font-size: 12px; line-height: 1.5;
  white-space: pre-wrap; word-break: break-all;
}
#log.collapsed { display: none; }
#log .warn { color: #e5c07b; }
#log .error { color: #e06c75; }
#log .info { color: #d4d4dc; }
