:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --border: #e4e9f2;
  --border-strong: #cfd7e6;
  --text: #0f172a;
  --text-secondary: #475569;
  --text-muted: #8492a6;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #eff6ff;
  --success: #059669;
  --success-soft: #ecfdf5;
  --warning: #d97706;
  --warning-soft: #fffbeb;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --purple: #6d28d9;
  --purple-soft: #f5f3ff;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 18px 48px rgba(15, 23, 42, 0.14);
}

[hidden] {
  display: none !important;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--primary);
  text-decoration: none;
}

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

button {
  cursor: pointer;
}

/* Top Bar */
.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.topbar {
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  flex-shrink: 0;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 15px;
  color: var(--text);
}

.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
}

.brand-tag {
  font-size: 12px;
  font-weight: 500;
  color: var(--primary);
  background: var(--primary-soft);
  padding: 2px 8px;
  border-radius: 999px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.ws-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  display: inline-block;
}

.ws-dot.online {
  background: var(--success);
}

.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 13px;
  color: var(--text-secondary);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  white-space: nowrap;
}

.btn:hover:not(:disabled) {
  background: var(--surface-alt);
  border-color: #b7c3d8;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}

.btn-success {
  background: var(--success);
  border-color: var(--success);
  color: #fff;
}

.btn-success:hover:not(:disabled) {
  background: #047857;
}

.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.btn-danger:hover:not(:disabled) {
  background: #b91c1c;
}

.btn-soft-danger {
  background: var(--danger-soft);
  border-color: #fecaca;
  color: var(--danger);
}

.btn-soft-primary {
  background: var(--primary-soft);
  border-color: #bfdbfe;
  color: var(--primary);
}

.btn-sm {
  min-height: 30px;
  padding: 0 10px;
  font-size: 12px;
}

.btn-lg {
  min-height: 42px;
  padding: 0 18px;
  font-size: 14px;
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}

.badge-draft { background: #f1f5f9; color: #475569; }
.badge-pending_accept { background: var(--warning-soft); color: var(--warning); }
.badge-in_progress { background: var(--primary-soft); color: var(--primary); }
.badge-pending_review { background: var(--purple-soft); color: var(--purple); }
.badge-revising { background: #fff7ed; color: #c2410c; }
.badge-completed { background: var(--success-soft); color: var(--success); }
.badge-cancelled { background: #f1f5f9; color: #94a3b8; }
.badge-urgent { background: var(--danger-soft); color: var(--danger); }

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  display: inline-block;
}

.status-online { background: var(--success); }
.status-busy { background: var(--warning); }
.status-offline { background: #94a3b8; }

/* Inputs */
.input,
.select,
.textarea {
  width: 100%;
  padding: 8px 11px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.input:focus,
.select:focus,
.textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.textarea {
  resize: vertical;
  min-height: 76px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 12px;
}

.form-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
}

.form-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

/* 3-Column Desk Layout */
.desk-main {
  flex: 1;
  display: grid;
  grid-template-columns: 310px minmax(0, 1fr) 360px;
  min-height: 0;
  overflow: hidden;
}

.pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
}

.pane:last-child {
  border-right: none;
}

.pane-header {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-shrink: 0;
}

.pane-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.pane-scroll {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

/* Order List */
.filter-bar {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}

.filter-tabs {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.filter-tab {
  padding: 4px 10px;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
}

.filter-tab:hover {
  background: var(--surface-alt);
}

.filter-tab.active {
  background: var(--primary-soft);
  color: var(--primary);
}

.order-item {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.12s;
  position: relative;
}

.order-item:hover {
  background: var(--surface-alt);
}

.order-item.active {
  background: var(--primary-soft);
}

.order-item-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}

.order-item-title {
  font-weight: 600;
  font-size: 13.5px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.order-item-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.order-item-preview {
  font-size: 12px;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.unread-pill {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Chat Area */
.chat-pane {
  background: var(--bg);
}

.chat-header {
  background: var(--surface);
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
}

.chat-header-info {
  min-width: 0;
}

.chat-header-title {
  font-size: 15px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-header-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.chat-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.action-banner {
  background: var(--warning-soft);
  border-bottom: 1px solid #fde68a;
  padding: 10px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
  color: #92400e;
  flex-shrink: 0;
}

.action-banner.review {
  background: var(--purple-soft);
  border-bottom-color: #ddd6fe;
  color: #5b21b6;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.msg-system {
  align-self: center;
  background: #e9eef6;
  color: var(--text-secondary);
  font-size: 12px;
  padding: 4px 12px;
  border-radius: 999px;
  max-width: 85%;
  text-align: center;
}

.msg-row {
  display: flex;
  flex-direction: column;
  max-width: 74%;
  align-self: flex-start;
}

.msg-row.mine {
  align-self: flex-end;
  align-items: flex-end;
}

.msg-meta {
  font-size: 11.5px;
  color: var(--text-muted);
  margin-bottom: 4px;
  display: flex;
  gap: 6px;
}

.msg-bubble {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 9px 13px;
  word-break: break-word;
  box-shadow: var(--shadow-sm);
}

.msg-text {
  white-space: pre-wrap;
  line-height: 1.55;
}

.msg-row.mine .msg-bubble {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.msg-images {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 6px;
}

.msg-img {
  max-width: 220px;
  max-height: 220px;
  border-radius: 8px;
  border: 1px solid var(--border);
  object-fit: cover;
  cursor: pointer;
}

.msg-file-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12.5px;
  color: var(--text);
  margin-top: 6px;
}

.msg-row.mine .msg-file-link {
  background: rgba(255, 255, 255, 0.16);
  border-color: rgba(255, 255, 255, 0.3);
  color: #fff;
}

/* Deliverable Card */
.deliverable-card {
  background: var(--surface);
  border: 1px solid #c7d2fe;
  border-left: 4px solid var(--primary);
  border-radius: 10px;
  padding: 12px 14px;
  box-shadow: var(--shadow-sm);
  min-width: 260px;
  max-width: 420px;
  color: var(--text);
}

.deliverable-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.deliverable-version {
  font-weight: 600;
  color: var(--primary);
  font-size: 13px;
}

.deliverable-files {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 8px;
}

.deliverable-file-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 8px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12.5px;
}

/* Composer */
.chat-composer {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 10px 14px;
  flex-shrink: 0;
}

.composer-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.composer-input-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.composer-input-row textarea {
  flex: 1;
  min-height: 44px;
  max-height: 120px;
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  resize: none;
  outline: none;
}

.composer-input-row textarea:focus {
  border-color: var(--primary);
}

/* Right Detail Pane */
.detail-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  padding: 0 12px;
  gap: 14px;
  flex-shrink: 0;
}

.detail-tab {
  padding: 10px 2px;
  border: none;
  border-bottom: 2px solid transparent;
  background: transparent;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}

.detail-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.detail-body {
  padding: 14px;
}

.info-card {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
  margin-bottom: 12px;
}

.info-card-title {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.kv-grid {
  display: grid;
  grid-template-columns: 74px 1fr;
  row-gap: 6px;
  column-gap: 8px;
  font-size: 12.5px;
}

.kv-label {
  color: var(--text-muted);
}

.bullet-list {
  margin: 0;
  padding-left: 18px;
  font-size: 13px;
  color: var(--text);
}

.bullet-list li {
  margin-bottom: 4px;
}

.missing-box {
  background: var(--warning-soft);
  border: 1px solid #fde68a;
  border-radius: var(--radius-md);
  padding: 10px 12px;
  margin-bottom: 12px;
  font-size: 12.5px;
  color: #92400e;
}

/* Transcript Segments */
.seg-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.seg-item {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s;
}

.seg-item:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.seg-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11.5px;
  margin-bottom: 3px;
}

.seg-speaker {
  font-weight: 600;
  color: var(--primary);
}

.seg-speaker.customer {
  color: var(--success);
}

.seg-time {
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.seg-text {
  font-size: 13px;
  color: var(--text);
}

/* Recommended Tech Card */
.tech-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  margin-bottom: 8px;
  background: var(--surface);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.tech-card:hover {
  border-color: #93c5fd;
}

.tech-card.selected {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.tech-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}

.tech-score {
  font-size: 12px;
  font-weight: 600;
  color: var(--primary);
}

.tech-reason {
  font-size: 12px;
  color: var(--text-secondary);
}

/* Empty State */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--text-muted);
  padding: 32px;
  text-align: center;
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.36);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
}

.modal-box {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 680px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-box.wide {
  max-width: 960px;
}

.modal-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  font-size: 15px;
  font-weight: 600;
}

.modal-close {
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.modal-close:hover {
  background: var(--surface-alt);
  color: var(--text);
}

.modal-body {
  padding: 16px 18px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

/* Recorder Box */
.recorder-panel {
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-md);
  padding: 18px;
  background: var(--surface-alt);
  text-align: center;
}

.recorder-timer {
  font-size: 28px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  margin: 8px 0;
  color: var(--text);
}

.recorder-timer.recording {
  color: var(--danger);
}

.waveform-canvas {
  width: 100%;
  height: 54px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  display: block;
  margin: 10px 0 14px;
}

.recorder-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

/* Pipeline Steps */
.pipeline-banner {
  background: var(--primary-soft);
  border: 1px solid #bfdbfe;
  border-radius: var(--radius-md);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  color: #1e40af;
  font-size: 13px;
}

/* Admin Layout */
.admin-main {
  flex: 1;
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  min-height: 0;
  overflow: hidden;
}

.admin-nav {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.admin-nav-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 13.5px;
  font-weight: 500;
  text-align: left;
}

.admin-nav-btn:hover {
  background: var(--surface-alt);
  color: var(--text);
}

.admin-nav-btn.active {
  background: var(--primary-soft);
  color: var(--primary);
}

.admin-content {
  padding: 20px 24px;
  overflow-y: auto;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
}

.stat-label {
  font-size: 12.5px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.stat-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
}

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

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.panel-head h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th,
.data-table td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.data-table th {
  background: var(--surface-alt);
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 12.5px;
}

/* Toast */
.toast-container {
  position: fixed;
  top: 66px;
  right: 16px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-left: 4px solid var(--primary);
  border-radius: 8px;
  padding: 10px 14px;
  box-shadow: var(--shadow-md);
  font-size: 13px;
  color: var(--text);
  max-width: 340px;
}

.toast.error { border-left-color: var(--danger); }
.toast.success { border-left-color: var(--success); }

/* Lightbox */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.78);
  z-index: 2100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.lightbox img {
  max-width: 92vw;
  max-height: 88vh;
  border-radius: 10px;
}

/* Responsive */
@media (max-width: 1120px) {
  .desk-main {
    grid-template-columns: 260px minmax(0, 1fr) 300px;
  }
}

@media (max-width: 860px) {
  .desk-main {
    grid-template-columns: 1fr;
    overflow-y: auto;
  }
  .pane {
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: 75vh;
  }
  .admin-main {
    grid-template-columns: 1fr;
  }
  .admin-nav {
    flex-direction: row;
    overflow-x: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .form-row-2 {
    grid-template-columns: 1fr;
  }
}
