/* dashboard.css — All Auto Recyclers admin */

:root {
  --ink: #14181F;
  --ink-soft: #4A5160;
  --paper: #FFFFFF;
  --bg: #FAFAF8;
  --accent: #0066FF;
  --accent-d: #0052CC;
  --accent-soft: #EEF3FF;
  --line: #E6E7EB;
  --line-soft: #F1F2F5;
  --mute: #8B92A1;
  --ok: #0F9D58;
  --ok-soft: #E3F6EC;
  --warn: #B26500;
  --warn-soft: #FFF6E6;
  --bad: #DC2626;
  --bad-soft: #FBE7E9;

  --radius: 8px;
  --radius-lg: 12px;

  --shadow-sm: 0 1px 2px rgba(20,24,31,.05);
  --shadow-md: 0 4px 16px rgba(20,24,31,.08);

  --body: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }

body.dash {
  margin: 0;
  font-family: var(--body);
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  display: flex;
  font-size: 15px;
  line-height: 1.55;
}

h1, h2, h3 { font-family: var(--body); color: var(--ink); margin: 0; font-weight: 700; letter-spacing: -0.01em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.05rem; }

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

input, select, textarea, button { font-family: inherit; font-size: 14px; }

/* ---------- Sidebar ---------- */
.side {
  width: 240px;
  flex-shrink: 0;
  background: var(--paper);
  color: var(--ink-soft);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  border-right: 1px solid var(--line);
}
.side__brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 18px;
  border-bottom: 1px solid var(--line);
  color: var(--ink);
}
.side__brand:hover { text-decoration: none; }
.side__mark {
  width: 36px; height: 36px;
  background: var(--ink);
  color: #fff;
  font-weight: 700;
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-size: 12px;
  letter-spacing: 0;
  flex-shrink: 0;
}
.side__brand strong { display: block; color: var(--ink); font-weight: 700; font-size: .95rem; }
.side__brand small { color: var(--mute); font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; }

.side__nav { padding: 12px 10px; flex: 1; }
.side__nav a {
  display: block;
  padding: 10px 14px;
  margin-bottom: 2px;
  color: var(--ink-soft);
  font-weight: 500;
  font-size: .94rem;
  border-radius: var(--radius);
}
.side__nav a:hover { background: var(--line-soft); color: var(--ink); text-decoration: none; }
.side__nav a.is-active {
  background: var(--accent-soft);
  color: var(--accent-d);
  font-weight: 600;
}

.side__foot {
  padding: 12px 10px 20px;
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.side__foot a {
  padding: 8px 14px;
  color: var(--mute);
  font-size: .88rem;
  border-radius: var(--radius);
}
.side__foot a:hover { background: var(--line-soft); color: var(--ink); text-decoration: none; }

/* ---------- Main ---------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  padding: 18px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar__user { color: var(--mute); font-size: .9rem; }
.content { padding: 24px 32px 48px; }

/* ---------- Range bar ---------- */
.range-bar {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.range-bar__chips { display: flex; gap: 4px; flex-wrap: wrap; }
.range-bar__chips a {
  padding: 7px 14px;
  font-size: .85rem;
  font-weight: 500;
  color: var(--ink-soft);
  border-radius: var(--radius);
}
.range-bar__chips a:hover { color: var(--ink); background: var(--line-soft); text-decoration: none; }
.range-bar__chips a.is-active { background: var(--ink); color: #fff; }
.range-bar__custom { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; }
.range-bar__custom label { font-size: .82rem; font-weight: 500; color: var(--mute); display: flex; flex-direction: column; gap: 4px; }
.range-bar__custom input { padding: 6px 8px; border: 1px solid var(--line); border-radius: var(--radius); }

/* ---------- Stat cards ---------- */
.stat-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  margin-bottom: 20px;
}
.stat {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.stat__label { font-size: .78rem; color: var(--mute); font-weight: 500; }
.stat__value { font-size: 1.9rem; font-weight: 700; color: var(--ink); line-height: 1.1; letter-spacing: -0.02em; }
.stat__note { color: var(--mute); font-size: .76rem; }
.stat--good { border-left: 3px solid var(--ok); }
.stat--good .stat__value { color: var(--ok); }

/* ---------- Panels ---------- */
.panel {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 22px;
  margin-bottom: 18px;
}
.panel__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 16px;
  gap: 12px;
  flex-wrap: wrap;
}
.panel__head h2 small { color: var(--mute); font-weight: 400; font-size: .82rem; }
.panel--narrow { max-width: 540px; }
.panel--wide { grid-column: 1 / -1; }

.dash-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }

/* ---------- Tables ---------- */
.table-scroll { overflow-x: auto; }
.d-table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.d-table th {
  text-align: left;
  font-size: .74rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--mute);
  font-weight: 600;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}
.d-table td { padding: 11px 12px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
.d-table tbody tr:hover td { background: var(--bg); }

/* ---------- Pills ---------- */
.pill {
  display: inline-block;
  font-size: .72rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
  white-space: nowrap;
}
.pill--st-new       { background: var(--accent-soft); color: var(--accent-d); }
.pill--st-contacted { background: var(--warn-soft); color: var(--warn); }
.pill--st-quoted    { background: #FFEBC4; color: #6F4400; }
.pill--st-sold      { background: var(--ok-soft); color: var(--ok); }
.pill--st-shipped   { background: #D6F2FB; color: #035B82; }
.pill--st-completed { background: #C7ECC8; color: #1C5828; }
.pill--st-cancelled { background: var(--bad-soft); color: var(--bad); }
.pill--st-lost      { background: var(--line); color: var(--ink-soft); }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-weight: 600; font-size: .85rem; color: var(--ink); }
.field input,
.field select,
.field textarea {
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  width: 100%;
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: 0;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0,102,255,.12);
}
.field textarea { resize: vertical; min-height: 100px; font-family: inherit; }
.field small { color: var(--mute); font-size: .82rem; }
.field input[readonly], .field select:disabled { background: var(--line-soft); color: var(--mute); }

.inline-row { display: flex; gap: 14px; align-items: end; flex-wrap: wrap; }
.inline-row .field { flex: 1 1 200px; margin-bottom: 0; }
.field--actions { flex: 0 0 auto !important; }

.row-actions { display: flex; gap: 6px; white-space: nowrap; }

/* ---------- Buttons ---------- */
.d-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 9px 16px;
  font-family: var(--body);
  font-size: 13px;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  text-decoration: none;
  transition: background .15s, color .15s, border-color .15s;
  line-height: 1;
}
.d-btn:hover { text-decoration: none; }
.d-btn--primary { background: var(--ink); color: #fff; }
.d-btn--primary:hover { background: var(--accent); }
.d-btn--accent { background: var(--accent); color: #fff; }
.d-btn--accent:hover { background: var(--accent-d); }
.d-btn--ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.d-btn--ghost:hover { background: var(--line-soft); border-color: var(--ink); }
.d-btn--sm { padding: 6px 12px; font-size: 12px; }
.d-btn--block { display: flex; width: 100%; }

/* ---------- Filter bar ---------- */
.filter-bar {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1fr 1fr auto;
  gap: 12px;
  padding: 16px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  margin-bottom: 18px;
  align-items: end;
}
.filter-bar__group { display: flex; flex-direction: column; gap: 4px; }
.filter-bar__group label { font-size: .74rem; color: var(--mute); font-weight: 600; }
.filter-bar__group input, .filter-bar__group select {
  padding: 7px 10px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--paper);
}
.filter-bar__group--actions { display: flex; flex-direction: row; gap: 6px; align-items: end; }

/* ---------- Alerts ---------- */
.alert {
  padding: 11px 16px;
  margin-bottom: 16px;
  border-left: 4px solid;
  border-radius: var(--radius);
  font-size: .92rem;
}
.alert--good { background: var(--ok-soft); color: var(--ok); border-color: var(--ok); }
.alert--bad  { background: var(--bad-soft); color: var(--bad); border-color: var(--bad); }
.alert--warn { background: var(--warn-soft); color: var(--warn); border-color: var(--warn); }

/* ---------- KV ---------- */
.kv { display: grid; grid-template-columns: 1fr 2fr; gap: 8px 16px; margin: 0; }
.kv--2 { grid-template-columns: repeat(2, auto 1fr); }
.kv dt { font-weight: 600; color: var(--mute); font-size: .85rem; padding: 6px 0; border-bottom: 1px solid var(--line-soft); }
.kv dd { margin: 0; padding: 6px 0; border-bottom: 1px solid var(--line-soft); }
.addr { background: var(--line-soft); padding: 14px; border-radius: var(--radius); line-height: 1.6; margin: 0; }
.back-link { display: inline-block; margin-bottom: 14px; color: var(--mute); font-weight: 500; }

/* ---------- Charts ---------- */
.chart { display: block; width: 100%; height: auto; }
.chart-empty { color: var(--mute); text-align: center; padding: 40px 20px; font-style: italic; }

.hbar { display: flex; flex-direction: column; gap: 8px; }
.hbar__row { display: grid; grid-template-columns: 160px 1fr 50px; gap: 12px; align-items: center; }
.hbar__label { font-size: .88rem; font-weight: 500; }
.hbar__track { background: var(--line-soft); height: 14px; border-radius: 7px; overflow: hidden; }
.hbar__fill { background: var(--accent); height: 100%; transition: width .3s ease; border-radius: 7px; }
.hbar__fill--st-new       { background: var(--accent); }
.hbar__fill--st-contacted { background: var(--warn); }
.hbar__fill--st-quoted    { background: #C4861A; }
.hbar__fill--st-sold      { background: var(--ok); }
.hbar__fill--st-shipped   { background: #0E7AAA; }
.hbar__fill--st-completed { background: #1C5828; }
.hbar__fill--st-cancelled { background: var(--bad); }
.hbar__fill--st-lost      { background: var(--mute); }
.hbar__count { text-align: right; font-weight: 600; color: var(--ink); font-size: .95rem; }

.funnel { display: flex; flex-direction: column; gap: 12px; }
.funnel__row { display: grid; grid-template-columns: 160px 1fr 60px; gap: 14px; align-items: center; }
.funnel__label { font-weight: 600; font-size: .92rem; }
.funnel__bar { background: var(--line-soft); height: 28px; border-radius: var(--radius); overflow: hidden; }
.funnel__fill {
  background: linear-gradient(90deg, var(--accent) 0%, var(--accent-d) 100%);
  height: 100%;
  display: flex;
  align-items: center;
  padding: 0 12px;
  color: #fff;
  font-weight: 600;
  font-size: .9rem;
  border-radius: var(--radius);
  transition: width .4s ease;
}
.funnel__pct { font-weight: 700; color: var(--ink); }

/* ---------- Login ---------- */
.dash--login {
  display: grid;
  place-items: center;
  background: var(--bg);
  padding: 24px;
}
.dash--login::before {
  content: '';
  position: fixed;
  top: -300px; right: -300px;
  width: 700px; height: 700px;
  background: radial-gradient(circle, rgba(0,102,255,0.06) 0%, transparent 70%);
  pointer-events: none;
}
.login-wrap { width: 100%; max-width: 420px; position: relative; }
.login-card {
  background: var(--paper);
  padding: 36px 32px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-md);
}
.login-card__brand { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.login-card__mark {
  width: 44px; height: 44px;
  background: var(--ink);
  color: #fff;
  font-weight: 700;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-size: 13px;
}
.login-card__brand strong { display: block; color: var(--ink); font-weight: 700; font-size: 1rem; }
.login-card__brand small { font-size: .7rem; color: var(--mute); text-transform: uppercase; letter-spacing: .08em; }
.login-card h1 { margin-bottom: 4px; }
.login-card__sub { color: var(--mute); margin: 0 0 20px; font-size: .92rem; }

/* ---------- Misc ---------- */
.muted { color: var(--mute); }
.small { font-size: .85rem; }
.empty { color: var(--mute); padding: 20px 0; text-align: center; }

/* ---------- Mobile ---------- */
@media (max-width: 900px) {
  body.dash { flex-direction: column; }
  .side { width: 100%; height: auto; position: static; flex-direction: row; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .side__brand { border-bottom: 0; border-right: 1px solid var(--line); flex-shrink: 0; }
  .side__nav { display: flex; padding: 12px; flex: 1; overflow-x: auto; }
  .side__nav a { margin: 0 4px 0 0; padding: 8px 12px; white-space: nowrap; }
  .side__foot { display: none; }
  .topbar { padding: 14px 18px; }
  .content { padding: 18px; }
  .dash-grid-2 { grid-template-columns: 1fr; }
  .filter-bar { grid-template-columns: 1fr 1fr; }
  .hbar__row { grid-template-columns: 110px 1fr 40px; }
  .funnel__row { grid-template-columns: 120px 1fr 50px; }
}
@media (max-width: 560px) {
  .filter-bar { grid-template-columns: 1fr; }
  .stat__value { font-size: 1.5rem; }
  .range-bar { flex-direction: column; align-items: stretch; }
  .range-bar__custom { justify-content: space-between; }
}
/* ---------- Mobile improvements ---------- */
@media (max-width: 768px) {
  /* Hide table on mobile, show card-style stacks */
  .d-table thead { display: none; }
  .d-table tbody tr {
    display: block;
    margin-bottom: 12px;
    padding: 12px;
    background: #fff;
    border: 1px solid var(--line);
  }
  .d-table tbody td {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 6px 0;
    border-bottom: 1px dashed var(--line);
    gap: 12px;
  }
  .d-table tbody td:last-child { border-bottom: 0; padding-top: 10px; }
  .d-table tbody td::before {
    content: attr(data-label);
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .06em;
    font-weight: 700;
    color: var(--mute);
    flex-shrink: 0;
  }
  /* For when data-label is not set, hide the prefix */
  .d-table tbody td:empty::before { content: ''; }

  /* Bigger touch targets */
  .d-btn, .d-btn--sm { min-height: 40px; }

  /* Stat values smaller */
  .stat__value { font-size: 1.6rem; }

  /* Charts scale */
  .chart { max-width: 100%; height: auto; }
  .hbar__row { grid-template-columns: 90px 1fr 36px; }
  .funnel__row { grid-template-columns: 100px 1fr 40px; }
  .funnel__fill { font-size: .8rem; padding: 0 8px; }

  /* Range bar stacks */
  .range-bar__chips { width: 100%; }
  .range-bar__chips a { flex: 1 1 auto; text-align: center; }
  .range-bar__custom { width: 100%; justify-content: space-between; }

  /* Filter bar stacks */
  .filter-bar { grid-template-columns: 1fr; gap: 10px; padding: 14px; }

  /* KV stacks */
  .kv { grid-template-columns: 1fr; gap: 4px; }
  .kv dt { padding: 6px 0 0; border-bottom: 0; }
  .kv dd { padding: 0 0 8px; border-bottom: 1px solid var(--line-soft); }
  .kv--2 { grid-template-columns: 1fr; }

  /* Login card padding */
  .login-card { padding: 28px 22px; }
}


/* ============ Status pill colors ============ */
.st-pill {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}
.st-received   { background: #dbeafe; color: #1e40af; }
.st-reviewing  { background: #fef3c7; color: #92400e; }
.st-confirmed  { background: #d1fae5; color: #065f46; }
.st-shipped    { background: #e0e7ff; color: #3730a3; }
.st-in-transit { background: #cffafe; color: #155e75; }
.st-delivered  { background: #d1fae5; color: #064e3b; }
.st-cancelled  { background: #fee2e2; color: #991b1b; }

/* ============ Tracking URL box (on order detail page) ============ */
.tracking-url-box {
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 16px 20px;
    margin: 16px 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}
.tracking-url-box__label {
    font-size: 0.85rem;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
    margin-bottom: 4px;
}
.tracking-url-box__url {
    font-family: 'Courier New', monospace;
    font-size: 0.85rem;
    color: #111827;
    word-break: break-all;
}
.tracking-url-box__copy-btn {
    background: #C8102E;
    color: white;
    border: 0;
    padding: 8px 16px;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    font-size: 0.85rem;
}
.tracking-url-box__copy-btn:hover { opacity: 0.9; }
.tracking-url-box__copied {
    color: #059669;
    font-weight: 600;
    font-size: 0.85rem;
    display: none;
}

/* ============ Status history timeline ============ */
.status-history {
    margin: 24px 0;
    padding: 20px;
    background: #f9fafb;
    border-radius: 8px;
}
.status-history__entry {
    padding: 10px 0;
    border-left: 2px solid #e5e7eb;
    padding-left: 16px;
    margin-bottom: 12px;
    position: relative;
}
.status-history__entry::before {
    content: '';
    position: absolute;
    left: -7px;
    top: 14px;
    width: 12px;
    height: 12px;
    background: #6b7280;
    border-radius: 50%;
}
.status-history__entry--cancelled::before { background: #ef4444; }
.status-history__when { font-size: 0.85rem; color: #6b7280; }
.status-history__change { font-weight: 600; margin: 4px 0; }
.status-history__reason { color: #6b7280; font-size: 0.9rem; margin-top: 4px; }

/* ============ Cancel reason field (shown on status change to Cancelled) ============ */
.cancel-reason-wrap { display: none; margin-top: 12px; }
.cancel-reason-wrap.is-visible { display: block; }
.cancel-reason-wrap textarea {
    width: 100%;
    min-height: 80px;
    padding: 8px 12px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-family: inherit;
    font-size: 0.95rem;
}
.cancel-reason-wrap__quick-fills {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}
.cancel-reason-wrap__quick-fill {
    background: #f3f4f6;
    border: 1px solid #d1d5db;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 0.8rem;
    cursor: pointer;
}
.cancel-reason-wrap__quick-fill:hover { background: #e5e7eb; }
