/* Imperial Age Returns — internal admin app
   Dark theme with gold accents to match the Imperial Age brand. */

:root {
  --bg: #0e0e10;
  --surface: #16161a;
  --surface-2: #1f1f25;
  --border: #2a2a32;
  --text: #f5f5f7;
  --text-muted: #a0a0a8;
  --gold: #c9a14a;
  --gold-soft: #e0bd6c;
  --red: #c8252b;
  --green: #4caf50;
  --orange: #e6a23c;
  --blue: #5b9bd5;
  --radius: 10px;
  --shadow: 0 4px 16px rgba(0,0,0,0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

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

.app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 16px 80px;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 0 24px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}

.brand h1 {
  margin: 0;
  font-size: 22px;
  letter-spacing: 0.02em;
  color: var(--gold);
  font-weight: 700;
}
.brand-logo {
  display: block;
  height: 80px;
  width: auto;
  margin-bottom: 4px;
}
.login-logo {
  display: block;
  height: 120px;
  width: auto;
  margin: 0 auto 12px;
}
.brand-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  display: block;
  margin-top: 2px;
}

.user-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
  color: var(--text-muted);
}

/* ---------- Login ---------- */

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 28px;
  box-shadow: var(--shadow);
}

.login-card h1 {
  color: var(--gold);
  font-size: 24px;
  margin: 0 0 4px;
  text-align: center;
  letter-spacing: 0.02em;
}
.login-card .subtitle {
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
  margin: 0 0 24px;
}

/* ---------- Cards ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}
.card h2 {
  margin: 0 0 16px;
  font-size: 18px;
  color: var(--gold);
}

/* ---------- Forms ---------- */

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}
.field span {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 500;
}
.field input,
.field select,
.field textarea {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 10px 12px;
  font-size: 15px;
  font-family: inherit;
  outline: none;
  transition: border-color .15s;
  width: 100%;
  max-width: 100%;
  min-width: 0;
}
.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--gold);
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--gold);
  color: #1a1a1f;
  border: none;
  border-radius: 8px;
  padding: 10px 18px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: background .15s, transform .05s;
}
.btn:hover { background: var(--gold-soft); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-block { width: 100%; }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }

/* ---------- Messages ---------- */

.alert {
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 14px;
  margin-bottom: 14px;
}
.alert-error {
  background: rgba(200, 37, 43, 0.15);
  border: 1px solid rgba(200, 37, 43, 0.4);
  color: #f0a4a8;
}
.alert-info {
  background: rgba(91, 155, 213, 0.12);
  border: 1px solid rgba(91, 155, 213, 0.35);
  color: #b0d2ee;
}
.alert-warning {
  background: rgba(230, 162, 60, 0.12);
  border: 1px solid rgba(230, 162, 60, 0.4);
  color: #f0c97e;
}
.alert a { color: inherit; text-decoration: underline; }
.alert .return-link {
  display: inline-block;
  margin-top: 6px;
  font-family: 'SF Mono', Menlo, Consolas, monospace;
  font-size: 13px;
}

.muted { color: var(--text-muted); font-size: 14px; }

/* ---------- Toolbar ---------- */

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.toolbar h2 { margin: 0; }
.toolbar .left { display: flex; align-items: center; gap: 12px; }
.toolbar .right { display: flex; align-items: center; gap: 8px; }

.search {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 8px 12px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  min-width: 200px;
}
.search:focus { border-color: var(--gold); }

/* ---------- Returns table ---------- */

.returns-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.returns-table th,
.returns-table td {
  text-align: left;
  padding: 12px 10px;
  border-bottom: 1px solid var(--border);
}
.returns-table th {
  font-weight: 600;
  color: var(--text-muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.returns-table tbody tr {
  cursor: pointer;
  transition: background .12s;
}
.returns-table tbody tr:hover {
  background: var(--surface-2);
}
.returns-table .order-ref {
  font-family: 'SF Mono', Menlo, Consolas, monospace;
  color: var(--gold-soft);
  font-weight: 500;
}
.returns-table .date {
  color: var(--text-muted);
  white-space: nowrap;
}

/* ---------- Status badges ---------- */

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.badge-new            { background: rgba(91,155,213,0.18);  color: #b0d2ee; border: 1px solid rgba(91,155,213,0.4); }
.badge-contacted      { background: rgba(230,162,60,0.18);  color: #f0c97e; border: 1px solid rgba(230,162,60,0.4); }
.badge-awaiting_reply { background: rgba(230,162,60,0.10);  color: #d4b48a; border: 1px solid rgba(230,162,60,0.3); }
.badge-reply_received { background: rgba(91,155,213,0.20);  color: #b0d2ee; border: 1px solid rgba(91,155,213,0.5); }
.badge-reshipped      { background: rgba(76,175,80,0.18);   color: #9bd49d; border: 1px solid rgba(76,175,80,0.4); }
.badge-closed         { background: rgba(160,160,168,0.15); color: #c0c0c8; border: 1px solid rgba(160,160,168,0.35); }
.badge-refunded       { background: rgba(200,37,43,0.18);   color: #f0a4a8; border: 1px solid rgba(200,37,43,0.4); }

/* Inline status <select> styled like the badge */
.status-select {
  padding: 3px 26px 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  font-family: inherit;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 10 10'><path fill='%23a0a0a8' d='M1 3l4 4 4-4z'/></svg>");
  background-repeat: no-repeat;
  background-position: right 8px center;
  cursor: pointer;
  outline: none;
  transition: filter .12s;
}
.status-select:hover    { filter: brightness(1.15); }
.status-select option   { background: var(--surface-2); color: var(--text); }
.status-select.saving   { opacity: 0.5; cursor: wait; }
.status-select.saved    { box-shadow: 0 0 0 2px rgba(76,175,80,0.4); }

/* ---------- Filters ---------- */

.filters {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.filters select {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 8px 12px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  cursor: pointer;
}
.filters select:focus { border-color: var(--gold); }
.filters .clear-link {
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px 8px;
}
.filters .clear-link:hover { color: var(--text); text-decoration: underline; }

/* ---------- Empty state ---------- */

.empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.empty p { margin: 0 0 16px; }

/* ---------- Detail page ---------- */

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}
.detail-grid .full { grid-column: 1 / -1; }

.detail-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 8px;
}
/* Push Delete to the far right on desktop only — on phones the buttons stack */
@media (min-width: 601px) {
  .detail-actions .detail-delete { margin-left: auto; }
}

.btn-danger {
  background: transparent;
  color: #f0a4a8;
  border: 1px solid rgba(200,37,43,0.4);
}
.btn-danger:hover { background: rgba(200,37,43,0.15); }

.back-link {
  display: inline-block;
  margin-bottom: 14px;
  color: var(--text-muted);
  font-size: 14px;
}

textarea.field-input,
.field textarea { min-height: 80px; resize: vertical; }

/* Order # field with inline "Fetch from Shopify" button */
.order-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}
.order-row input { flex: 1; }
.order-row .btn { white-space: nowrap; }

.fetch-status {
  font-size: 13px;
  margin-top: 6px;
  min-height: 18px;
}
.fetch-status.success { color: #9bd49d; }
.fetch-status.error   { color: #f0a4a8; }
.fetch-status.muted   { color: var(--text-muted); }

/* "Or search by customer" divider */
.or-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 6px 0 12px;
  color: var(--text-muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.or-divider::before,
.or-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ---------- Photo section (detail page) ---------- */

.photo-section {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 16px;
}
.photo-section h3 {
  margin: 0 0 10px;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}
.photo-thumb {
  display: block;
  max-width: 100%;
  max-height: 320px;
  border-radius: 6px;
  border: 1px solid var(--border);
  margin-bottom: 10px;
  cursor: zoom-in;
}
.photo-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.photo-empty {
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 10px;
}
input[type="file"].photo-input {
  font-family: inherit;
  font-size: 13px;
  color: var(--text-muted);
}
input[type="file"].photo-input::file-selector-button {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 6px 12px;
  margin-right: 10px;
  cursor: pointer;
  font-family: inherit;
}
input[type="file"].photo-input::file-selector-button:hover {
  background: var(--bg);
}

/* ---------- Email section ---------- */

.email-section {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 16px;
}
.email-section h3 {
  margin: 0 0 10px;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}
.email-recipient {
  font-size: 14px;
  color: var(--text);
  margin-bottom: 10px;
}
.email-recipient strong { color: var(--gold-soft); }
.email-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.btn-success {
  background: var(--green);
  color: #0e0e10;
}
.btn-success:hover { background: #6cc06f; }

.email-preview {
  margin-top: 10px;
}
.email-preview summary {
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
  color: var(--gold-soft);
  user-select: none;
  padding: 4px 0;
}
.email-preview pre {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
  margin-top: 8px;
  font-family: 'SF Mono', Menlo, Consolas, monospace;
  font-size: 12px;
  color: var(--text);
  white-space: pre-wrap;
  max-height: 220px;
  overflow-y: auto;
}

/* ---------- Shopify status banner (refunded / cancelled) ---------- */

.shopify-banner {
  display: flex !important;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 14px;
  margin-bottom: 16px;
  line-height: 1.45;
}
.shopify-banner strong { font-weight: 700; letter-spacing: 0.02em; }
.shopify-banner.banner-refunded {
  background: rgba(76, 175, 80, 0.14);
  border: 1px solid rgba(76, 175, 80, 0.45);
  color: #c0e6c2;
}
.shopify-banner.banner-cancelled {
  background: rgba(200, 37, 43, 0.16);
  border: 1px solid rgba(200, 37, 43, 0.5);
  color: #f0a4a8;
}
.shopify-banner.banner-partial {
  background: rgba(230, 162, 60, 0.16);
  border: 1px solid rgba(230, 162, 60, 0.5);
  color: #f0c97e;
}

/* Same banner, compact form: a small inline pill we can show next to an
   order_ref in the dashboard list. */
.shopify-pill {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 999px;
  margin-left: 6px;
  letter-spacing: 0.02em;
  vertical-align: middle;
}
.shopify-pill.pill-refunded  { background: rgba(76,175,80,0.2);  color: #9bd49d; border: 1px solid rgba(76,175,80,0.5); }
.shopify-pill.pill-cancelled { background: rgba(200,37,43,0.2);  color: #f0a4a8; border: 1px solid rgba(200,37,43,0.55); }
.shopify-pill.pill-partial   { background: rgba(230,162,60,0.2); color: #f0c97e; border: 1px solid rgba(230,162,60,0.55); }

/* TunePipe-origin marker — shown on the return-detail title and dashboard rows. */
.source-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  margin-left: 8px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: rgba(91,155,213,0.18);
  color: #b6d6f1;
  border: 1px solid rgba(91,155,213,0.5);
  vertical-align: middle;
}

/* ---------- Replacement order section + modal ---------- */

.reship-section {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 16px;
}
.reship-section h3 {
  margin: 0 0 10px;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}
.reship-empty {
  color: var(--text-muted);
  font-size: 13px;
  margin-bottom: 10px;
  line-height: 1.5;
}
.reship-existing {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 10px;
}
.reship-existing-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
  font-size: 14px;
}
.reship-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}
.reship-order-link {
  font-family: 'SF Mono', Menlo, Consolas, monospace;
  color: var(--gold-soft);
  font-weight: 600;
}
.reship-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(2px);
  cursor: pointer;
}
.modal-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 920px;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 {
  margin: 0;
  color: var(--gold);
  font-size: 18px;
}
.modal-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: background .12s, color .12s;
}
.modal-close:hover { background: var(--surface-2); color: var(--text); }
.modal-body {
  padding: 16px 20px;
  overflow-y: auto;
}
.modal-intro {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.55;
  margin-bottom: 14px;
}
.modal-intro code {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 6px;
  font-family: 'SF Mono', Menlo, Consolas, monospace;
  font-size: 12px;
  color: var(--gold-soft);
}
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
}

.reship-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}
.reship-form-row.two {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.reship-reference {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
}
.reship-reference h4 {
  margin: 0 0 8px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  font-weight: 600;
}
.reship-reference textarea {
  width: 100%;
  min-height: 110px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 10px 12px;
  font-size: 13px;
  font-family: 'SF Mono', Menlo, Consolas, monospace;
  resize: vertical;
  outline: none;
}
.reship-reference textarea:focus { border-color: var(--gold); }

/* Inline hint under a form field, used e.g. for the Brazil CPF reminder */
.field-hint {
  display: block;
  margin-top: 6px;
  padding: 8px 10px;
  border-radius: 6px;
  background: rgba(230, 162, 60, 0.12);
  border: 1px solid rgba(230, 162, 60, 0.4);
  color: #f0c97e;
  font-size: 12.5px;
  line-height: 1.45;
}
.field-hint code {
  background: rgba(0,0,0,0.35);
  border-radius: 4px;
  padding: 1px 5px;
  font-family: 'SF Mono', Menlo, Consolas, monospace;
  font-size: 11.5px;
}

@media (max-width: 700px) {
  .reship-grid { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
  .modal { padding: 0; }
  .modal-card { max-height: 100vh; height: 100vh; border-radius: 0; }
  .reship-form-row.two { grid-template-columns: 1fr; }
}

/* ---------- Order contents (line items from Shopify) ---------- */

.items-section {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 16px;
}
.items-section h3 {
  margin: 0 0 10px;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}
.items-list { list-style: none; padding: 0; margin: 0; }
.items-list li {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 6px 0;
  border-bottom: 1px dashed var(--border);
  font-size: 14px;
}
.items-list li:last-child { border-bottom: none; }
.items-list .qty {
  color: var(--gold-soft);
  font-weight: 600;
  min-width: 32px;
  font-variant-numeric: tabular-nums;
}
.items-list .title  { flex: 1; color: var(--text); }
.items-list .variant {
  color: var(--text-muted);
  font-size: 13px;
  font-style: italic;
}
.items-list .sku {
  color: var(--text-muted);
  font-size: 11px;
  font-family: 'SF Mono', Menlo, Consolas, monospace;
}
.items-empty { color: var(--text-muted); font-size: 13px; }

/* Customer search results list */
.customer-results {
  margin-top: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  max-height: 320px;
  overflow-y: auto;
}
.customer-results .result-row {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background .12s;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.customer-results .result-row:last-child { border-bottom: none; }
.customer-results .result-row:hover { background: var(--surface); }
.customer-results .result-top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.customer-results .result-name {
  font-weight: 600;
  color: var(--text);
}
.customer-results .result-order {
  font-family: 'SF Mono', Menlo, Consolas, monospace;
  color: var(--gold-soft);
  font-size: 13px;
}
.customer-results .result-meta {
  font-size: 12px;
  color: var(--text-muted);
}
.customer-results .result-items {
  font-size: 12px;
  color: var(--gold-soft);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- Stats page ---------- */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-bottom: 20px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
.stat-card .label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 8px;
}
.stat-card .value {
  font-size: 32px;
  font-weight: 700;
  color: var(--gold);
  line-height: 1;
}
.stat-card .delta {
  display: inline-block;
  margin-left: 8px;
  font-size: 13px;
  font-weight: 600;
  vertical-align: middle;
}
.stat-card .delta.up   { color: #f0a4a8; }
.stat-card .delta.down { color: #9bd49d; }
.stat-card .delta.flat { color: var(--text-muted); }
.stat-card .sub {
  margin-top: 8px;
  font-size: 13px;
  color: var(--text-muted);
}

.bar-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.bar-row {
  display: grid;
  grid-template-columns: 200px 1fr 60px;
  gap: 10px;
  align-items: center;
}
.bar-label {
  font-size: 14px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bar-track {
  background: var(--surface-2);
  border-radius: 4px;
  height: 22px;
  position: relative;
  overflow: hidden;
}
.bar-fill {
  background: var(--gold);
  height: 100%;
  border-radius: 4px;
  transition: width .3s;
}
.bar-fill.status-new            { background: #5b9bd5; }
.bar-fill.status-contacted      { background: #e6a23c; }
.bar-fill.status-awaiting_reply { background: #d4b48a; }
.bar-fill.status-reshipped      { background: #4caf50; }
.bar-fill.status-closed         { background: #a0a0a8; }
.bar-fill.status-refunded       { background: #c8252b; }

.bar-value {
  font-size: 13px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

/* Returned products: expandable list */

.products-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.product-item {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.product-item > summary {
  list-style: none;
  cursor: pointer;
  padding: 10px 12px;
  display: grid;
  grid-template-columns: 1fr 100px 60px 16px;
  gap: 10px;
  align-items: center;
  user-select: none;
  transition: background .12s;
}
.product-item > summary::-webkit-details-marker { display: none; }
.product-item > summary:hover { background: var(--surface); }
.product-item > summary .p-name {
  font-size: 14px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.product-item > summary .p-name .variant {
  color: var(--text-muted);
  font-style: italic;
  font-size: 13px;
  margin-left: 6px;
}
.product-item > summary .p-bar {
  background: var(--bg);
  border-radius: 4px;
  height: 16px;
  position: relative;
  overflow: hidden;
}
.product-item > summary .p-bar-fill {
  background: var(--gold);
  height: 100%;
  border-radius: 4px;
}
.product-item > summary .p-count {
  font-size: 13px;
  color: var(--text-muted);
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.product-item > summary .p-arrow {
  font-size: 11px;
  color: var(--text-muted);
  transition: transform .15s;
}
.product-item[open] > summary .p-arrow { transform: rotate(90deg); }
.product-item[open] > summary { background: var(--surface); }

.product-returns {
  border-top: 1px solid var(--border);
  padding: 6px 0;
}
.product-returns a.return-row {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  gap: 10px;
  padding: 8px 12px;
  align-items: center;
  text-decoration: none;
  color: var(--text);
  border-bottom: 1px dashed var(--border);
  transition: background .12s;
}
.product-returns a.return-row:last-child { border-bottom: none; }
.product-returns a.return-row:hover { background: var(--surface-2); text-decoration: none; }
.product-returns .pr-order {
  font-family: 'SF Mono', Menlo, Consolas, monospace;
  color: var(--gold-soft);
  font-size: 13px;
}
.product-returns .pr-customer {
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.product-returns .pr-customer .pr-country {
  color: var(--text-muted);
  font-size: 12px;
  margin-left: 6px;
}
.product-returns .pr-qty {
  color: var(--gold-soft);
  font-weight: 600;
  font-size: 13px;
}

@media (max-width: 600px) {
  .product-item > summary {
    grid-template-columns: 1fr 60px 16px;
  }
  .product-item > summary .p-bar { display: none; }
  .product-returns a.return-row {
    grid-template-columns: 1fr auto;
    grid-template-areas: "order qty" "customer status";
    gap: 4px 10px;
  }
  .product-returns .pr-order    { grid-area: order; }
  .product-returns .pr-customer { grid-area: customer; }
  .product-returns .pr-qty      { grid-area: qty; justify-self: end; }
  .product-returns .pr-status   { grid-area: status; justify-self: end; }
}

/* Time-trend bars (vertical) */
.time-bars {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 140px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.time-bar {
  flex: 1;
  min-width: 14px;
  background: var(--gold);
  border-radius: 3px 3px 0 0;
  position: relative;
  transition: opacity .15s;
}
.time-bar:hover { opacity: 0.85; }
.time-bar .tip {
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 12px;
  color: var(--text);
  white-space: nowrap;
  display: none;
  margin-bottom: 4px;
  z-index: 5;
}
.time-bar:hover .tip { display: block; }
.time-axis {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  font-size: 11px;
  color: var(--text-muted);
}

/* ============================================================
   MOBILE
   - Tablets and below (≤700px): light tweaks
   - Phones (≤600px):           heavier restructuring (stacked header,
                                wrapping user-bar, full-width search,
                                tighter typography)
   ============================================================ */

@media (max-width: 700px) {
  .app { padding: 16px 12px 60px; }
  .login-card { padding: 24px 20px; }
  .detail-grid { grid-template-columns: 1fr; }

  /* Hide less-essential columns on phones */
  .returns-table th.col-country,
  .returns-table td.col-country { display: none; }
  .returns-table th, .returns-table td { padding: 10px 6px; }
  .search { min-width: 0; flex: 1; }

  /* Stats */
  .stats-grid { grid-template-columns: 1fr; }
  .bar-row    { grid-template-columns: 130px 1fr 50px; }
  .bar-label  { font-size: 13px; }
}

@media (max-width: 600px) {
  /* Prevent any rogue child from forcing horizontal scroll on the body */
  html, body { overflow-x: hidden; max-width: 100%; }
  .app       { padding: 12px 10px 60px; }

  /* Header: stack brand above user-bar so they don't fight for the same row */
  .app-header {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 10px 0 14px;
    margin-bottom: 16px;
  }
  .brand h1        { font-size: 18px; letter-spacing: 0.04em; }
  .brand-logo      { height: 60px; }
  .login-logo      { height: 90px; }
  .brand-subtitle  { font-size: 11px; }

  .user-bar {
    flex-wrap: wrap;
    gap: 6px;
    width: 100%;
    justify-content: flex-end;
  }
  .user-bar #user-email {
    flex: 1;
    min-width: 0;
    font-size: 12px;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .user-bar .btn {
    padding: 6px 10px;
    font-size: 12px;
  }

  /* Cards: tighter padding so content gets more horizontal room */
  .card { padding: 14px 12px; }

  /* Toolbar: stack title + actions on phones */
  .toolbar { flex-direction: column; align-items: stretch; gap: 10px; }
  .toolbar .right { width: 100%; }
  .toolbar h2 { font-size: 17px; }
  .search { width: 100%; }

  /* Filters */
  .filters { gap: 6px; }
  .filters select { font-size: 13px; padding: 7px 10px; flex: 1; min-width: 130px; }

  /* Order row (input + Fetch button): keep side-by-side, just tighten gap */
  .order-row { gap: 6px; }
  .order-row .btn { padding: 8px 10px; font-size: 13px; }

  /* Detail page: stack the Save / Back / Delete buttons full-width on phones.
     Cleaner than letting them wrap awkwardly, and fixes the Delete button
     hugging the right edge of the card. */
  .detail-actions { flex-direction: column; align-items: stretch; gap: 8px; }
  .detail-actions .btn { width: 100%; margin: 0; }

  /* Safety net: nothing inside a card may exceed 100% width.
     Prevents stray inline margins / fixed widths from breaking the layout. */
  .card > * { max-width: 100%; box-sizing: border-box; }
  .card *   { max-width: 100%; }
  .field    { width: 100%; min-width: 0; }
  .field input, .field select, .field textarea { width: 100%; min-width: 0; }
  .order-row, .detail-grid, .detail-actions { width: 100%; min-width: 0; }

  /* Forms — keep input font-size at 16px on iOS to prevent the auto-zoom-on-focus */
  .field input, .field select, .field textarea { font-size: 16px; }

  /* Stats: tighter time chart and bar rows */
  .time-bars { height: 100px; gap: 2px; }
  .time-bar  { min-width: 8px; }
  .stat-card .value { font-size: 26px; }
  .bar-row { grid-template-columns: 100px 1fr 56px; gap: 8px; }
  .bar-label { font-size: 12px; }

  /* Email preview: smaller mono text so long lines don't blow out */
  .email-preview pre { font-size: 11px; padding: 8px; }

  /* Customer search results — keep readable */
  .customer-results .result-meta { font-size: 11px; }

  /* ----- Returns table → vertical card list on phones -----
     The standard "responsive table" pattern: hide thead, transform each row
     into a self-contained card with a 2-column grid. No horizontal scroll. */
  #table-wrap { overflow-x: visible !important; }
  .returns-table { display: block; width: 100%; }
  .returns-table thead { display: none; }
  .returns-table tbody { display: block; width: 100%; }
  .returns-table tr {
    display: grid;
    grid-template-columns: auto 1fr;
    grid-template-areas:
      "date     status"
      "order    customer"
      "country  country";
    column-gap: 10px;
    row-gap: 4px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface-2);
    padding: 12px;
    margin-bottom: 8px;
    align-items: center;
  }
  .returns-table tr:hover { background: var(--surface-2); }
  .returns-table td {
    display: block;
    padding: 0;
    border: none;
    min-width: 0;
  }
  .returns-table .cell-date {
    grid-area: date;
    color: var(--text-muted);
    font-size: 12px;
    white-space: nowrap;
  }
  .returns-table .cell-status {
    grid-area: status;
    justify-self: end;
  }
  .returns-table .cell-order {
    grid-area: order;
    white-space: nowrap;
  }
  .returns-table .cell-customer {
    grid-area: customer;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 14px;
    min-width: 0;
  }
  /* Country cell: show again on phones (it's hidden on tablets via .col-country) */
  .returns-table .cell-country {
    grid-area: country;
    display: block;
    color: var(--text-muted);
    font-size: 13px;
  }
}


/* ========================================================
   IMPERIAL AGE SUPPORT — additions on top of Returns base
   ======================================================== */

/* Ticket list rows */
.ticket-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.ticket-row {
  display: grid;
  grid-template-columns: 56px 1fr auto;
  gap: 14px;
  align-items: center;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text);
  transition: background 0.12s;
}
.ticket-row:hover {
  background: var(--surface-2);
  text-decoration: none;
}
.ticket-flag {
  font-size: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.anomaly-icon { font-size: 13px; }
.ticket-main { min-width: 0; }
.ticket-subject {
  font-weight: 600;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ticket-meta {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 2px;
}
.contact-count {
  display: inline-block;
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 1px 6px;
  border-radius: 8px;
  font-size: 11px;
  color: var(--text-muted);
  margin-left: 4px;
}
.ticket-side {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}
.ticket-date {
  font-size: 12px;
  color: var(--text-muted);
}

/* Status badge */
.status-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.status-badge.status-new       { color: var(--gold-soft); border-color: var(--gold); }
.status-badge.status-triaged   { color: var(--blue); }
.status-badge.status-drafted   { color: var(--gold); }
.status-badge.status-replied   { color: var(--green); border-color: var(--green); }
.status-badge.status-awaiting  { color: var(--orange); border-color: var(--orange); }
.status-badge.status-closed    { color: var(--text-muted); }
.status-badge.status-archived  { color: var(--text-muted); opacity: 0.6; }

/* Empty state */
.empty-state {
  text-align: center;
  padding: 48px 16px;
  color: var(--text-muted);
}
.empty-state .small { font-size: 12px; opacity: 0.7; }

/* Ticket detail page */
.ticket-detail {
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.ticket-head { padding-bottom: 12px; border-bottom: 1px solid var(--border); }
.ticket-title {
  margin: 0 0 8px 0;
  font-size: 22px;
  color: var(--text);
}
.ticket-head-meta {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 6px;
}
.flag-dot { font-size: 18px; }
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 11px;
  letter-spacing: 0.04em;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  text-transform: uppercase;
}

/* Anomaly banner */
.anomaly-banner {
  background: rgba(230, 162, 60, 0.12);
  border: 1px solid var(--orange);
  color: var(--orange);
  padding: 12px 14px;
  border-radius: var(--radius);
  font-size: 14px;
}

/* Info grid (Shopify + Royal Mail blocks) */
.info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.info-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.info-label {
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.info-val {
  font-size: 14px;
  color: var(--text);
}

/* Draft area */
.draft-area {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.draft-textarea {
  min-height: 180px;
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  resize: vertical;
}
.draft-actions { display: flex; gap: 10px; }

/* Conversation thread */
.section-title {
  margin: 16px 0 8px;
  font-size: 14px;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  text-transform: uppercase;
}
.thread {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.msg {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.msg-in { border-left-color: var(--blue); }
.msg-out { border-left-color: var(--gold); }
.msg-meta {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 6px;
}
.msg-subject { font-size: 14px; color: var(--text); margin-bottom: 6px; font-weight: 500; }
.msg-body {
  margin: 0;
  white-space: pre-wrap;
  font: 13px/1.5 ui-monospace, 'SF Mono', Menlo, Monaco, monospace;
  color: var(--text-muted);
}
.ai-tag {
  font-size: 10px;
  letter-spacing: 0.05em;
  background: var(--gold);
  color: var(--bg);
  padding: 1px 6px;
  border-radius: 4px;
  text-transform: uppercase;
}

/* Settings page */
.settings-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 18px;
}
.settings-section h2 {
  margin: 0 0 6px;
  font-size: 16px;
  color: var(--gold);
}
.field-row {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-top: 10px;
}
.field-row input[type="text"] {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  flex: 1;
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 12px;
  font-size: 13px;
}
.data-table th, .data-table td {
  border-bottom: 1px solid var(--border);
  padding: 8px 10px;
  text-align: left;
}
.data-table th { color: var(--text-muted); font-weight: 500; }
.toggle-list {
  list-style: none;
  padding: 0;
  margin: 10px 0 0;
}
.toggle-list li { padding: 6px 0; }

/* Buttons (helpers, base in returns css) */
.btn-primary {
  background: var(--gold);
  color: var(--bg);
  font-weight: 600;
}
.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}

/* Mobile */
@media (max-width: 700px) {
  .info-grid { grid-template-columns: 1fr; }
  .ticket-row { grid-template-columns: 36px 1fr; }
  .ticket-side { grid-column: 2; align-items: flex-start; flex-direction: row; gap: 10px; margin-top: 4px; }
  .field-row { flex-wrap: wrap; }
}
