:root {
  color-scheme: light;
  --bg: #eef1f4;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --line: #d7dde5;
  --line-strong: #b7c0cc;
  --text: #172033;
  --muted: #667085;
  --muted-strong: #475467;
  --accent: #0f766e;
  --accent-dark: #115e59;
  --blue: #2563eb;
  --amber: #b45309;
  --danger: #b42318;
  --shadow: 0 12px 32px rgba(22, 32, 51, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

a { color: var(--accent-dark); text-decoration: none; }
strong { font-weight: 750; }
small { color: var(--muted); }

.app-shell {
  min-height: 100vh;
  display: flex;
}

.sidebar {
  width: 248px;
  min-height: 100vh;
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: 18px;
  background: #172033;
  color: #e6edf6;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  color: #fff;
}

.brand-mark {
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: #0f766e;
  color: #fff;
  font-weight: 850;
  letter-spacing: 0;
}

.brand-mark.large {
  width: 48px;
  height: 48px;
  margin-bottom: 12px;
}

.brand small {
  display: block;
  color: #aab6c7;
  font-size: 12px;
}

.side-nav {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.side-nav a {
  min-height: 40px;
  display: flex;
  align-items: center;
  padding: 9px 11px;
  border-radius: 6px;
  color: #cbd5e1;
}

.side-nav a:hover,
.side-nav a.active {
  background: rgba(255, 255, 255, 0.09);
  color: #fff;
}

.sidebar-footer {
  margin-top: auto;
  display: grid;
  gap: 10px;
  color: #cbd5e1;
  font-size: 13px;
}

.main-area {
  flex: 1;
  min-width: 0;
}

.page {
  max-width: 1480px;
  margin: 0 auto;
  padding: 26px;
}

.toolbar {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: flex-start;
  margin-bottom: 18px;
}

.toolbar .actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

h1, h2, p { margin-top: 0; }
h1 {
  margin-bottom: 6px;
  font-size: 28px;
  line-height: 1.15;
  letter-spacing: 0;
}
h2 {
  margin-bottom: 10px;
  font-size: 16px;
  letter-spacing: 0;
}
p { margin-bottom: 10px; color: var(--muted); }

.eyebrow {
  display: block;
  margin-bottom: 5px;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

button, .button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  min-height: 38px;
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-weight: 700;
}

button:hover, .button:hover { border-color: var(--line-strong); }

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

.metric-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.metric-strip > div {
  padding: 13px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.metric-strip span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
}

.metric-strip strong {
  display: block;
  font-size: 22px;
  line-height: 1;
}

.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.tabs a {
  min-width: max-content;
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted-strong);
}

.tabs a.active {
  border-color: var(--accent);
  background: #eaf7f5;
  color: var(--accent-dark);
  font-weight: 800;
}

.tabs strong {
  min-width: 24px;
  min-height: 22px;
  display: inline-grid;
  place-items: center;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--muted-strong);
  font-size: 12px;
}

.filters {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 230px auto;
  gap: 10px;
  margin-bottom: 14px;
}

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  min-height: 38px;
  padding: 8px 10px;
  background: #fff;
  color: var(--text);
  font: inherit;
}

textarea {
  min-height: 150px;
  resize: vertical;
}

input:focus, select:focus, textarea:focus {
  outline: 3px solid rgba(15, 118, 110, 0.14);
  border-color: var(--accent);
}

.ticket-list,
.conversation,
.side-panel > *,
.settings-card,
.auth-panel,
.form-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.ticket-list { overflow: hidden; }

.ticket-row {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) 270px;
  gap: 14px;
  align-items: center;
  padding: 13px 16px;
  border-bottom: 1px solid var(--line);
  color: var(--text);
}

.ticket-row:last-child { border-bottom: 0; }
.ticket-row:hover { background: var(--surface-soft); }
.ticket-row.unread {
  background: #eefaf8;
  box-shadow: inset 4px 0 0 var(--accent);
}

.channel-token {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #e8edf3;
  color: #243044;
  font-weight: 850;
  text-transform: uppercase;
}

.ticket-main, .ticket-side {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.ticket-main strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ticket-side { align-items: flex-end; text-align: right; }

.ticket-title-line {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.source {
  color: var(--accent-dark);
  font-size: 11px;
  font-weight: 850;
  text-transform: uppercase;
}

.unread-dot {
  border-radius: 999px;
  padding: 2px 7px;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 800;
}

.badge {
  background: var(--badge, #64748b);
  color: #fff;
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 12px;
  font-weight: 800;
}

.detail-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 348px;
  gap: 18px;
  align-items: start;
}

.conversation { padding: 18px; }

.ticket-heading {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 14px;
  margin-bottom: 16px;
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 18px;
}

.message {
  max-width: 78%;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.message.inbound {
  border-left: 4px solid var(--blue);
}

.message.outbound {
  margin-left: auto;
  background: #ecfdf5;
  border-color: #b7e4d6;
}

.message.internal {
  margin-inline: auto;
  background: #fff7ed;
  border-color: #fed7aa;
}

.message-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 8px;
}

.message-body { white-space: normal; word-break: break-word; }

.reply-box {
  border-top: 1px solid var(--line);
  padding-top: 16px;
}

.composer-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.side-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  position: sticky;
  top: 18px;
}

.side-panel > *,
.auth-panel,
.form-panel {
  padding: 16px;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.settings-card { padding: 16px; }

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

.section-head h2 { margin-bottom: 0; }

.list-line {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 0;
  border-bottom: 1px solid var(--line);
  color: var(--text);
}

.list-line:last-child { border-bottom: 0; }
.list-line span { color: var(--muted); }

.mini-action {
  font-weight: 800;
  white-space: nowrap;
}

.empty-state {
  padding: 28px;
  color: var(--muted);
  text-align: center;
}

.empty-state strong {
  display: block;
  margin-bottom: 4px;
  color: var(--text);
}

.flash {
  max-width: 1480px;
  margin: 14px auto 0;
  padding: 0 26px;
}

.flash-item {
  padding: 10px 12px;
  border-radius: 6px;
  background: #eef2ff;
  border: 1px solid #c7d2fe;
}

.flash-item.error { background: #fef2f2; border-color: #fecaca; color: var(--danger); }
.flash-item.success { background: #ecfdf5; border-color: #bbf7d0; color: var(--accent-dark); }
.flash-item.warning { background: #fff7ed; border-color: #fed7aa; color: var(--amber); }

.form p { margin-bottom: 12px; }
.form label {
  display: block;
  color: var(--text);
  font-weight: 750;
  margin-bottom: 5px;
}

.form-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.auth-panel {
  width: min(420px, calc(100vw - 32px));
  margin: 9vh auto;
  box-shadow: var(--shadow);
}

.form-panel {
  max-width: 760px;
  box-shadow: var(--shadow);
}

.meta-box p { overflow-wrap: anywhere; }

@media (max-width: 1080px) {
  .sidebar {
    width: 210px;
  }
  .metric-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .detail-layout,
  .settings-grid {
    grid-template-columns: 1fr;
  }
  .side-panel {
    position: static;
  }
}

@media (max-width: 760px) {
  .app-shell {
    display: block;
  }
  .sidebar {
    position: static;
    width: 100%;
    min-height: 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  }
  .side-nav {
    flex-direction: row;
    overflow-x: auto;
  }
  .sidebar-footer {
    display: none;
  }
  .page {
    padding: 16px;
  }
  .toolbar {
    flex-direction: column;
  }
  .filters,
  .ticket-row,
  .metric-strip {
    grid-template-columns: 1fr;
  }
  .ticket-side {
    align-items: flex-start;
    text-align: left;
  }
  .message {
    max-width: 100%;
  }
}
