/* =====================================================================
   State Side Auto Parts — admin dashboard stylesheet
   ===================================================================== */

:root {
  --navy-900: #0A1F33;
  --navy-800: #0F2A44;
  --navy-700: #163553;
  --navy-100: #E7ECF2;
  --paper:    #F6F7FA;
  --ink:      #1A1F2A;
  --muted:    #5B6573;
  --line:     #E1E5EC;
  --accent:   #E63946;
  --accent-d: #C92B38;
  --ok:       #1F8A4C;
  --warn:     #D38B16;
  --bad:      #C92B38;
  --info:     #1E6FB8;

  --shadow-sm: 0 1px 2px rgba(10,31,51,.06), 0 1px 3px rgba(10,31,51,.06);
  --shadow-md: 0 6px 18px rgba(10,31,51,.08), 0 2px 6px rgba(10,31,51,.06);
  --shadow-lg: 0 18px 40px rgba(10,31,51,.14);

  --radius: 12px;
  --radius-sm: 8px;
  --display: 'Georgia', 'Times New Roman', serif;
  --body: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; }

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

h1, h2, h3 {
  font-family: var(--display);
  color: var(--navy-900);
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.01em;
}
h1 { font-size: 1.5rem; }
h2 { font-size: 1.1rem; }

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

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

/* ---------- Sidebar ---------- */
.dash-sidebar {
  width: 260px;
  flex-shrink: 0;
  background: var(--navy-900);
  color: rgba(255,255,255,.85);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.dash-sidebar__brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 18px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.dash-sidebar__mark {
  width: 40px; height: 40px;
  background: var(--accent);
  color: #fff;
  font-family: var(--display);
  font-weight: 700;
  display: grid;
  place-items: center;
  border-radius: 10px;
}
.dash-sidebar__brand strong { color: #fff; font-family: var(--display); font-size: 1rem; display: block; }
.dash-sidebar__brand small  { font-size: .72rem; color: rgba(255,255,255,.6); text-transform: uppercase; letter-spacing: .08em; }
.dash-nav { padding: 16px 10px; flex: 1; }
.dash-nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border-radius: 8px;
  color: rgba(255,255,255,.78);
  font-weight: 500;
  margin-bottom: 4px;
}
.dash-nav a:hover { background: rgba(255,255,255,.06); color: #fff; text-decoration: none; }
.dash-nav a.is-active { background: rgba(230,57,70,.15); color: #fff; border-left: 3px solid var(--accent); padding-left: 11px; }
.dash-nav__ico { font-size: 1.05rem; opacity: .8; }
.dash-sidebar__foot {
  padding: 14px 10px 20px;
  border-top: 1px solid rgba(255,255,255,.08);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.dash-sidebar__foot a {
  padding: 10px 14px;
  border-radius: 8px;
  color: rgba(255,255,255,.7);
  font-size: .9rem;
}
.dash-sidebar__foot a:hover { background: rgba(255,255,255,.06); color: #fff; text-decoration: none; }

/* ---------- Main ---------- */
.dash-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.dash-topbar {
  background: #fff;
  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;
}
.dash-topbar__user { color: var(--muted); font-size: .9rem; }
.dash-content { padding: 28px 32px; }

/* ---------- Stat cards ---------- */
.stat-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  margin-bottom: 24px;
}
.stat-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.stat-card__label { font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; }
.stat-card__value { font-family: var(--display); font-size: 2rem; color: var(--navy-900); font-weight: 700; }
.stat-card__note  { color: var(--muted); font-size: .78rem; margin-top: 2px; }
.stat-card--good { border-left: 4px solid var(--ok); }
.stat-card--good .stat-card__value { color: var(--ok); }
.stat-card--bad  { border-left: 4px solid var(--bad); }
.stat-card--bad  .stat-card__value { color: var(--bad); }

/* ---------- Panels ---------- */
.panel {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 20px;
}
.panel__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  gap: 12px;
  flex-wrap: wrap;
}
.panel__head h2 small { color: var(--muted); font-family: var(--body); font-weight: 500; 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: 20px; }

/* ---------- Tables ---------- */
.table-scroll { overflow-x: auto; }
.dash-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .92rem;
}
.dash-table th {
  text-align: left;
  font-size: .76rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
  font-weight: 700;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: #fafbfc;
}
.dash-table td { padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.dash-table--zebra tbody tr:nth-child(odd) td { background: #fafbfc; }
.dash-table tbody tr:hover td { background: var(--navy-100); }

/* ---------- Status pills ---------- */
.status-pill {
  display: inline-block;
  font-size: .74rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  padding: 4px 10px;
  border-radius: 999px;
  white-space: nowrap;
}
.st-new         { background: #DCE7F5; color: #143E70; }
.st-contacted   { background: #FFF4D9; color: #6A4A05; }
.st-quoted      { background: #FAE3CC; color: #7A3F05; }
.st-sold        { background: #D4F0DC; color: #14542A; }
.st-shipped     { background: #E3D5F5; color: #4A1E73; }
.st-in-transit  { background: #C4ECF8; color: #0C547A; }
.st-completed   { background: #BFE5C8; color: #0E4523; }
.st-cancelled   { background: #FBDADD; color: #7A1822; }
.st-lost        { background: #E1E1E5; color: #4A4A52; }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-weight: 600; font-size: .85rem; color: var(--navy-900); }
.field input,
.field select,
.field textarea {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fff;
  width: 100%;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(230,57,70,.15);
}
.field textarea { resize: vertical; min-height: 100px; }
.field input[readonly], .field select:disabled { background: #f4f5f7; color: var(--muted); }
.field small { color: var(--muted); font-size: .82rem; }

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

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

/* ---------- Buttons ---------- */
.dash-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 8px;
  font-weight: 600;
  font-size: .9rem;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: background .15s ease, color .15s ease, border-color .15s ease;
  line-height: 1.2;
}
.dash-btn:hover { text-decoration: none; }
.dash-btn--primary { background: var(--accent); color: #fff; }
.dash-btn--primary:hover { background: var(--accent-d); }
.dash-btn--ghost { background: transparent; color: var(--navy-800); border-color: var(--line); }
.dash-btn--ghost:hover { background: var(--navy-100); border-color: var(--navy-700); }
.dash-btn--sm { padding: 6px 12px; font-size: .82rem; }

.btn { /* shared compat */
  display: inline-flex; align-items: center; justify-content: center;
  padding: 12px 20px; border-radius: 999px; font-weight: 600; cursor: pointer;
  border: 2px solid transparent; text-decoration: none;
}
.btn--primary { background: var(--accent); color: #fff; box-shadow: 0 6px 18px rgba(230,57,70,.2); }
.btn--primary:hover { background: var(--accent-d); }
.btn--block { width: 100%; }

/* ---------- Filter bar ---------- */
.filter-bar {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1fr 1fr auto;
  gap: 12px;
  padding: 16px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
  align-items: end;
}
.filter-bar__group { display: flex; flex-direction: column; gap: 4px; }
.filter-bar__group label { font-size: .76rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.filter-bar__group input, .filter-bar__group select {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fff;
}
.filter-bar__group--actions { display: flex; flex-direction: row; gap: 8px; align-items: end; }

/* ---------- Alerts ---------- */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  border-left: 4px solid;
}
.alert--good { background: #E6F4EA; color: #14542A; border-color: var(--ok); }
.alert--bad  { background: #FBE7E9; color: #7A1822; border-color: var(--bad); }
.alert--warn { background: #FFF4D9; color: #6A4A05; border-color: var(--warn); }

/* ---------- Definition lists ---------- */
.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(--muted); font-size: .85rem; padding: 6px 0; border-bottom: 1px solid var(--line); }
.kv dd { margin: 0; padding: 6px 0; border-bottom: 1px solid var(--line); }
.kv dt:last-of-type, .kv dd:last-of-type { border-bottom: 0; }
.addr { background: #fafbfc; border-radius: var(--radius-sm); padding: 14px; font-style: normal; line-height: 1.6; }

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

/* ---------- Login ---------- */
.dash-body--login {
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--navy-900) 0%, var(--navy-700) 100%);
  padding: 24px;
}
.login-wrap { width: 100%; max-width: 440px; }
.login-card {
  background: #fff;
  border-radius: var(--radius);
  padding: 36px 32px;
  box-shadow: var(--shadow-lg);
}
.login-card__brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}
.login-card__mark {
  width: 44px; height: 44px;
  background: var(--navy-800);
  color: var(--accent);
  font-family: var(--display);
  font-weight: 700;
  display: grid;
  place-items: center;
  border-radius: 10px;
}
.login-card__brand strong { color: var(--navy-900); font-family: var(--display); font-size: 1.05rem; display: block; }
.login-card__brand small  { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.login-card h1 { margin-bottom: 4px; }
.login-card__sub { color: var(--muted); margin: 0 0 20px; font-size: .92rem; }
.login-card__hint { color: var(--muted); font-size: .82rem; text-align: center; margin: 18px 0 0; }

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

/* ---------- Mobile ---------- */
@media (max-width: 900px) {
  body.dash-body { flex-direction: column; }
  .dash-sidebar {
    width: 100%;
    height: auto;
    position: static;
    flex-direction: row;
    overflow-x: auto;
  }
  .dash-sidebar__brand { border-bottom: 0; border-right: 1px solid rgba(255,255,255,.08); flex-shrink: 0; }
  .dash-nav { display: flex; padding: 12px; flex: 1; overflow-x: auto; }
  .dash-nav a { margin: 0 4px 0 0; padding: 9px 12px; white-space: nowrap; }
  .dash-nav a.is-active { border-left: 0; border-bottom: 3px solid var(--accent); padding-left: 12px; }
  .dash-sidebar__foot { display: none; }
  .dash-topbar { padding: 14px 18px; }
  .dash-content { padding: 18px; }
  .dash-grid-2 { grid-template-columns: 1fr; }
  .filter-bar { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 560px) {
  .filter-bar { grid-template-columns: 1fr; }
  .stat-card__value { font-size: 1.6rem; }
}
/* ---------- 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; }
}

/* ---------- Tracking URL box ---------- */
.tracking-url-box {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: #F7F3EE;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.tracking-url-box__label {
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
  margin-right: 4px;
}
.tracking-url-box__url {
  flex: 1;
  min-width: 200px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .85rem;
  color: var(--navy-900);
  word-break: break-all;
}
.tracking-url-box__copy {
  background: var(--navy-800);
  color: #fff;
  border: 0;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  font-size: .82rem;
  font-weight: 600;
  cursor: pointer;
}
.tracking-url-box__copy:hover { background: var(--navy-700); }
.tracking-url-box__copied {
  font-size: .8rem;
  font-weight: 600;
  color: var(--ok);
}
.tracking-url-box__copied[hidden] { display: none; }

/* ---------- Status history timeline ---------- */
.status-timeline { list-style: none; padding: 0; margin: 0; position: relative; }
.status-timeline::before {
  content: '';
  position: absolute;
  left: 8px; top: 6px; bottom: 6px;
  width: 2px;
  background: var(--line);
}
.status-timeline__item {
  position: relative;
  padding: 0 0 16px 28px;
  font-size: .9rem;
}
.status-timeline__item:last-child { padding-bottom: 0; }
.status-timeline__item::before {
  content: '';
  position: absolute;
  left: 2px; top: 4px;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--navy-800);
  border: 3px solid #fff;
  box-shadow: 0 0 0 1px var(--line);
}
.status-timeline__time {
  font-size: .76rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
}
.status-timeline__who { font-weight: 600; }
.status-timeline__change { margin: 2px 0; }
.status-timeline__reason {
  margin-top: 4px;
  padding: 8px 10px;
  background: #FBDADD;
  border-left: 3px solid var(--bad);
  font-size: .85rem;
  color: #7A1822;
  border-radius: 0 4px 4px 0;
}
.status-timeline__empty { color: var(--muted); font-style: italic; }

/* ---------- Cancel reason inline ---------- */
.cancel-reason {
  margin-top: 10px;
  padding: 12px;
  background: #FBDADD;
  border-left: 3px solid var(--bad);
  border-radius: 0 6px 6px 0;
}
.cancel-reason[hidden] { display: none; }
.cancel-reason label {
  display: block;
  font-weight: 600;
  font-size: .85rem;
  margin-bottom: 6px;
  color: #7A1822;
}
.cancel-reason textarea {
  width: 100%;
  min-height: 70px;
  padding: 8px 10px;
  border: 1px solid #E5B0B5;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: .9rem;
}
.cancel-reason__quick {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}
.cancel-reason__quick button {
  background: #fff;
  border: 1px solid #E5B0B5;
  color: #7A1822;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: .78rem;
  cursor: pointer;
}
.cancel-reason__quick button:hover { background: #FBDADD; }
