:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #1c252e;
  --muted: #687382;
  --line: #dce3ea;
  --sidebar: #172026;
  --teal: #0f766e;
  --teal-soft: #d9f3ee;
  --blue: #2563eb;
  --blue-soft: #dbeafe;
  --amber: #b7791f;
  --amber-soft: #fff3c4;
  --rose: #be123c;
  --rose-soft: #ffe4e6;
  --green: #15803d;
  --green-soft: #dcfce7;
  --violet: #6d28d9;
  --violet-soft: #ede9fe;
  --shadow: 0 8px 28px rgba(21, 32, 43, .08);
}

* { box-sizing: border-box; }

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

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

.sidebar {
  background: var(--sidebar);
  color: #fff;
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #fff;
  text-decoration: none;
  font-size: 1.05rem;
  font-weight: 750;
  padding: 4px 8px;
}

.brand:hover { color: #fff; }

.brand-mark,
.stat-icon,
.icon-btn {
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 36px;
}

.brand-mark {
  border-radius: 8px;
  background: var(--teal);
}

.side-nav {
  display: grid;
  gap: 6px;
}

.side-link {
  height: 42px;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 0;
  border-radius: 8px;
  color: rgba(255, 255, 255, .72);
  background: transparent;
  padding: 0 12px;
  font-weight: 650;
  text-align: left;
}

.side-link i { width: 18px; text-align: center; }
.side-link:hover { color: #fff; background: rgba(255, 255, 255, .08); }
.side-link.active { color: #fff; background: rgba(15, 118, 110, .82); }

.sidebar-foot {
  margin-top: auto;
  border-top: 1px solid rgba(255, 255, 255, .12);
  padding-top: 12px;
}

.sidebar-foot a {
  display: flex;
  align-items: center;
  gap: 10px;
  color: rgba(255, 255, 255, .72);
  text-decoration: none;
  padding: 10px 12px;
  border-radius: 8px;
  font-weight: 650;
}

.sidebar-foot a:hover { color: #fff; background: rgba(255, 255, 255, .08); }

.main {
  min-width: 0;
  padding: 24px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.eyebrow {
  color: var(--teal);
  font-weight: 750;
  font-size: .78rem;
}

h1 {
  margin: 0;
  font-size: 1.65rem;
  font-weight: 780;
}

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

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

.stat-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow);
  min-height: 86px;
}

.stat-icon {
  border-radius: 8px;
  font-size: 1rem;
}

.stat-teal { color: var(--teal); background: var(--teal-soft); }
.stat-blue { color: var(--blue); background: var(--blue-soft); }
.stat-amber { color: var(--amber); background: var(--amber-soft); }
.stat-rose { color: var(--rose); background: var(--rose-soft); }

.stat-label {
  color: var(--muted);
  font-size: .8rem;
  font-weight: 650;
}

.stat-value {
  font-size: 1.25rem;
  font-weight: 800;
  margin-top: 2px;
}

.workspace {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.toolbar {
  min-height: 66px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.search-box { max-width: 380px; }
.search-box .input-group-text { background: #fff; color: var(--muted); }
.filter-select { min-width: 180px; }

.table-wrap { min-height: 320px; }

.responsive-table {
  width: 100%;
  overflow-x: auto;
}

.table {
  margin: 0;
  min-width: 860px;
}

.table thead th {
  background: #f8fafc;
  color: #53606f;
  border-bottom: 1px solid var(--line);
  font-size: .78rem;
  font-weight: 760;
  padding: 12px 14px;
}

.table tbody td {
  border-bottom: 1px solid #edf1f5;
  padding: 13px 14px;
  vertical-align: middle;
}

.table tbody tr:hover { background: #fbfcfd; }
.table tbody tr:last-child td { border-bottom: 0; }

.cell-title {
  color: var(--ink);
  font-weight: 730;
  line-height: 1.25;
}

.cell-sub {
  color: var(--muted);
  font-size: .8rem;
  margin-top: 3px;
  word-break: break-word;
}

.actions-cell,
.line-item-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
}

.icon-btn {
  border: 1px solid var(--line);
  background: #fff;
  color: #53606f;
  border-radius: 8px;
  padding: 0;
}

.icon-btn:hover {
  border-color: var(--teal);
  color: var(--teal);
  background: var(--teal-soft);
}

.icon-btn.danger:hover {
  border-color: var(--rose);
  color: var(--rose);
  background: var(--rose-soft);
}

.btn-primary {
  --bs-btn-bg: var(--teal);
  --bs-btn-border-color: var(--teal);
  --bs-btn-hover-bg: #0b615b;
  --bs-btn-hover-border-color: #0b615b;
  --bs-btn-active-bg: #0b615b;
  --bs-btn-active-border-color: #0b615b;
}

.btn,
.form-control,
.form-select,
.input-group-text,
.modal-content {
  border-radius: 8px;
}

.form-control,
.form-select,
.input-group-text {
  border-color: var(--line);
}

.form-control:focus,
.form-select:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 .2rem rgba(15, 118, 110, .14);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 25px;
  padding: 3px 9px;
  border-radius: 8px;
  font-size: .76rem;
  font-weight: 750;
  white-space: nowrap;
}

.order-pending,
.order-confirmed,
.return-requested,
.return-approved,
.refund-pending,
.complaint-awaiting_customer,
.priority-medium {
  color: var(--amber);
  background: var(--amber-soft);
}

.order-processing,
.order-shipped,
.order-out_for_delivery,
.refund-processing,
.complaint-in_progress {
  color: var(--blue);
  background: var(--blue-soft);
}

.order-delivered,
.return-refund_completed,
.return-received,
.refund-completed,
.complaint-resolved,
.customer-active,
.priority-low {
  color: var(--green);
  background: var(--green-soft);
}

.order-cancelled,
.return-rejected,
.return-cancelled,
.refund-failed,
.complaint-open,
.priority-high {
  color: var(--rose);
  background: var(--rose-soft);
}

.order-returned,
.return-pickup_scheduled,
.return-picked_up,
.return-refund_initiated,
.complaint-closed,
.customer-inactive,
.priority-urgent {
  color: var(--violet);
  background: var(--violet-soft);
}

.empty-state {
  min-height: 220px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-weight: 650;
  text-align: center;
  padding: 24px;
}

.empty-state.small {
  min-height: 92px;
  border: 1px dashed var(--line);
  border-radius: 8px;
}

.modal-header,
.modal-footer {
  border-color: var(--line);
}

.modal-title {
  font-weight: 780;
}

.compact-form {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fbfcfd;
}

.form-section-title {
  font-weight: 760;
  margin-bottom: 12px;
}

.line-item {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 10px;
  background: #fff;
}

.line-total {
  min-width: 110px;
  text-align: right;
  font-weight: 760;
}

.thread-list {
  max-height: 420px;
  overflow-y: auto;
  display: grid;
  gap: 10px;
  padding: 4px;
}

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

.thread-message span {
  display: block;
  color: var(--muted);
  font-size: .75rem;
  margin-top: 5px;
}

.thread-message.customer {
  margin-left: auto;
  background: var(--teal-soft);
  border-color: #b7e6df;
}

.thread-message.support {
  background: var(--blue-soft);
  border-color: #bdd4ff;
}

.thread-message.system {
  max-width: 100%;
  background: var(--amber-soft);
  border-color: #f3d377;
}

#toast-container {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 2000;
  display: grid;
  gap: 8px;
}

.toast-msg {
  min-width: 260px;
  max-width: min(420px, calc(100vw - 36px));
  border-radius: 8px;
  color: #fff;
  padding: 11px 14px;
  font-weight: 680;
  box-shadow: var(--shadow);
}

.toast-success { background: var(--green); }
.toast-error { background: var(--rose); }
.toast-info { background: var(--blue); }

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 20;
    flex-direction: row;
    align-items: center;
    overflow-x: auto;
    padding: 10px;
  }

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

  .side-link {
    min-width: 42px;
  }

  .side-link span,
  .sidebar-foot {
    display: none;
  }

  .main {
    padding: 16px;
  }

  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .topbar,
  .toolbar,
  .line-item {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar-actions,
  .search-box,
  .filter-select {
    width: 100%;
  }

  .stats-grid {
    grid-template-columns: 1fr;
  }

  .actions-cell,
  .line-item-actions {
    justify-content: flex-start;
  }

  .thread-message {
    max-width: 100%;
  }
}
