:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --ink: #0f172a;
  --slate: #334155;
  --muted: #64748b;
  --border: #e2e8f0;
  --border-light: #f1f5f9;
  --primary: #0284c7;
  --primary-hover: #0369a1;
  --green: #059669;
  --green-bg: #ecfdf5;
  --green-border: #a7f3d0;
  --amber: #d97706;
  --amber-bg: #fffbeb;
  --amber-border: #fde68a;
  --red: #dc2626;
  --red-bg: #fef2f2;
  --red-border: #fecaca;
  --radius: 10px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); }

button, a { -webkit-tap-highlight-color: transparent; }
button { font: inherit; cursor: pointer; transition: background 0.15s, border-color 0.15s, color 0.15s; }
button:disabled { opacity: 0.55; cursor: not-allowed; }
button:focus-visible, a:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
[hidden] { display: none !important; }

/* Top Navigation */
.topbar {
  height: 64px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  gap: 20px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand-logo {
  width: 28px;
  height: 28px;
  border-radius: 6px;
}
.brand strong {
  font-size: 19px;
  letter-spacing: -0.5px;
  font-weight: 700;
  color: var(--ink);
}
.brand-divider {
  height: 18px;
  border-left: 1px solid var(--border);
}
.brand-sub {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 1px;
  color: var(--muted);
}
.nav-status {
  display: flex;
  align-items: center;
  gap: 16px;
}
.ticket-tag {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  font-weight: 600;
  background: var(--border-light);
  border: 1px solid var(--border);
  padding: 4px 10px;
  border-radius: 6px;
  color: var(--slate);
}
.status-live {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 6px;
}
.pulse-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 2px var(--green-bg);
}

/* Buttons */
.button {
  padding: 9px 16px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  font-weight: 600;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  white-space: nowrap;
}
.button:hover:not(:disabled) {
  background: var(--border-light);
}
.button.primary {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}
.button.primary:hover:not(:disabled) {
  background: #1e293b;
}
.button.small {
  font-size: 12px;
  padding: 6px 14px;
}
.text-button {
  border: 0;
  background: transparent;
  font-size: 12px;
  padding: 4px 0;
  color: var(--muted);
  font-weight: 500;
}
.text-button:hover:not(:disabled) {
  color: var(--primary);
}

/* Main Container */
main {
  max-width: 1360px;
  margin: 0 auto;
  padding: 28px 32px 48px;
}

/* Alert Message */
.message {
  background: var(--amber-bg);
  color: #92400e;
  border: 1px solid var(--amber-border);
  border-radius: 8px;
  padding: 12px 18px;
  margin-bottom: 20px;
  font-size: 13px;
  line-height: 1.5;
}

/* Ticket Header */
.ticket-header {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 28px;
  margin-bottom: 24px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}
.ticket-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}
.ticket-meta {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
}
.meta-sep {
  color: #cbd5e1;
}
.ticket-code {
  font-weight: 600;
  color: var(--primary);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.ticket-header h1 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.4px;
  margin: 0 0 6px;
  color: var(--ink);
}
.customer-info {
  font-size: 13px;
  color: var(--muted);
  margin: 0;
}
.customer-info b {
  color: var(--slate);
}

/* Status Pill */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 20px;
  white-space: nowrap;
  background: var(--green-bg);
  color: var(--green);
  border: 1px solid var(--green-border);
}
.pill.neutral {
  background: var(--border-light);
  color: var(--muted);
  border-color: var(--border);
}
.pill.warn {
  background: var(--amber-bg);
  color: var(--amber);
  border-color: var(--amber-border);
}
.pill.blocked {
  background: var(--red-bg);
  color: var(--red);
  border-color: var(--red-border);
}

/* Case Switcher */
.case-switcher {
  display: flex;
  align-items: center;
  gap: 16px;
  padding-top: 16px;
}
.switcher-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.8px;
  color: var(--muted);
  flex-shrink: 0;
}
.case-buttons {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  width: 100%;
}
.case-buttons button {
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 6px;
  padding: 8px 12px;
  text-align: left;
  font-size: 11px;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.case-buttons button span {
  font-size: 12px;
  font-weight: 600;
  color: var(--slate);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.case-buttons button[aria-pressed="true"] {
  background: var(--surface);
  border-color: var(--primary);
  box-shadow: 0 1px 4px rgba(2, 132, 199, 0.12);
  color: var(--primary);
}
.case-buttons button[aria-pressed="true"] span {
  color: var(--ink);
}

/* Workspace Grid */
.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(360px, 1fr);
  gap: 24px;
}

/* Left Panel */
.case-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
  overflow: hidden;
}
.panel-section {
  padding: 24px 28px;
  border-bottom: 1px solid var(--border);
}
.panel-section:last-child {
  border-bottom: 0;
}
.section-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--slate);
  margin: 0 0 16px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Conversation Thread */
.conversation {
  display: flex;
  gap: 12px;
  margin-bottom: 14px;
}
.conversation.internal {
  margin-bottom: 0;
}
.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
}
.avatar.customer {
  background: #e0f2fe;
  color: #0369a1;
}
.avatar.agent {
  background: #fef3c7;
  color: #92400e;
}
.chat-body {
  flex: 1;
}
.speaker {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 4px;
}
.speaker span {
  font-size: 11px;
  font-weight: 400;
  color: var(--muted);
  margin-left: 6px;
}
.bubble {
  font-size: 13px;
  line-height: 1.6;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 0 8px 8px 8px;
  padding: 10px 14px;
  color: var(--slate);
}
.bubble.note {
  background: #fffdf5;
  border-color: #fef08a;
  color: #713f12;
}

/* Order Details / Receipt */
.order-details {
  background: #fafbfc;
}
.receipt {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
}
.receipt-amount-block {
  display: flex;
  flex-direction: column;
}
.small-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.8px;
  color: var(--muted);
}
.receipt strong {
  font-size: 38px;
  font-weight: 700;
  letter-spacing: -1px;
  color: var(--ink);
  margin: 4px 0;
}
.receipt strong span {
  font-size: 24px;
  color: var(--muted);
}
.muted {
  font-size: 12px;
  color: var(--muted);
}
.receipt-meta {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
}
.receipt-meta span {
  display: flex;
  justify-content: space-between;
  gap: 20px;
}
.receipt-meta b {
  color: var(--ink);
  font-weight: 600;
}
.receipt-meta b.highlight {
  color: var(--amber);
}

/* Step Rail */
.step-rail {
  display: flex;
  justify-content: space-between;
  position: relative;
  padding: 10px 0 24px;
}
.step-rail::before {
  content: '';
  position: absolute;
  top: 22px;
  left: 20px;
  right: 20px;
  height: 2px;
  background: var(--border);
  z-index: 1;
}
.step-rail > div {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  padding: 0 8px;
  font-size: 11px;
  color: var(--muted);
  font-weight: 500;
}
.step-rail i {
  font-style: normal;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--surface);
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
}
.step-rail .done {
  color: var(--green);
}
.step-rail .done i {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}
.step-rail .current {
  color: var(--primary);
  font-weight: 600;
}
.step-rail .current i {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

/* Action Execution Card */
.action-card {
  background: #f1f5f9;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 18px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}
.action-card-text .small-label {
  color: var(--primary);
}
.action-card-text p {
  font-size: 13px;
  color: var(--slate);
  margin: 4px 0 0;
  line-height: 1.4;
}
.action-card .button {
  min-width: 170px;
}
.action-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 14px;
}
.action-footer span {
  font-size: 11px;
  color: var(--muted);
}

/* Right Panel Cards */
.side-panel {
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.card-header h3 {
  font-size: 14px;
  font-weight: 700;
  margin: 0;
  color: var(--ink);
  letter-spacing: -0.2px;
}

/* Meta List */
.meta-list {
  margin: 0;
}
.meta-list > div {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px solid var(--border-light);
  font-size: 12px;
}
.meta-list dt {
  color: var(--muted);
  flex-shrink: 0;
}
.meta-list dd {
  margin: 0;
  color: var(--ink);
  text-align: right;
  font-weight: 500;
  word-break: break-all;
}
.meta-list dd code {
  font-size: 11px;
  color: var(--slate);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* Stats Row */
.stats-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  text-align: center;
}
.stats-row > div:first-child {
  border-right: 1px solid var(--border);
}
.stats-row strong {
  display: block;
  font-size: 22px;
  font-weight: 700;
  color: var(--ink);
}
.stats-row span {
  font-size: 11px;
  color: var(--muted);
}

/* Worker Card */
.worker-badge {
  font-size: 11px;
  font-weight: 600;
  background: var(--border-light);
  padding: 3px 8px;
  border-radius: 4px;
  color: var(--slate);
}
.agent-card {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
}
.agent-icon {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  background: #e0f2fe;
  color: #0369a1;
  display: grid;
  place-items: center;
  font-size: 14px;
  font-weight: 700;
  flex-shrink: 0;
}
.agent-card p {
  margin: 0;
  font-size: 12px;
  line-height: 1.5;
  color: var(--slate);
}
.agent-card.offline .agent-icon {
  background: var(--border-light);
  color: var(--muted);
}
.task-id-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 12px;
  font-size: 11px;
}
.task-id-row code {
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* Audit Log */
.audit {
  max-height: 280px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}
.empty-audit {
  padding: 20px;
  font-size: 12px;
  color: var(--muted);
  margin: 0;
  text-align: center;
}
.audit-item {
  display: grid;
  grid-template-columns: 55px 14px 1fr;
  gap: 10px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  align-items: start;
}
.audit-item:last-child {
  border-bottom: 0;
}
.audit-item time {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 10px;
  color: var(--muted);
  padding-top: 2px;
}
.event-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-top: 4px;
  border: 2px solid var(--muted);
}
.event-dot.authority { border-color: var(--primary); }
.event-dot.identity { border-color: #6366f1; }
.event-dot.payment { border-color: var(--green); background: var(--green); }
.event-dot.blocked { border-color: var(--red); background: var(--red); }
.audit-item h4 {
  margin: 0 0 2px;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink);
}
.audit-item p {
  margin: 0;
  font-size: 11px;
  color: var(--muted);
  line-height: 1.4;
}

/* Site Footer */
.site-footer {
  max-width: 1360px;
  margin: 0 auto;
  padding: 20px 32px 32px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--muted);
}

/* Dialog */
dialog {
  border: 1px solid var(--border);
  border-radius: 12px;
  max-width: 420px;
  padding: 24px;
  color: var(--ink);
  background: var(--surface);
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
}
dialog::backdrop {
  background: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(2px);
}
dialog h2 {
  font-size: 18px;
  margin: 0 0 10px;
}
dialog p {
  font-size: 13px;
  line-height: 1.6;
  color: var(--muted);
  margin: 0 0 20px;
}
.dialog-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}

/* Responsive */
@media (max-width: 1024px) {
  .workspace {
    grid-template-columns: 1fr;
  }
}
@media (max-width: 768px) {
  .topbar {
    padding: 0 16px;
  }
  main {
    padding: 16px;
  }
  .case-buttons {
    grid-template-columns: 1fr 1fr;
  }
  .receipt {
    flex-direction: column;
    align-items: flex-start;
  }
  .action-card {
    flex-direction: column;
    align-items: stretch;
  }
}
