:root {
  --ink: #17222e;
  --muted: #64717e;
  --line: #dce2e7;
  --soft: #f4f6f7;
  --paper: #ffffff;
  --brand: #087f5b;
  --brand-dark: #056647;
  --accent: #d99a18;
  --danger: #b42318;
  --shadow: 0 12px 32px rgba(20, 36, 48, 0.08);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  color: var(--ink);
  background: var(--soft);
}

* { box-sizing: border-box; letter-spacing: 0; }
[hidden] { display: none !important; }
body { margin: 0; min-height: 100vh; background: var(--soft); }
button, input, select, textarea { font: inherit; }
button, select, a { -webkit-tap-highlight-color: transparent; }

.app-shell { display: grid; grid-template-columns: 216px minmax(330px, 390px) minmax(0, 1fr); min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 20px 14px; background: #132b29; color: #fff; }
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px 22px; border-bottom: 1px solid rgba(255,255,255,.12); }
.brand strong, .brand span { display: block; }
.brand strong { font-size: 15px; }
.brand span { margin-top: 2px; color: #a9c5bf; font-size: 12px; }
.brand-mark { display: grid; place-items: center; width: 48px; height: 48px; background: var(--brand); color: #fff; font-weight: 800; border-radius: 6px; }
.brand-mark.compact { width: 36px; height: 36px; flex: 0 0 36px; }
.area-nav { display: grid; gap: 4px; margin-top: 18px; }
.area-button { width: 100%; min-height: 42px; display: flex; align-items: center; gap: 10px; padding: 0 10px; color: #c7d8d5; border: 0; background: transparent; border-radius: 5px; text-align: left; cursor: pointer; }
.area-button:hover { background: rgba(255,255,255,.07); color: #fff; }
.area-button.active { color: #fff; background: #087f5b; }
.area-button svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.sidebar-footer { margin-top: auto; padding: 16px 8px 0; border-top: 1px solid rgba(255,255,255,.12); }
.user-chip strong, .user-chip span { display: block; overflow: hidden; text-overflow: ellipsis; }
.user-chip strong { font-size: 13px; white-space: nowrap; }
.user-chip span { margin-top: 4px; color: #a9c5bf; font-size: 11px; white-space: nowrap; }
.logout { display: inline-block; margin-top: 12px; color: #d7e6e3; font-size: 12px; text-decoration: none; }

.queue-panel { height: 100vh; display: flex; flex-direction: column; background: #f8f9fa; border-right: 1px solid var(--line); overflow: hidden; }
.queue-header { min-height: 92px; display: flex; align-items: center; justify-content: space-between; padding: 18px 18px 12px; }
.eyebrow { margin: 0 0 4px; color: var(--brand); font-size: 11px; font-weight: 800; text-transform: uppercase; }
.queue-header h1 { margin: 0; font-size: 20px; line-height: 1.2; }
.icon-button { width: 38px; height: 38px; display: grid; place-items: center; flex: 0 0 38px; border: 1px solid var(--line); background: var(--paper); border-radius: 5px; color: var(--ink); cursor: pointer; }
.icon-button:hover { border-color: #aab6bf; }
.icon-button svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-button.loading svg { animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.filters { padding: 0 18px 12px; border-bottom: 1px solid var(--line); }
.search-box { height: 40px; display: flex; align-items: center; gap: 8px; padding: 0 11px; border: 1px solid #cfd7dd; background: var(--paper); border-radius: 5px; }
.search-box:focus-within { border-color: var(--brand); box-shadow: 0 0 0 2px rgba(8,127,91,.12); }
.search-box svg { width: 17px; height: 17px; fill: none; stroke: var(--muted); stroke-width: 2; }
.search-box input { min-width: 0; width: 100%; border: 0; outline: 0; background: transparent; color: var(--ink); }
.filter-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.filter-row select { min-width: 0; width: 100%; height: 34px; padding: 0 8px; border: 1px solid #cfd7dd; background: var(--paper); border-radius: 5px; color: var(--ink); font-size: 12px; }
.toggle { grid-column: 1 / -1; display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; cursor: pointer; }
.toggle input { accent-color: var(--brand); }
.queue-count { min-height: 35px; padding: 10px 18px 7px; color: var(--muted); font-size: 12px; }
.ticket-list { min-height: 0; overflow-y: auto; padding: 0 10px 18px; }
.ticket-item { width: 100%; display: block; padding: 12px; border: 1px solid transparent; border-bottom-color: var(--line); background: transparent; color: var(--ink); text-align: left; cursor: pointer; }
.ticket-item:hover { background: #fff; }
.ticket-item.active { border-color: #a8d2c5; background: #fff; box-shadow: 0 2px 10px rgba(20,36,48,.05); border-radius: 5px; }
.ticket-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.ticket-id { color: var(--brand); font-size: 12px; font-weight: 800; }
.ticket-time { color: var(--muted); font-size: 11px; white-space: nowrap; }
.ticket-subject { margin: 6px 0 9px; display: -webkit-box; overflow: hidden; font-size: 13px; font-weight: 650; line-height: 1.35; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.ticket-bottom { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.status-badge { max-width: 72%; overflow: hidden; padding: 4px 6px; background: #e8f3ef; color: #11694f; border-radius: 4px; font-size: 10px; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.ticket-owner { min-width: 0; overflow: hidden; color: var(--muted); font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }

.detail-panel { min-width: 0; height: 100vh; overflow-y: auto; background: var(--paper); }
.empty-state { min-height: 100%; display: grid; place-content: center; justify-items: center; padding: 32px; color: var(--muted); text-align: center; }
.empty-state svg { width: 42px; height: 42px; fill: none; stroke: #98a7b2; stroke-width: 1.5; }
.empty-state h2 { margin: 14px 0 4px; color: var(--ink); font-size: 18px; }
.empty-state p { margin: 0; font-size: 13px; }
.detail-loading { padding: 28px; color: var(--muted); }
.detail-header { position: sticky; top: 0; z-index: 5; padding: 20px 26px 0; border-bottom: 1px solid var(--line); background: rgba(255,255,255,.97); backdrop-filter: blur(8px); }
.detail-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.detail-heading h2 { margin: 3px 0 8px; max-width: 850px; font-size: 22px; line-height: 1.25; }
.detail-meta { display: flex; flex-wrap: wrap; gap: 14px; color: var(--muted); font-size: 12px; }
.detail-status { min-width: 190px; }
.detail-status select { width: 100%; height: 38px; padding: 0 9px; border: 1px solid #cfd7dd; background: var(--paper); border-radius: 5px; font-size: 12px; }
.detail-status button { width: 100%; margin-top: 6px; }
.tabs { display: flex; gap: 18px; margin-top: 18px; }
.tab-button { padding: 0 0 11px; border: 0; border-bottom: 2px solid transparent; background: transparent; color: var(--muted); font-size: 12px; font-weight: 700; cursor: pointer; }
.tab-button.active { border-bottom-color: var(--brand); color: var(--brand); }
.detail-content { padding: 22px 26px 50px; }
.section { margin-bottom: 28px; }
.section-title { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.section-title h3 { margin: 0; font-size: 14px; }
.data-grid { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 1px; overflow: hidden; border: 1px solid var(--line); background: var(--line); border-radius: 5px; }
.data-cell { min-width: 0; padding: 11px 12px; background: var(--paper); }
.data-cell dt { margin-bottom: 5px; color: var(--muted); font-size: 10px; font-weight: 700; text-transform: uppercase; }
.data-cell dd { margin: 0; overflow-wrap: anywhere; font-size: 12px; line-height: 1.4; }
.field-group { margin-bottom: 18px; }
.field-group h3 { margin: 0 0 8px; padding-bottom: 7px; border-bottom: 1px solid var(--line); font-size: 13px; }
.line-label { margin: 12px 0 6px; color: var(--brand); font-size: 11px; font-weight: 800; }
.timeline { position: relative; display: grid; gap: 12px; }
.action { padding: 13px 14px; border: 1px solid var(--line); border-left: 3px solid #aab6bf; border-radius: 5px; }
.action.internal { border-left-color: var(--accent); background: #fffdf7; }
.action-header { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.action-header strong { font-size: 12px; }
.action-header span { color: var(--muted); font-size: 11px; white-space: nowrap; }
.action-text { color: #34424e; font-size: 12px; line-height: 1.55; white-space: pre-wrap; overflow-wrap: anywhere; }
.attachments { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.attachment { display: inline-flex; align-items: center; gap: 5px; max-width: 100%; padding: 6px 8px; border: 1px solid var(--line); border-radius: 4px; color: var(--brand-dark); font-size: 11px; text-decoration: none; }
.attachment span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.note-form { padding: 14px; border: 1px solid var(--line); background: var(--soft); border-radius: 5px; }
.note-form textarea { width: 100%; min-height: 92px; resize: vertical; padding: 10px; border: 1px solid #cfd7dd; border-radius: 5px; outline: 0; }
.note-form textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 2px rgba(8,127,91,.12); }
.form-actions { display: flex; justify-content: flex-end; margin-top: 8px; }
.button { min-height: 36px; display: inline-flex; align-items: center; justify-content: center; padding: 0 13px; border: 1px solid #cfd7dd; background: var(--paper); color: var(--ink); border-radius: 5px; font-size: 12px; font-weight: 700; text-decoration: none; cursor: pointer; }
.button.primary { border-color: var(--brand); background: var(--brand); color: #fff; }
.button.primary:hover { background: var(--brand-dark); }
.button:disabled { opacity: .55; cursor: not-allowed; }
.error-state { margin: 18px; padding: 14px; border: 1px solid #f2b8b5; background: #fff3f2; color: var(--danger); border-radius: 5px; font-size: 13px; }
.toast { position: fixed; right: 18px; bottom: 18px; z-index: 50; max-width: 380px; padding: 11px 14px; border-radius: 5px; background: #17222e; color: #fff; box-shadow: var(--shadow); font-size: 12px; opacity: 0; transform: translateY(8px); pointer-events: none; transition: .18s ease; }
.toast.visible { opacity: 1; transform: translateY(0); }
.toast.error { background: var(--danger); }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: #132b29; }
.login-panel { width: min(420px,100%); padding: 38px; border-radius: 6px; background: #fff; box-shadow: var(--shadow); }
.login-panel h1 { margin: 8px 0 12px; font-size: 26px; }
.login-panel p:not(.eyebrow) { margin: 0 0 24px; color: var(--muted); font-size: 14px; line-height: 1.55; }
.login-button { width: 100%; }

@media (max-width: 1000px) {
  .app-shell { grid-template-columns: 74px minmax(310px, 360px) minmax(0,1fr); }
  .sidebar { padding: 16px 8px; }
  .brand { justify-content: center; padding: 0 0 16px; }
  .brand > div:last-child, .area-button span, .sidebar-footer { display: none; }
  .area-button { justify-content: center; padding: 0; }
  .data-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
}

@media (max-width: 760px) {
  .app-shell { display: block; }
  .sidebar { position: sticky; z-index: 20; height: 58px; flex-direction: row; align-items: center; padding: 7px 10px; }
  .brand { border: 0; padding: 0 8px 0 0; }
  .brand-mark.compact { width: 34px; height: 34px; }
  .area-nav { display: flex; flex: 1; margin: 0; overflow-x: auto; }
  .area-button { width: 42px; min-width: 42px; height: 42px; }
  .queue-panel, .detail-panel { height: calc(100vh - 58px); }
  .queue-panel { border-right: 0; }
  .detail-panel { position: fixed; inset: 58px 0 0; z-index: 10; transform: translateX(100%); transition: transform .2s ease; }
  .detail-panel.open { transform: translateX(0); }
  .detail-header { padding: 16px 16px 0; }
  .detail-heading { display: block; }
  .detail-heading h2 { font-size: 18px; }
  .detail-status { margin-top: 14px; }
  .detail-content { padding: 18px 16px 40px; }
  .data-grid { grid-template-columns: 1fr; }
  .mobile-back { display: inline-flex !important; }
}

.mobile-back { display: none; margin-bottom: 10px; }
