:root {
  color-scheme: light;
  --navy: #101b32;
  --navy-2: #172643;
  --blue: #2f80ed;
  --blue-soft: #eaf3ff;
  --orange: #f59e0b;
  --ink: #172033;
  --muted: #697386;
  --line: #dfe5ed;
  --surface: #ffffff;
  --canvas: #f3f6fa;
  --success: #137a55;
  --danger: #b42318;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--canvas); color: var(--ink); font-size: 16px; }
button, input, textarea { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 260px 1fr; }
.sidebar { background: var(--navy); color: white; padding: 24px 18px; display: flex; flex-direction: column; }
.brand { display: flex; align-items: center; gap: 12px; padding: 0 8px 28px; border-bottom: 1px solid rgba(255,255,255,.12); }
.brand-mark { width: 42px; height: 42px; display: grid; place-items: center; background: var(--blue); border-radius: 12px; font-weight: 800; font-size: 1.25rem; }
.brand strong, .employee strong, .mode-card strong { display: block; }
.brand small, .employee small, .mode-card small { display: block; color: #aebad0; margin-top: 2px; }
nav { display: grid; gap: 8px; margin-top: 26px; }
.nav-item { border: 0; color: #d7deec; background: transparent; display: flex; justify-content: space-between; align-items: center; padding: 13px 14px; border-radius: 10px; text-align: left; }
.nav-item:hover, .nav-item.active { color: white; background: var(--navy-2); }
.count { min-width: 26px; padding: 3px 8px; border-radius: 999px; background: rgba(255,255,255,.12); text-align: center; font-size: .8rem; }
.nav-item.active .count { background: var(--blue); }
.mode-card { margin-top: auto; display: flex; gap: 10px; align-items: center; padding: 14px; background: rgba(255,255,255,.06); border-radius: 12px; }
.mode-dot { width: 9px; height: 9px; background: #38d39f; border-radius: 50%; box-shadow: 0 0 0 4px rgba(56,211,159,.12); }

main { min-width: 0; }
.topbar { min-height: 92px; background: white; border-bottom: 1px solid var(--line); padding: 20px 32px; display: flex; align-items: center; justify-content: space-between; }
.topbar h1 { margin: 2px 0 0; font-size: 1.55rem; letter-spacing: -.02em; }
.eyebrow { margin: 0; font-size: .75rem; color: var(--blue); font-weight: 800; letter-spacing: .12em; }
.employee { display: flex; align-items: center; gap: 10px; }
.topbar-actions { display: flex; align-items: center; gap: 18px; }
.notification-button { border: 1px solid var(--line); background: white; color: var(--ink); border-radius: 10px; padding: 9px 12px; font-weight: 700; }
.notification-button:hover { border-color: #aac8ee; background: var(--blue-soft); }
.message-button { border: 1px solid var(--blue); background: var(--blue-soft); color: #155db5; border-radius: 10px; padding: 9px 12px; font-weight: 750; }
.message-button:hover { background: #dcecff; }
.message-button b { display: inline-grid; min-width: 22px; height: 22px; padding: 0 6px; margin-left: 5px; place-items: center; border-radius: 999px; background: var(--blue); color: white; font-size: .75rem; }
.employee > span { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; background: var(--blue-soft); color: var(--blue); font-weight: 800; }
.employee small { color: var(--muted); }

.workspace { padding: 26px 32px 40px; display: grid; grid-template-columns: minmax(280px, 360px) minmax(520px, 1fr); gap: 22px; align-items: start; }
.queue-column, .detail-card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; box-shadow: 0 8px 28px rgba(16,27,50,.06); }
.queue-column { overflow: hidden; }
.queue-heading { padding: 16px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; font-weight: 750; }
.icon-button { border: 1px solid var(--line); background: white; border-radius: 8px; width: 34px; height: 34px; color: var(--muted); }
.question-list { display: grid; }
.runtime-strip { margin: 0 28px 18px; padding: 12px 16px; display: grid; grid-template-columns: minmax(220px, 1fr) repeat(3, minmax(105px, auto)) 38px; gap: 18px; align-items: center; background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 4px 18px rgba(16,27,50,.05); }
.finance-strip { margin: 18px 28px 10px; padding: 11px 16px; display: flex; gap: 28px; align-items: center; background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 4px 18px rgba(16,27,50,.05); }
.finance-strip > div { display: grid; grid-template-columns: auto auto; column-gap: 10px; align-items: baseline; }
.finance-strip small { grid-column: 1 / -1; color: var(--muted); }
.finance-strip span { color: var(--muted); font-size: .86rem; }
.finance-strip .secondary-button { margin-left: auto; padding: 8px 12px; }
.finance-warning strong, .finance-warning span { color: var(--danger) !important; }
.runtime-strip > div:first-child { display: grid; grid-template-columns: 12px 1fr; column-gap: 9px; align-items: center; }
.runtime-strip > div:first-child small { grid-column: 2; color: var(--muted); }
.runtime-dot { width: 10px; height: 10px; border-radius: 50%; background: #28a66a; box-shadow: 0 0 0 4px rgba(40,166,106,.12); }
.runtime-dot.offline { background: #dc5b5b; box-shadow: 0 0 0 4px rgba(220,91,91,.12); }
.runtime-service { border-left: 1px solid var(--line); padding-left: 18px; display: flex; flex-direction: column; }
.runtime-service small { color: var(--muted); }
@media (max-width: 980px) { .runtime-strip { grid-template-columns: 1fr 1fr; } .runtime-service { border-left: 0; padding-left: 0; } }
.question-row { border: 0; border-bottom: 1px solid var(--line); background: white; text-align: left; padding: 17px 18px; }
.question-row:last-child { border-bottom: 0; }
.question-row:hover, .question-row.active { background: #f7faff; box-shadow: inset 3px 0 var(--blue); }
.question-row .meta { display: flex; justify-content: space-between; color: var(--muted); font-size: .8rem; margin-bottom: 7px; }
.question-row strong { display: block; line-height: 1.35; }
.question-row p { margin: 6px 0 0; color: var(--muted); font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.detail-card { min-height: 640px; padding: 24px; }
.detail-head { display: flex; justify-content: space-between; gap: 18px; align-items: flex-start; padding-bottom: 18px; border-bottom: 1px solid var(--line); }
.detail-head h2 { margin: 4px 0 7px; font-size: 1.4rem; }
.detail-head p { margin: 0; color: var(--muted); }
.status { flex: none; display: inline-flex; align-items: center; gap: 7px; padding: 7px 11px; border-radius: 999px; font-size: .82rem; font-weight: 750; background: #fff7e6; color: #9a5a00; }
.status.answered { background: #e9f8f1; color: var(--success); }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.source-strip { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 12px; margin: 18px 0; }
.source-cell { padding: 13px 14px; background: #f7f9fc; border-radius: 10px; }
.source-cell small { display: block; color: var(--muted); margin-bottom: 4px; }
.context-box { border-left: 3px solid var(--blue); background: var(--blue-soft); padding: 14px 16px; border-radius: 0 10px 10px 0; line-height: 1.5; }
.section-title { margin: 24px 0 10px; font-size: 1rem; }
.product-table { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.product-head, .product-row { display: grid; grid-template-columns: minmax(125px,.8fr) 80px minmax(260px,1.7fr); gap: 12px; align-items: center; padding: 12px 14px; }
.product-head { background: #f7f9fc; color: var(--muted); font-size: .82rem; font-weight: 700; }
.product-row + .product-row { border-top: 1px solid var(--line); }
.article { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-weight: 750; }
.qty { color: var(--muted); }
.recognized a { color: var(--blue); font-weight: 650; text-decoration: none; }
.recognized a:hover { text-decoration: underline; }
.recognized small { color: var(--success); display: block; margin-top: 4px; }
.link-input, .comment-input { width: 100%; border: 1px solid #b9c4d3; border-radius: 9px; padding: 10px 12px; color: var(--ink); background: white; }
.link-input:focus, .comment-input:focus { outline: 3px solid rgba(47,128,237,.16); border-color: var(--blue); }
.field-hint { color: var(--muted); display: block; margin-top: 5px; font-size: .78rem; }
.comment-input { min-height: 92px; resize: vertical; line-height: 1.45; }
.actions { margin-top: 18px; display: flex; justify-content: flex-end; gap: 10px; }
.primary-button, .secondary-button { border-radius: 10px; padding: 11px 16px; font-weight: 750; }
.primary-button { border: 1px solid var(--blue); background: var(--blue); color: white; }
.primary-button:hover { background: #236fd1; }
.secondary-button { border: 1px solid var(--line); background: white; color: var(--ink); }
.answer-options { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 10px; }
.answer-option.active { border-color: var(--primary); background: #eef4ff; color: var(--primary); }
.answer-summary { margin-top: 20px; border: 1px solid #bfe7d4; background: #f0fbf6; border-radius: 12px; padding: 16px; }
.answer-summary strong { display: block; color: var(--success); margin-bottom: 8px; }
.answer-summary a { color: var(--blue); word-break: break-all; }
.history { margin-top: 24px; border-top: 1px solid var(--line); padding-top: 16px; }
.history-item { display: flex; gap: 10px; color: var(--muted); padding: 7px 0; font-size: .86rem; }
.history-mark { width: 8px; height: 8px; margin-top: 5px; background: #9eacc0; border-radius: 50%; flex: none; }
.empty-state { min-height: 560px; display: grid; place-content: center; justify-items: center; text-align: center; color: var(--muted); }
.empty-state h2 { color: var(--ink); margin: 12px 0 4px; }
.empty-state p { max-width: 390px; line-height: 1.5; }
.empty-icon { width: 52px; height: 52px; border-radius: 14px; display: grid; place-items: center; background: var(--blue-soft); color: var(--blue); font-size: 1.5rem; font-weight: 800; }
.toast { position: fixed; right: 24px; bottom: 24px; max-width: 420px; padding: 13px 16px; border-radius: 10px; color: white; background: var(--navy); box-shadow: 0 12px 34px rgba(0,0,0,.2); transform: translateY(20px); opacity: 0; pointer-events: none; transition: .2s ease; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: var(--danger); }
.message-dialog { width: min(760px, calc(100vw - 32px)); max-height: calc(100vh - 40px); padding: 0; border: 0; border-radius: 18px; color: var(--ink); box-shadow: 0 26px 80px rgba(16,27,50,.28); }
.message-dialog::backdrop { background: rgba(8,17,34,.58); backdrop-filter: blur(3px); }
.dialog-head { display: flex; justify-content: space-between; align-items: flex-start; padding: 22px 24px 14px; border-bottom: 1px solid var(--line); }
.dialog-head h2 { margin: 3px 0 0; }
.dialog-intro { margin: 18px 24px 0; color: var(--muted); line-height: 1.5; }
.operator-form { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; padding: 20px 24px; }
.operator-form label { display: grid; gap: 6px; font-size: .86rem; font-weight: 700; }
.operator-form input, .operator-form select, .operator-form textarea { width: 100%; border: 1px solid #b9c4d3; border-radius: 9px; padding: 10px 11px; background: white; color: var(--ink); font: inherit; }
.operator-form textarea { min-height: 94px; resize: vertical; line-height: 1.45; }
.operator-form input:focus, .operator-form select:focus, .operator-form textarea:focus { outline: 3px solid rgba(47,128,237,.16); border-color: var(--blue); }
.full-field, .dialog-actions { grid-column: 1 / -1; }
.dialog-actions { display: flex; justify-content: flex-end; }
.operator-messages-section { border-top: 1px solid var(--line); padding: 18px 24px 24px; }
.operator-messages-section h3 { margin: 0 0 10px; }
.operator-message-card { display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: start; padding: 13px; border: 1px solid var(--line); border-radius: 11px; background: #f8fafc; }
.operator-message-card + .operator-message-card { margin-top: 9px; }
.service-badge { min-width: 48px; padding: 6px 8px; border-radius: 8px; background: #fff0d6; color: #9a5a00; font-weight: 800; text-align: center; }
.operator-message-card p { margin: 0 0 5px; line-height: 1.4; }
.operator-message-card small { color: var(--muted); }
.resolve-button { border: 1px solid #aedbc7; color: var(--success); background: #edfaf4; border-radius: 8px; padding: 8px 10px; font-weight: 700; }
.empty-messages { color: var(--muted); padding: 12px 0; }

.auth-overlay { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 20px; background: linear-gradient(145deg, #0c1830, #172b50); }
.auth-card { width: min(420px, 100%); padding: 28px; border-radius: 18px; background: white; box-shadow: 0 30px 90px rgba(0,0,0,.35); }
.auth-brand { display: flex; gap: 12px; align-items: center; margin-bottom: 24px; }
.auth-brand strong, .auth-brand small { display: block; }
.auth-brand small { color: var(--muted); margin-top: 3px; }
.auth-card form { display: grid; gap: 15px; }
.auth-card label { display: grid; gap: 6px; font-weight: 700; font-size: .88rem; }
.auth-card input { border: 1px solid #b9c4d3; border-radius: 9px; padding: 11px 12px; }
.auth-card .primary-button { margin-top: 4px; }

.admin-tabs { display: flex; gap: 8px; padding: 16px 24px 0; }
.admin-tabs .active { border-color: var(--blue); color: var(--blue); background: var(--blue-soft); }
.admin-panel { max-height: 68vh; overflow: auto; }
.admin-list { padding: 0 24px 24px; display: grid; gap: 8px; }
.admin-row { display: grid; grid-template-columns: minmax(200px,1fr) auto auto auto; gap: 10px; align-items: center; padding: 12px; border: 1px solid var(--line); border-radius: 10px; }
.admin-row.disabled { opacity: .65; background: #f6f7f9; }
.admin-row small { display: block; color: var(--muted); margin-top: 3px; }
.admin-row .secondary-button { padding: 7px 10px; }
.permissions { border: 1px solid var(--line); border-radius: 10px; display: flex; flex-wrap: wrap; gap: 14px; padding: 12px; }
.permissions legend { font-weight: 700; }
.permissions label { display: flex; grid-template-columns: auto 1fr; align-items: center; }
.permissions input { width: auto; }

@media (max-width: 980px) {
  .app-shell { grid-template-columns: 86px 1fr; }
  .brand div, .mode-card div, .nav-item span:first-child { display: none; }
  .brand { justify-content: center; padding-inline: 0; }
  .nav-item { justify-content: center; }
  .mode-card { justify-content: center; }
  .workspace { grid-template-columns: 1fr; }
  .question-list { grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); }
  .question-row { border-right: 1px solid var(--line); }
}

@media (max-width: 680px) {
  .app-shell { display: block; }
  .sidebar { padding: 12px 16px; flex-direction: row; align-items: center; gap: 12px; }
  .brand { border: 0; padding: 0; }
  .brand-mark { width: 38px; height: 38px; }
  .sidebar nav { margin: 0; display: flex; }
  .mode-card { display: none; }
  .topbar { padding: 16px 18px; }
  .employee div { display: none; }
  .notification-button { font-size: 0; padding: 9px 11px; }
  .notification-button span { font-size: 1rem; }
  .message-button { font-size: 0; padding: 9px 11px; }
  .message-button span, .message-button b { font-size: .75rem; }
  .operator-form { grid-template-columns: 1fr; }
  .operator-form > *, .full-field, .dialog-actions { grid-column: 1; }
  .workspace { padding: 16px; }
  .detail-card { padding: 18px; }
  .source-strip { grid-template-columns: 1fr; }
  .product-head { display: none; }
  .product-row { grid-template-columns: 1fr 50px; }
  .product-row > :last-child { grid-column: 1 / -1; }
  .finance-strip { margin: 12px 16px; align-items: stretch; flex-direction: column; gap: 10px; }
  .admin-row { grid-template-columns: 1fr auto; }
}
