:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-raised: #ffffff;
  --surface-soft: #fafafa;
  --surface-strong: #f0f1f3;
  --text: #17191f;
  --text-soft: #626875;
  --text-faint: #969ca8;
  --border: #e2e4e9;
  --border-strong: #cfd3da;
  --accent: #ff002f;
  --accent-dark: #d90028;
  --accent-soft: rgba(255, 0, 47, 0.07);
  --green: #137a4b;
  --green-soft: #eaf7f0;
  --amber: #9a5b00;
  --amber-soft: #fff6e4;
  --red: #c62a3b;
  --red-soft: #fff0f2;
  --blue: #2864a5;
  --blue-soft: #edf5ff;
  --shadow: 0 12px 32px rgba(24, 28, 38, 0.08);
}

.dark {
  --bg: #0f0f10;
  --surface: #151517;
  --surface-raised: #1a1a1d;
  --surface-soft: #111113;
  --surface-strong: #232327;
  --text: #f4f4f6;
  --text-soft: #a5a7ae;
  --text-faint: #747780;
  --border: rgba(255, 255, 255, 0.1);
  --border-strong: rgba(255, 255, 255, 0.18);
  --accent-soft: rgba(255, 0, 47, 0.13);
  --green: #6bd4a2;
  --green-soft: rgba(44, 174, 111, 0.12);
  --amber: #f0b45b;
  --amber-soft: rgba(227, 157, 44, 0.12);
  --red: #ff7585;
  --red-soft: rgba(255, 50, 78, 0.12);
  --blue: #84b9f0;
  --blue-soft: rgba(62, 135, 216, 0.12);
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.28);
}

* { box-sizing: border-box; }

html, body, #app { width: 100%; height: 100%; margin: 0; }

html { background: var(--bg); }

body {
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea { font: inherit; }
button { color: inherit; }

button:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 2px solid rgba(255, 0, 47, 0.38);
  outline-offset: 2px;
}

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(0, 0, 0, 0.16); border-radius: 99px; }
.dark ::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.16); }

.boot-screen, .auth-screen {
  min-height: 100%;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 20px;
  padding: 28px;
  text-align: center;
  color: var(--text-soft);
}

.auth-card {
  width: min(440px, calc(100vw - 32px));
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 34px;
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.auth-card h1 { margin: 18px 0 8px; font-size: 24px; color: var(--text); }
.auth-card p { margin: 0 0 22px; line-height: 1.6; }

.minh-mark {
  position: relative;
  width: 44px;
  height: 44px;
  border: 1px solid var(--border-strong);
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--surface);
}

.minh-mark span {
  position: absolute;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
  animation: signal 1.6s ease-in-out infinite;
}
.minh-mark span:nth-child(1) { transform: translate(-9px, 5px); }
.minh-mark span:nth-child(2) { transform: translate(0, -7px); animation-delay: .16s; }
.minh-mark span:nth-child(3) { transform: translate(9px, 5px); animation-delay: .32s; }

@keyframes signal { 0%, 100% { opacity: .35; } 50% { opacity: 1; } }

.app-shell {
  height: 100%;
  display: grid;
  grid-template-rows: 64px minmax(0, 1fr);
  background: var(--bg);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 0 20px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
}

.brand-block, .topbar-actions, .agent-line, .case-person, .row, .button-row {
  display: flex;
  align-items: center;
}

.brand-block { gap: 12px; min-width: 0; }
.brand-block .minh-mark { width: 34px; height: 34px; flex: 0 0 34px; }
.brand-block h1 { margin: 0; font-size: 15px; line-height: 1.2; }
.brand-block p { margin: 3px 0 0; color: var(--text-faint); font-size: 11px; }
.topbar-actions { gap: 8px; }

.status-ribbon {
  display: flex;
  align-items: center;
  gap: 18px;
  min-width: 0;
  padding: 7px 12px;
  border: 1px solid var(--border);
  background: var(--surface-soft);
  border-radius: 9px;
}

.metric { display: flex; align-items: baseline; gap: 6px; white-space: nowrap; }
.metric strong { font-size: 13px; }
.metric span { color: var(--text-faint); font-size: 11px; }

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: 288px minmax(420px, 1fr) 330px;
  gap: 1px;
  background: var(--border);
  overflow: hidden;
}

.pane { min-width: 0; min-height: 0; background: var(--surface); }
.case-pane, .control-pane { display: flex; flex-direction: column; }
.case-main { display: grid; grid-template-rows: auto minmax(0, 1fr); }

.pane-head {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.pane-head h2, .section-title { margin: 0; font-size: 13px; font-weight: 700; }
.pane-head .subtle { margin-top: 5px; }
.subtle { color: var(--text-faint); font-size: 11px; line-height: 1.45; }

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px;
  margin-top: 13px;
  padding: 3px;
  background: var(--surface-strong);
  border-radius: 9px;
}

.tab {
  border: 0;
  border-radius: 7px;
  padding: 7px 8px;
  background: transparent;
  color: var(--text-soft);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}
.tab.active { background: var(--surface-raised); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

.search-wrap { position: relative; margin-top: 10px; }
.search-wrap svg { position: absolute; left: 10px; top: 9px; width: 14px; height: 14px; color: var(--text-faint); }
.search-wrap input { padding-left: 31px; }

input, textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  padding: 9px 11px;
  font-size: 12px;
  transition: border-color .15s ease, background-color .15s ease;
}
input::placeholder, textarea::placeholder { color: var(--text-faint); }
input:focus, textarea:focus { border-color: rgba(255, 0, 47, .42); outline: none; }
textarea { min-height: 90px; resize: vertical; line-height: 1.5; }

.case-list { flex: 1; min-height: 0; overflow: auto; padding: 8px; }
.case-row {
  width: 100%;
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
  padding: 11px 10px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.case-row:hover { background: var(--surface-soft); }
.case-row.active { background: var(--accent-soft); border-color: rgba(255, 0, 47, .18); }

.avatar {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--surface-strong);
  color: var(--text-soft);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}
.case-row.active .avatar { background: var(--accent); color: white; }
.case-row strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.case-row p { margin: 4px 0 0; color: var(--text-soft); font-size: 11px; line-height: 1.35; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.case-row time { color: var(--text-faint); font-size: 9px; white-space: nowrap; }

.case-header {
  padding: 17px 20px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.case-header-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; }
.case-person { gap: 10px; min-width: 0; }
.case-person h2 { margin: 0; font-size: 15px; }
.case-person p { margin: 4px 0 0; color: var(--text-faint); font-size: 10px; }

.stage-track {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  margin-top: 15px;
  position: relative;
}
.stage-track::before { content: ""; position: absolute; left: 5%; right: 5%; top: 5px; height: 1px; background: var(--border-strong); }
.stage {
  position: relative;
  padding-top: 17px;
  color: var(--text-faint);
  text-align: center;
  font-size: 9px;
  font-weight: 600;
}
.stage::before { content: ""; position: absolute; top: 0; left: 50%; width: 11px; height: 11px; margin-left: -5px; border: 2px solid var(--surface); border-radius: 50%; background: var(--border-strong); z-index: 1; }
.stage.done, .stage.current { color: var(--text); }
.stage.done::before { background: var(--text); }
.stage.current::before { background: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.timeline { min-height: 0; overflow: auto; padding: 22px clamp(18px, 4vw, 52px) 32px; background: var(--surface-soft); }
.message { display: grid; grid-template-columns: 25px minmax(0, 1fr); gap: 10px; max-width: 760px; margin: 0 auto 16px; }
.message.outbound { grid-template-columns: minmax(0, 1fr) 25px; }
.message.outbound .message-dot { grid-column: 2; }
.message.outbound .message-body { grid-column: 1; grid-row: 1; justify-self: end; background: var(--surface); border-color: rgba(255, 0, 47, .22); }
.message.internal .message-body, .message.system .message-body { background: var(--amber-soft); border-color: color-mix(in srgb, var(--amber) 28%, transparent); }
.message.system .message-body { background: var(--blue-soft); border-color: color-mix(in srgb, var(--blue) 28%, transparent); }
.message-dot { width: 25px; height: 25px; display: grid; place-items: center; border-radius: 50%; background: var(--surface-strong); color: var(--text-faint); }
.message-dot svg { width: 12px; height: 12px; }
.message-body { max-width: 80%; border: 1px solid var(--border); background: var(--surface); border-radius: 10px; padding: 11px 13px; box-shadow: 0 2px 7px rgba(0,0,0,.025); }
.message-meta { display: flex; justify-content: space-between; gap: 20px; margin-bottom: 6px; color: var(--text-faint); font-size: 9px; }
.message-body p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 12px; line-height: 1.55; }
.attachment-flag { display: inline-flex; align-items: center; gap: 5px; margin-top: 8px; color: var(--blue); font-size: 10px; }
.attachment-flag svg { width: 12px; height: 12px; }

.control-scroll { min-height: 0; overflow: auto; padding: 14px; }
.control-section { padding: 14px 0; border-bottom: 1px solid var(--border); }
.control-section:first-child { padding-top: 0; }
.control-section:last-child { border-bottom: 0; }
.control-section .section-title { display: flex; justify-content: space-between; gap: 8px; align-items: center; margin-bottom: 10px; }
.agent-card { padding: 11px; border: 1px solid var(--border); background: var(--surface-soft); border-radius: 9px; }
.agent-line { justify-content: space-between; gap: 10px; }
.agent-line + .agent-line { margin-top: 8px; }
.agent-line span { color: var(--text-faint); font-size: 10px; }
.agent-line strong { font-size: 10px; text-align: right; overflow: hidden; text-overflow: ellipsis; }
.agent-health { display: inline-flex; align-items: center; gap: 6px; }
.agent-health::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--text-faint); }
.agent-health.idle::before { background: var(--green); }
.agent-health.busy::before { background: var(--accent); animation: signal 1s infinite; }
.agent-health.error::before, .agent-health.offline::before { background: var(--red); }

.field-label { display: block; margin: 10px 0 6px; color: var(--text-soft); font-size: 10px; font-weight: 600; }
.checkbox-row { display: flex; align-items: flex-start; gap: 8px; margin-top: 9px; color: var(--text-soft); font-size: 10px; line-height: 1.4; }
.checkbox-row input { width: 14px; height: 14px; margin: 0; accent-color: var(--accent); }
.button-row { gap: 7px; margin-top: 10px; }
.button-row.wrap { flex-wrap: wrap; }

.btn {
  min-height: 33px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text-soft);
  padding: 7px 11px;
  font-size: 10px;
  font-weight: 600;
  cursor: pointer;
  transition: .15s ease;
}
.btn:hover { border-color: var(--border-strong); color: var(--text); background: var(--surface-soft); }
.btn svg { width: 13px; height: 13px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-dark); }
.btn.danger { color: var(--red); }
.btn:disabled { opacity: .5; cursor: wait; }
.icon-btn { width: 34px; padding: 0; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 1px solid var(--border);
  border-radius: 99px;
  padding: 3px 7px;
  background: var(--surface-soft);
  color: var(--text-soft);
  font-size: 9px;
  font-weight: 600;
}
.badge.active { color: var(--green); border-color: color-mix(in srgb, var(--green) 28%, transparent); background: var(--green-soft); }
.badge.resolved { color: var(--text-faint); }
.badge.queue { color: var(--amber); background: var(--amber-soft); border-color: transparent; }

.note-card { padding: 9px 10px; border-left: 2px solid var(--accent); background: var(--surface-soft); }
.note-card + .note-card { margin-top: 7px; }
.note-card p { margin: 0; color: var(--text-soft); font-size: 10px; line-height: 1.45; white-space: pre-wrap; }
.note-card small { display: block; margin-top: 6px; color: var(--text-faint); font-size: 8px; }

.empty-state { min-height: 180px; display: grid; place-content: center; justify-items: center; padding: 28px; text-align: center; color: var(--text-faint); }
.empty-state svg { width: 28px; height: 28px; margin-bottom: 9px; }
.empty-state strong { color: var(--text-soft); font-size: 12px; }
.empty-state p { max-width: 270px; margin: 6px 0 0; font-size: 10px; line-height: 1.5; }

.toast-root { position: fixed; right: 18px; bottom: 18px; z-index: 100; display: grid; gap: 8px; }
.toast { max-width: 360px; padding: 11px 13px; border: 1px solid var(--border); border-left: 3px solid var(--green); border-radius: 8px; background: var(--surface-raised); box-shadow: var(--shadow); font-size: 11px; animation: toast-in .2s ease; }
.toast.error { border-left-color: var(--red); }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

.mobile-control-toggle { display: none; }

@media (max-width: 1120px) {
  .workspace { grid-template-columns: 255px minmax(400px, 1fr); }
  .control-pane { position: fixed; z-index: 30; top: 64px; right: 0; bottom: 0; width: min(360px, 92vw); border-left: 1px solid var(--border); box-shadow: var(--shadow); transform: translateX(102%); transition: transform .2s ease; }
  .control-pane.open { transform: translateX(0); }
  .mobile-control-toggle { display: inline-flex; }
  .status-ribbon { display: none; }
}

@media (max-width: 760px) {
  .app-shell { grid-template-rows: 58px minmax(0, 1fr); }
  .topbar { padding: 0 12px; }
  .brand-block p { display: none; }
  .workspace { grid-template-columns: 1fr; }
  .case-pane { display: none; }
  .case-pane.mobile-open { display: flex; position: fixed; inset: 58px 0 0; z-index: 25; }
  .case-main { min-width: 0; }
  .case-header { padding: 13px 14px; }
  .stage { font-size: 0; }
  .stage-track { margin-top: 10px; }
  .timeline { padding: 16px 12px 28px; }
  .message-body { max-width: 92%; }
  .control-pane { top: 58px; }
  .mobile-case-toggle { display: inline-flex !important; }
}

.mobile-case-toggle { display: none; }

