:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --ink: #17212b;
  --muted: #61707d;
  --line: #d7dee3;
  --soft: #f3f6f7;
  --paper: #ffffff;
  --nav: #123c3d;
  --nav-active: #245e5c;
  --teal: #087f75;
  --teal-dark: #06645d;
  --gold: #b97716;
  --red: #b42318;
  --blue: #2563a6;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body { margin: 0; background: var(--soft); color: var(--ink); font-size: 14px; }
button, input, select, textarea { font: inherit; }
a { color: var(--teal-dark); }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 244px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; background: var(--nav); color: #f7ffff; border-right: 1px solid #0a2d2d; }
.brand { display: flex; align-items: center; gap: 10px; min-height: 76px; padding: 16px; color: inherit; text-decoration: none; border-bottom: 1px solid rgba(255,255,255,.12); }
.brand-mark { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 6px; background: #e9f4f1; color: var(--nav); font-weight: 800; }
.brand strong, .brand small { display: block; }
.brand small { margin-top: 3px; color: #b9d2d0; font-size: 11px; }
.navigation { overflow-y: auto; padding: 12px 10px; }
.nav-link { display: block; min-height: 38px; padding: 10px 12px; border-radius: 6px; color: #dbebea; text-decoration: none; font-weight: 650; }
.nav-link:hover { background: rgba(255,255,255,.08); }
.nav-link.active { background: var(--nav-active); color: #fff; box-shadow: inset 3px 0 #8cd3c8; }
.sidebar-footer { margin-top: auto; display: grid; gap: 6px; padding: 16px; border-top: 1px solid rgba(255,255,255,.12); color: #b9d2d0; font-size: 12px; }
.sidebar-footer a { color: #fff; }

.workspace { min-width: 0; }
.topbar { min-height: 86px; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 16px 24px; background: var(--paper); border-bottom: 1px solid var(--line); }
.eyebrow { margin: 0 0 4px; color: var(--teal-dark); font-size: 11px; font-weight: 800; text-transform: uppercase; }
h1, h2, h3, p { letter-spacing: 0; }
h1 { margin: 0; font-size: 24px; line-height: 1.2; }
h2 { margin: 0; font-size: 18px; }
h3 { margin: 0; font-size: 15px; }
.topbar-actions, .inline-actions, .module-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.role-control { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; font-weight: 700; }

.page-content { padding: 22px 24px 40px; }
.metric-grid { display: grid; grid-template-columns: repeat(5, minmax(120px, 1fr)); gap: 10px; margin-bottom: 22px; }
.metric { min-height: 88px; padding: 14px; background: var(--paper); border: 1px solid var(--line); border-radius: 7px; }
.metric span { display: block; color: var(--muted); font-size: 11px; font-weight: 800; text-transform: uppercase; }
.metric strong { display: block; margin-top: 10px; font-size: 25px; }
.section-header, .panel-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 12px; }
.section-header p, .panel-header p { margin: 5px 0 0; color: var(--muted); }
.module-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.module-card { min-height: 148px; display: flex; flex-direction: column; justify-content: space-between; gap: 18px; padding: 16px; background: var(--paper); border: 1px solid var(--line); border-radius: 7px; }
.module-card p { margin: 8px 0 0; color: var(--muted); line-height: 1.5; }
.module-actions a { font-weight: 750; text-decoration: none; }

.button, button { min-height: 38px; border: 1px solid transparent; border-radius: 6px; padding: 8px 13px; cursor: pointer; font-weight: 750; text-decoration: none; }
.button.primary, button.primary { background: var(--teal); color: #fff; }
.button.primary:hover, button.primary:hover { background: var(--teal-dark); }
.button.secondary, button.secondary { background: var(--paper); color: var(--ink); border-color: var(--line); }
.button.danger, button.danger { background: #fff3f1; color: var(--red); border-color: #f2c5bf; }
button:disabled { cursor: not-allowed; opacity: .55; }

.panel { margin-bottom: 16px; padding: 18px; background: var(--paper); border: 1px solid var(--line); border-radius: 7px; }
.split-layout { display: grid; grid-template-columns: minmax(280px, .8fr) minmax(0, 1.4fr); gap: 14px; align-items: start; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.form-stack { display: grid; gap: 12px; }
label { display: grid; gap: 6px; color: #3f4c56; font-size: 12px; font-weight: 750; }
input, select, textarea { width: 100%; min-height: 40px; border: 1px solid #bdc8ce; border-radius: 5px; background: #fff; padding: 8px 10px; color: var(--ink); }
textarea { min-height: 92px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid #9ed8d3; outline-offset: 1px; border-color: var(--teal); }
.full { grid-column: 1 / -1; }
.status { min-height: 20px; color: var(--muted); }
.status.error { color: var(--red); }
.status.success { color: var(--teal-dark); }
.muted { color: var(--muted); }

.data-list { display: grid; gap: 8px; }
.data-row { display: grid; gap: 4px; padding: 12px; background: #fbfcfc; border: 1px solid var(--line); border-radius: 6px; }
.data-row header { display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.data-row p { margin: 0; color: var(--muted); line-height: 1.45; overflow-wrap: anywhere; }
.badge { display: inline-flex; align-items: center; min-height: 24px; border-radius: 999px; padding: 3px 8px; background: #e7f3f1; color: #135f59; font-size: 11px; font-weight: 800; }
.badge.waiting { background: #fff1d6; color: #805514; }
.badge.closed, .badge.rejected { background: #eceff1; color: #56636d; }
.badge.urgent, .badge.open { background: #ffe5e1; color: #9b2c20; }
.code-field { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; align-items: center; }
.code-field input, .code-field textarea { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12px; }
.empty-state { display: grid; place-items: center; min-height: 160px; padding: 24px; border: 1px dashed #bac7cc; border-radius: 6px; color: var(--muted); text-align: center; }

.conversation-layout { display: grid; grid-template-columns: minmax(230px, .75fr) minmax(0, 1.5fr); gap: 12px; }
.conversation-list { max-height: 620px; overflow-y: auto; }
.conversation-button { width: 100%; display: grid; gap: 4px; text-align: left; background: #fff; color: var(--ink); border-color: var(--line); }
.conversation-button.active { border-color: var(--teal); box-shadow: inset 3px 0 var(--teal); }
.conversation-button small { color: var(--muted); font-weight: 500; }
.message-list { min-height: 320px; max-height: 500px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; padding: 12px; background: #f4f7f7; border: 1px solid var(--line); border-radius: 6px; }
.message { align-self: flex-start; max-width: 76%; padding: 10px 12px; background: #fff; border: 1px solid var(--line); border-radius: 6px; }
.message.staff { align-self: flex-end; background: #e7f3f1; border-color: #badbd7; }
.message.internal { align-self: stretch; max-width: none; background: #fff3d8; border-color: #e8ce91; }
.message strong, .message small { display: block; }
.message p { margin: 5px 0; white-space: pre-wrap; }
.message small { color: var(--muted); }
.reply-row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 8px; align-items: end; margin-top: 10px; }
.check-control { display: flex; align-items: center; gap: 7px; min-height: 40px; }
.check-control input { width: 16px; min-height: 16px; }

.toast { position: fixed; z-index: 50; right: 20px; bottom: 20px; max-width: 360px; padding: 12px 14px; border-radius: 6px; background: #17212b; color: #fff; box-shadow: 0 12px 35px rgba(0,0,0,.22); }
.toast.error { background: #841d15; }
.error-page { max-width: 620px; margin: 12vh auto; padding: 24px; background: #fff; border: 1px solid var(--line); }

.public-chat-page { min-height: 100vh; display: grid; place-items: center; padding: 18px; background: #edf3f2; }
.public-chat { width: min(100%, 620px); background: #fff; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.public-chat header { padding: 18px; background: var(--nav); color: #fff; }
.public-chat header h1 { font-size: 20px; }
.public-chat header p { margin: 5px 0 0; color: #c9dcdb; }
.public-chat main { padding: 18px; }
.public-chat .message-list { min-height: 360px; }

.test-results { display: grid; gap: 8px; }
.test-result { display: flex; align-items: flex-start; gap: 10px; padding: 12px; border: 1px solid var(--line); background: #fff; border-radius: 6px; }
.test-result strong { min-width: 54px; color: var(--teal-dark); }
.test-result.fail strong { color: var(--red); }

@media (max-width: 1080px) {
  .metric-grid { grid-template-columns: repeat(3, minmax(120px, 1fr)); }
  .module-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
  .app-shell { display: block; }
  .sidebar { position: static; height: auto; }
  .navigation { display: flex; overflow-x: auto; padding: 8px; }
  .nav-link { flex: 0 0 auto; }
  .sidebar-footer { display: none; }
  .topbar { align-items: flex-start; padding: 14px 16px; }
  .topbar-actions { justify-content: flex-end; }
  .page-content { padding: 16px; }
  .metric-grid, .module-grid, .form-grid, .split-layout, .conversation-layout { grid-template-columns: 1fr; }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .reply-row { grid-template-columns: 1fr; }
}
