:root {
  --bg: #eef2f6;
  --panel: #ffffff;
  --panel-muted: #f8fafc;
  --line: #d6dee8;
  --line-strong: #bdc8d5;
  --text: #172033;
  --muted: #667085;
  --muted-strong: #475467;
  --blue: #2563eb;
  --blue-dark: #1d4ed8;
  --green: #16833a;
  --amber: #b7791f;
  --red: #c24136;
  --violet: #6f42c1;
  --sidebar: #111c29;
  --sidebar-active: #203047;
  --shadow: 0 10px 28px rgba(16, 24, 40, .07);
}

* { box-sizing: border-box; }

html { min-width: 320px; }

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

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

.shell {
  display: grid;
  grid-template-columns: 232px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  background: var(--sidebar);
  color: #eef3f7;
  padding: 18px 14px;
}

.brand {
  display: grid;
  gap: 2px;
  margin: 0 0 22px;
  padding: 8px 10px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, .12);
}

.brand strong {
  font-size: 18px;
  line-height: 1.2;
}

.brand span {
  color: #9fb0c3;
  font-size: 12px;
}

.nav {
  display: grid;
  gap: 5px;
}

.nav a,
.logout-link {
  display: flex;
  align-items: center;
  min-height: 40px;
  border: 0;
  border-radius: 8px;
  color: #eef3f7;
  background: transparent;
  padding: 9px 12px;
  text-align: left;
  width: 100%;
  cursor: pointer;
  font: inherit;
  font-weight: 650;
}

.nav a:hover,
.logout-link:hover,
.nav a.active {
  background: var(--sidebar-active);
  text-decoration: none;
}

.nav a.active {
  box-shadow: inset 3px 0 0 #60a5fa;
}

.main { min-width: 0; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  min-height: 66px;
  background: rgba(255, 255, 255, .96);
  border-bottom: 1px solid var(--line);
  padding: 13px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  backdrop-filter: blur(8px);
}

.user-chip {
  display: grid;
  gap: 1px;
  min-width: 140px;
  justify-items: end;
  color: var(--text);
}

.user-chip span {
  color: var(--muted);
  font-size: 12px;
}

.content {
  width: 100%;
  max-width: 1540px;
  margin: 0;
  padding: 28px 32px 44px;
}

.page-title {
  margin: 0;
  font-size: 22px;
  line-height: 1.2;
  font-weight: 750;
  color: #101828;
}

.muted { color: var(--muted); }

.band,
.panel,
.ticket-hero {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.band,
.panel { padding: 18px; }

.panel h2,
.section-heading h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.25;
}

.section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

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

.stat { border-left: 4px solid var(--blue); }
.stat strong { display: block; font-size: 28px; margin-top: 6px; }
.stat.green { border-color: var(--green); }
.stat.amber { border-color: var(--amber); }
.stat.red { border-color: var(--red); }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 10px;
  margin-bottom: 16px;
}

.form-row {
  display: grid;
  gap: 7px;
  margin-bottom: 14px;
}

label {
  color: var(--muted-strong);
  font-size: 13px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid #c7d0da;
  border-radius: 8px;
  padding: 10px 11px;
  background: #fff;
  color: var(--text);
  font: inherit;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: #76a7fa;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .13);
}

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 13px;
  background: var(--blue);
  color: #fff;
  font-weight: 750;
  cursor: pointer;
  white-space: nowrap;
}

.btn:hover {
  background: var(--blue-dark);
  text-decoration: none;
}

.btn.secondary {
  background: #fff;
  color: var(--text);
  border-color: #c7d0da;
}

.btn.secondary:hover {
  background: #f8fafc;
}

.btn.danger { background: var(--red); }
.btn.small { min-height: 30px; padding: 5px 9px; font-size: 12px; }
.btn.full { width: 100%; }
.btn:disabled, input:disabled, select:disabled { opacity: .55; cursor: not-allowed; }

.inline-form {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) auto;
  gap: 8px;
  align-items: center;
  min-width: 280px;
}

.inline-form input,
.inline-form select {
  min-height: 34px;
  padding: 7px 9px;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

th,
td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  background: #f0f4f8;
  font-size: 12px;
  color: #4b5968;
  text-transform: uppercase;
}

tr:last-child td { border-bottom: 0; }

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 12px;
  font-weight: 800;
  color: #24313f;
  background: #e8edf2;
}

.badge.open,
.badge.new { background: #e6f0ff; color: #174ea6; }
.badge.resolved,
.badge.closed { background: #e7f6ec; color: #146c2e; }
.badge.escalated,
.badge.urgent { background: #fdecec; color: #a32b20; }
.badge.pending { background: #fff4db; color: #8a5a12; }
.badge.high { background: #fdf0e6; color: #a44912; }
.badge.support-active { background: #e7f6ec; color: #146c2e; }
.badge.support-refund_requested { background: #fff4db; color: #8a5a12; }
.badge.support-refunded { background: #eef2f7; color: #334155; }
.badge.support-chargeback_filed,
.badge.support-support_hold { background: #fdecec; color: #a32b20; }
.badge.refund-none { background: #e8edf2; color: #24313f; }
.badge.refund-team_leader_review { background: #e6f0ff; color: #174ea6; }
.badge.refund-sustained { background: #e7f6ec; color: #146c2e; }
.badge.refund-manager_review { background: #fff4db; color: #8a5a12; }
.badge.refund-refund_initiated { background: #fdf0e6; color: #a44912; }
.badge.refund-refunded { background: #eef2f7; color: #334155; }

.support-alert {
  border-radius: 8px;
  padding: 14px 16px;
  margin-bottom: 16px;
  border: 1px solid #e3ba57;
  border-left-width: 5px;
  background: #fff8e6;
  color: #664409;
}

.support-alert.restricted {
  border-color: #dc7b72;
  background: #fff0ef;
  color: #8f241d;
}

.support-alert strong { display: block; font-size: 15px; }
.support-alert p { margin: 8px 0 0; }

.flash {
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 16px;
  border: 1px solid #b6dfc2;
  background: #eefaf1;
  color: #135f2a;
}

.flash.error { border-color: #f0b8b2; background: #fff0ef; color: #98261f; }

.comment-list {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.comment {
  border-left: 4px solid #c7d0da;
  border-radius: 8px;
  padding: 12px 14px;
  background: #fff;
}

.comment.internal {
  border-color: var(--violet);
  background: #f7f3ff;
}

.comment-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: baseline;
  margin-bottom: 6px;
}

.comment p { margin: 0; }

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

.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-box {
  width: min(420px, 100%);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 24px;
}

.ticket-hero {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  padding: 20px;
  margin-bottom: 16px;
}

.ticket-kicker {
  color: var(--blue);
  font-size: 12px;
  font-weight: 850;
  text-transform: uppercase;
}

.ticket-title {
  margin: 4px 0 8px;
  font-size: 26px;
  line-height: 1.22;
}

.ticket-meta,
.detail-line {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--muted);
}

.ticket-meta span + span::before,
.detail-line span + span::before {
  content: "/";
  color: var(--line-strong);
  margin-right: 8px;
}

.ticket-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.ticket-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.ticket-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(340px, 380px);
  align-items: start;
  gap: 16px;
}

.ticket-main,
.ticket-side {
  display: grid;
  gap: 16px;
}

.ticket-side {
  position: sticky;
  top: 86px;
}

.ticket-description {
  min-height: 170px;
}

.ticket-description p {
  margin: 0;
}

.meta-list {
  display: grid;
  gap: 10px;
}

.meta-list p {
  margin: 0;
}

.meta-label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.action-panel form:last-child,
.action-panel .form-row:last-child {
  margin-bottom: 0;
}

.ticket-command-center {
  padding: 0;
  overflow: hidden;
}

.command-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  background: var(--panel-muted);
  border-bottom: 1px solid var(--line);
}

.command-header h2,
.compact-heading h3 {
  margin: 0;
  font-size: 17px;
  line-height: 1.25;
}

.command-header p {
  margin: 3px 0 0;
}

.command-section {
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

.command-section:last-child {
  border-bottom: 0;
}

.compact-heading {
  align-items: center;
  margin-bottom: 10px;
}

.customer-stack {
  display: grid;
  gap: 4px;
}

.customer-stack span,
.command-meta {
  font-size: 13px;
}

.support-line {
  margin-top: 10px;
}

.customer-note {
  margin: 12px 0 0;
  color: var(--muted-strong);
}

.decision-actions {
  display: grid;
  gap: 14px;
}

.decision-actions form + form {
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.textarea-compact {
  min-height: 84px;
}

.no-action {
  margin-bottom: 0;
}

.control-details {
  border-bottom: 1px solid var(--line);
}

.control-details:last-child {
  border-bottom: 0;
}

.control-details summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 48px;
  padding: 0 18px;
  color: #101828;
  cursor: pointer;
  font-weight: 800;
  list-style: none;
}

.control-details summary::-webkit-details-marker {
  display: none;
}

.control-details summary::after {
  content: "+";
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
}

.control-details[open] summary::after {
  content: "-";
}

.control-details > form,
.control-details > .date-grid {
  padding: 0 18px 18px;
}

.control-details form + form {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.timeline-list {
  display: grid;
  gap: 10px;
  padding: 0 18px 18px;
}

.timeline-list p {
  display: grid;
  gap: 2px;
  margin: 0;
}

.date-grid {
  display: grid;
  gap: 10px;
}

.date-grid p { margin: 0; }

.note-form {
  padding-bottom: 14px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.checkbox-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  color: var(--muted-strong);
  font-weight: 650;
}

.checkbox-row input { width: auto; }

@media (max-width: 1100px) {
  .ticket-layout { grid-template-columns: 1fr; }
  .ticket-side { position: static; }
}

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
  }
  .nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .topbar {
    position: static;
    padding: 12px 16px;
  }
  .content { padding: 16px; }
  .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; }
  .ticket-hero { display: grid; }
  .ticket-actions { justify-content: flex-start; }
}

@media (max-width: 560px) {
  .nav { grid-template-columns: 1fr; }
  .topbar {
    align-items: flex-start;
    display: grid;
  }
  .user-chip { justify-items: start; }
  .ticket-title { font-size: 22px; }
  .ticket-actions .btn { width: 100%; }
}
