:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --ink: #151b2d;
  --muted: #637088;
  --line: #dce4ef;
  --dark: #130f2b;
  --dark-2: #211743;
  --green: #12b981;
  --blue: #2563eb;
  --aqua: #57dbe8;
  --red: #dc2626;
  --amber: #b45309;
  --shadow: 0 18px 44px rgba(18, 24, 41, .11);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button { cursor: pointer; }

.shell-header {
  min-height: 74px;
  padding: 14px clamp(16px, 4vw, 48px);
  background: var(--dark);
  border-bottom: 1px solid rgba(255,255,255,.12);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  color: #fff;
  text-decoration: none;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--aqua), var(--green));
  color: #071225;
  font-weight: 950;
}

.brand-text {
  font-size: 19px;
  line-height: .92;
  font-weight: 950;
  letter-spacing: 0;
}

.top-actions {
  display: flex;
  gap: 8px;
  padding: 5px;
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 8px;
  background: rgba(255,255,255,.06);
}

.nav-button {
  min-height: 36px;
  border: 0;
  border-radius: 6px;
  padding: 8px 14px;
  color: #d8def1;
  background: transparent;
  font-weight: 800;
}

.nav-button.is-active {
  background: #fff;
  color: var(--dark);
}

.app-shell {
  width: min(1220px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 50px;
}

.hero-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 22px;
  align-items: stretch;
  margin-bottom: 22px;
}

.hero-panel > div:first-child,
.service-card,
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.hero-panel > div:first-child {
  padding: clamp(24px, 4vw, 40px);
}

.eyebrow,
.kicker {
  margin: 0 0 8px;
  color: #5b3fd7;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: .1em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  max-width: 760px;
  font-size: clamp(30px, 5vw, 52px);
  line-height: 1;
  letter-spacing: 0;
}

h2 {
  margin: 0;
  font-size: 20px;
  line-height: 1.2;
  letter-spacing: 0;
}

.lead {
  margin: 16px 0 0;
  max-width: 700px;
  color: var(--muted);
  font-size: 17px;
  line-height: 1.65;
}

.service-card {
  min-height: 152px;
  padding: 22px;
  display: flex;
  align-items: center;
  gap: 15px;
}

.service-card p {
  margin: 5px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

.status-dot {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
  border-radius: 999px;
  background: var(--green);
  box-shadow: 0 0 0 8px rgba(18,185,129,.16);
}

.service-card.is-closed .status-dot {
  background: var(--amber);
  box-shadow: 0 0 0 8px rgba(180,83,9,.14);
}

.view { display: none; }
.view.is-active { display: block; }

.admin-mode .hero-panel,
.admin-mode .nav-button[data-view="client"] {
  display: none;
}

body:not(.admin-mode) .nav-button[data-view="agent"],
body:not(.admin-mode) .logout-button,
body:not(.admin-mode) #agentView {
  display: none;
}

.admin-mode .app-shell {
  padding-top: 22px;
}

.admin-mode:not(.admin-auth) .agent-layout {
  grid-template-columns: 1fr;
}

.admin-mode:not(.admin-auth) .agent-layout > aside {
  display: none;
}

.admin-mode:not(.admin-auth) .detail-panel {
  width: min(520px, 100%);
  min-height: auto;
  margin: 0 auto;
}

.grid {
  display: grid;
  gap: 22px;
}

.two-columns {
  grid-template-columns: minmax(0, 1.12fr) minmax(340px, .88fr);
}

.agent-layout {
  grid-template-columns: minmax(280px, .75fr) minmax(0, 1.2fr) minmax(300px, .85fr);
  align-items: start;
}

.panel {
  overflow: hidden;
}

.panel-heading {
  min-height: 74px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  padding: 5px 10px;
  border-radius: 999px;
  background: #ecfdf5;
  color: #047857;
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}

.badge.offline {
  background: #fff7ed;
  color: var(--amber);
}

.heading-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.stack {
  padding: 20px;
  display: grid;
  gap: 15px;
}

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

label {
  display: grid;
  gap: 7px;
  color: #43506a;
  font-size: 13px;
  font-weight: 900;
}

input,
select,
textarea {
  width: 100%;
  min-height: 44px;
  border: 1px solid #cbd6e4;
  border-radius: 8px;
  padding: 11px 12px;
  color: var(--ink);
  background: #fff;
  outline: none;
}

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

input:focus,
select:focus,
textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37,99,235,.14);
}

.button {
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 10px 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 900;
}

.button.small {
  min-height: 34px;
  padding: 7px 10px;
  font-size: 12px;
}

.button.primary {
  background: var(--green);
  color: #041f16;
}

.button.secondary {
  background: var(--blue);
  color: #fff;
}

.button.subtle {
  border-color: var(--line);
  background: #fff;
  color: var(--ink);
}

.button.danger {
  color: var(--red);
}

.button:disabled,
.chat-composer.is-disabled {
  opacity: .52;
  cursor: not-allowed;
}

.helper {
  margin: 0;
  padding: 0 20px 20px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.chat-window {
  height: 340px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: auto;
  background: #fbfcff;
}

.chat-message {
  max-width: 86%;
  border: 1px solid #dce7f5;
  border-radius: 8px;
  padding: 10px 12px;
  background: #eef5ff;
  line-height: 1.45;
  font-size: 14px;
}

.chat-message.client {
  align-self: flex-end;
  background: #dcfce7;
  border-color: #bbf7d0;
}

.chat-message.agent {
  align-self: flex-start;
}

.chat-message small {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 11px;
}

.chat-composer {
  padding: 14px;
  border-top: 1px solid var(--line);
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

.tickets-panel {
  margin-top: 22px;
}

.ticket-list {
  display: grid;
  gap: 12px;
  padding: 18px;
}

.ticket-list.compact {
  max-height: 645px;
  overflow: auto;
}

.ticket-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fff;
  display: grid;
  gap: 10px;
}

.ticket-card.is-selected {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}

.ticket-card header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.ticket-card strong {
  display: block;
}

.client-thread {
  display: grid;
  gap: 10px;
}

.client-thread-entry {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fbfcff;
}

.client-thread-entry.agent {
  border-color: #bfdbfe;
  background: #eff6ff;
}

.client-thread-entry p {
  margin: 6px 0;
}

.client-thread-entry small {
  color: var(--muted);
}

.ticket-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.status {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 4px 8px;
  border-radius: 999px;
  background: #eff6ff;
  color: #1d4ed8;
  font-size: 12px;
  font-weight: 900;
}

.status.resolved {
  background: #ecfdf5;
  color: #047857;
}

.status.waiting {
  background: #fff7ed;
  color: var(--amber);
}

.detail-panel {
  min-height: 640px;
}

.ticket-detail-body {
  padding: 20px;
  display: grid;
  gap: 18px;
}

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

.detail-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcff;
}

.detail-item span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  margin-bottom: 4px;
  text-transform: uppercase;
}

.thread {
  display: grid;
  gap: 10px;
}

.thread-entry {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
  line-height: 1.5;
}

.thread-entry.agent {
  border-color: #bfdbfe;
  background: #eff6ff;
}

.thread-entry.note {
  border-color: #fde68a;
  background: #fffbeb;
}

.thread-entry small {
  display: block;
  margin-top: 8px;
  color: var(--muted);
}

.admin-actions {
  display: grid;
  gap: 12px;
}

.empty-state {
  min-height: 260px;
  display: grid;
  place-items: center;
  align-content: center;
  padding: 36px;
  text-align: center;
}

.empty-state p {
  max-width: 360px;
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.5;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 10;
  width: min(390px, calc(100% - 36px));
  padding: 14px 16px;
  border-radius: 8px;
  background: #111827;
  color: #fff;
  box-shadow: 0 16px 36px rgba(0,0,0,.22);
  line-height: 1.45;
  transform: translateY(130%);
  transition: transform .22s ease;
}

.toast.show {
  transform: translateY(0);
}

@media (max-width: 1060px) {
  .hero-panel,
  .two-columns,
  .agent-layout {
    grid-template-columns: 1fr;
  }

  .detail-panel {
    min-height: auto;
  }
}

@media (max-width: 680px) {
  .shell-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .top-actions,
  .nav-button {
    width: 100%;
  }

  .top-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .app-shell {
    width: min(100% - 22px, 1220px);
    padding-top: 18px;
  }

  .field-row,
  .detail-grid,
  .chat-composer {
    grid-template-columns: 1fr;
  }

  .panel-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .brand-text { font-size: 18px; }
}
