/* ── Variables ──────────────────────────────────────────────────────────────── */
:root {
  --orange:     #E8521A;
  --orange-lt:  #F07040;
  --orange-bg:  #FBE8E0;
  --cream:      #FAF7F2;
  --ink:        #1A1208;
  --ink-80:     #3A2E1E;
  --ink-60:     #6B5E48;
  --ink-30:     #B8AC9A;
  --border:     #E8E2D9;
  --green:      #2A9D5C;
  --green-bg:   #D4F0E3;
  --red:        #D63B3B;
  --red-bg:     #FAE0E0;
  --radius:     10px;
  --shadow:     0 2px 12px rgba(26,18,8,.07);
  --transition: .18s ease;
}

/* ── Reset / Base ────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body {
  font-family: 'Quicksand', sans-serif;
  background: var(--cream);
  color: var(--ink);
  min-height: 100vh;
}

/* ── Login ───────────────────────────────────────────────────────────────────── */
.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--ink);
}
.login-box {
  background: var(--cream);
  border-radius: 16px;
  padding: 2.5rem 2rem;
  width: 340px;
  text-align: center;
  box-shadow: 0 8px 40px rgba(0,0,0,.4);
}
.login-box .logo-text {
  font-size: 2.8rem;
  margin-bottom: .25rem;
}
.login-sub {
  color: var(--ink-60);
  font-size: .95rem;
  margin-bottom: 1.5rem;
}
.login-box input {
  width: 100%;
  padding: .7rem 1rem;
  border: 2px solid var(--border);
  border-radius: 8px;
  font-family: 'Quicksand', sans-serif;
  font-size: .95rem;
  margin-bottom: .75rem;
  outline: none;
  transition: border-color var(--transition);
  background: white;
}
.login-box input:focus { border-color: var(--orange); }
.login-box button {
  width: 100%;
  padding: .75rem;
  background: var(--orange);
  color: white;
  border: none;
  border-radius: 8px;
  font-family: 'Quicksand', sans-serif;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: background var(--transition);
}
.login-box button:hover { background: var(--orange-lt); }
.login-error {
  color: var(--red);
  font-size: .85rem;
  margin-top: .5rem;
  min-height: 1.2em;
}

/* ── App layout ──────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }

.header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: .75rem 1.5rem;
  background: var(--ink);
  color: white;
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
}
.header-left { display: flex; align-items: baseline; gap: .5rem; flex-shrink: 0; }
.header-sub { font-size: .85rem; color: var(--ink-30); font-weight: 500; }

.tabs {
  display: flex;
  gap: .25rem;
  flex: 1;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  padding: .45rem .9rem;
  background: transparent;
  color: rgba(255,255,255,.6);
  border: none;
  border-radius: 6px;
  font-family: 'Quicksand', sans-serif;
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--transition);
}
.tab:hover { background: rgba(255,255,255,.1); color: white; }
.tab.active { background: var(--orange); color: white; }

.sync-btn {
  flex-shrink: 0;
  padding: .4rem .8rem;
  background: rgba(255,255,255,.12);
  color: white;
  border: 1px solid rgba(255,255,255,.2);
  border-radius: 6px;
  font-family: 'Quicksand', sans-serif;
  font-size: .8rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition);
  white-space: nowrap;
}
.sync-btn:hover { background: rgba(255,255,255,.2); }

/* ── Tab content ─────────────────────────────────────────────────────────────── */
.tab-content {
  padding: 1.5rem;
  max-width: 1280px;
  margin: 0 auto;
}

.logo-text {
  font-family: 'Caveat', cursive;
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--orange);
  letter-spacing: .03em;
}

.section-title {
  font-family: 'Caveat', cursive;
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 1rem;
}

.section-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}
.section-header .section-title { margin-bottom: 0; }

.hint {
  color: var(--ink-60);
  font-size: .88rem;
  margin-bottom: 1rem;
}

/* ── Stat grid ───────────────────────────────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: .75rem;
  margin-bottom: 1.5rem;
}
.stat-grid.small { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
.stat-card {
  background: white;
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  transition: transform var(--transition);
}
.stat-card:hover { transform: translateY(-2px); }
.stat-card.highlight {
  background: var(--orange);
  border-color: var(--orange);
  color: white;
}
.stat-card.highlight .stat-label { color: rgba(255,255,255,.8); }
.stat-label { font-size: .78rem; font-weight: 600; color: var(--ink-60); text-transform: uppercase; letter-spacing: .04em; margin-bottom: .4rem; }
.stat-value { font-size: 1.7rem; font-weight: 700; font-family: 'Caveat', cursive; }

/* ── Cards ───────────────────────────────────────────────────────────────────── */
.card {
  background: white;
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}
.card h3 {
  font-family: 'Caveat', cursive;
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: .75rem;
  color: var(--ink);
}
.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .75rem;
}
@media (max-width: 680px) { .two-col { grid-template-columns: 1fr; } }

/* ── Split chart ─────────────────────────────────────────────────────────────── */
.split-bar-wrap {
  display: flex;
  height: 28px;
  border-radius: 6px;
  overflow: hidden;
  background: var(--border);
  margin-bottom: .6rem;
}
.split-bar {
  background: var(--orange);
  transition: width .5s ease;
}
.split-bar.one-time {
  background: var(--ink-30);
}
.split-labels {
  display: flex;
  gap: 1.5rem;
  font-size: .85rem;
  font-weight: 600;
}
.dot {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 50%;
  margin-right: .3rem;
}
.dot.sub { background: var(--orange); }
.dot.ot { background: var(--ink-30); }

.pack-row {
  display: flex;
  justify-content: space-between;
  padding: .45rem 0;
  border-bottom: 1px solid var(--border);
  font-size: .9rem;
}
.pack-row:last-child { border-bottom: none; }
.pack-row span:last-child { font-weight: 700; }

/* ── Tables ──────────────────────────────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  background: white;
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .88rem;
}
.data-table thead {
  background: var(--ink);
  color: white;
  position: sticky;
  top: 0;
}
.data-table thead th {
  padding: .7rem 1rem;
  text-align: left;
  font-weight: 600;
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  white-space: nowrap;
}
.data-table tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}
.data-table tbody tr:hover { background: var(--cream); }
.data-table tbody tr:last-child { border-bottom: none; }
.data-table tbody td {
  padding: .65rem 1rem;
  vertical-align: middle;
}

/* ── Status badges ───────────────────────────────────────────────────────────── */
.status-badge {
  display: inline-block;
  padding: .2rem .6rem;
  border-radius: 20px;
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .03em;
}
.status-badge.unfulfilled { background: var(--orange-bg); color: var(--orange); }
.status-badge.fulfilled   { background: var(--green-bg);  color: var(--green);  }
.status-badge.refunded    { background: var(--red-bg);    color: var(--red);    }
.status-badge.active      { background: var(--green-bg);  color: var(--green);  }
.status-badge.canceled    { background: var(--red-bg);    color: var(--red);    }
.status-badge.sub         { background: var(--orange-bg); color: var(--orange); }
.status-badge.one-time    { background: #EEE; color: var(--ink-60); }

/* ── Action buttons ──────────────────────────────────────────────────────────── */
.btn {
  display: inline-block;
  padding: .35rem .75rem;
  border-radius: 6px;
  border: none;
  font-family: 'Quicksand', sans-serif;
  font-size: .8rem;
  font-weight: 700;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}
.btn-orange { background: var(--orange); color: white; }
.btn-orange:hover { background: var(--orange-lt); }
.btn-ghost { background: transparent; color: var(--orange); border: 1.5px solid var(--orange); }
.btn-ghost:hover { background: var(--orange-bg); }
.btn-green { background: var(--green); color: white; }
.btn-green:hover { filter: brightness(1.1); }
.btn-sm { padding: .25rem .55rem; font-size: .75rem; }

/* ── Search / filter ─────────────────────────────────────────────────────────── */
.search-wrap {
  display: flex;
  gap: .5rem;
  flex: 1;
  min-width: 0;
}
input[type="text"], input[type="search"], select {
  padding: .5rem .9rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-family: 'Quicksand', sans-serif;
  font-size: .9rem;
  outline: none;
  background: white;
  color: var(--ink);
  transition: border-color var(--transition);
}
input[type="text"]:focus, input[type="search"]:focus, select:focus { border-color: var(--orange); }
#orders-search, #customers-search { flex: 1; min-width: 0; }

/* ── Pagination ──────────────────────────────────────────────────────────────── */
.pagination {
  display: flex;
  gap: .4rem;
  margin-top: .75rem;
  flex-wrap: wrap;
}
.pagination button {
  padding: .3rem .65rem;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  background: white;
  font-family: 'Quicksand', sans-serif;
  font-size: .82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
}
.pagination button.active { background: var(--orange); color: white; border-color: var(--orange); }
.pagination button:hover:not(.active) { border-color: var(--orange); color: var(--orange); }

/* ── Badge ────────────────────────────────────────────────────────────────────── */
.badge {
  background: var(--orange);
  color: white;
  padding: .2rem .6rem;
  border-radius: 20px;
  font-size: .78rem;
  font-weight: 700;
}

/* ── Fulfillment queue ───────────────────────────────────────────────────────── */
.fulfillment-list { display: flex; flex-direction: column; gap: .75rem; }
.fulfill-card {
  background: white;
  border-radius: var(--radius);
  border: 1.5px solid var(--border);
  padding: 1rem 1.25rem;
  box-shadow: var(--shadow);
}
.fulfill-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: .5rem;
  margin-bottom: .6rem;
}
.fulfill-name { font-weight: 700; font-size: 1rem; }
.fulfill-meta { font-size: .83rem; color: var(--ink-60); margin-top: .15rem; }
.fulfill-address {
  background: var(--cream);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: .5rem .75rem;
  font-size: .9rem;
  line-height: 1.6;
  margin-bottom: .75rem;
}
.fulfill-actions {
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
  align-items: center;
}
.tracking-input {
  padding: .32rem .7rem;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  font-family: 'Quicksand', sans-serif;
  font-size: .85rem;
  width: 180px;
  outline: none;
  transition: border-color var(--transition);
}
.tracking-input:focus { border-color: var(--green); }

/* ── Bar chart (MRR trend) ───────────────────────────────────────────────────── */
.bar-chart {
  display: flex;
  align-items: flex-end;
  gap: .4rem;
  height: 120px;
  padding: 0 .25rem;
}
.bar-chart-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .3rem;
  height: 100%;
  justify-content: flex-end;
}
.bar-chart-bar {
  width: 100%;
  background: var(--orange);
  border-radius: 4px 4px 0 0;
  min-height: 2px;
  transition: height .4s ease;
}
.bar-chart-label { font-size: .65rem; color: var(--ink-60); white-space: nowrap; }
.bar-chart-val { font-size: .7rem; font-weight: 700; color: var(--ink); }

/* ── Funnel ──────────────────────────────────────────────────────────────────── */
.funnel-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  max-width: 400px;
  margin: 0 auto;
}
.funnel-step {
  width: 100%;
  background: white;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  text-align: center;
  transition: border-color var(--transition), transform var(--transition);
}
.funnel-step.highlight {
  border-color: var(--orange);
  background: var(--orange-bg);
}
.funnel-step:hover { transform: scale(1.01); }
.funnel-label { font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-60); margin-bottom: .3rem; }
.funnel-count { font-family: 'Caveat', cursive; font-size: 2.2rem; font-weight: 700; line-height: 1; margin-bottom: .2rem; }
.funnel-pct { font-size: .85rem; font-weight: 600; color: var(--orange); }
.funnel-arrow { font-size: 1.2rem; color: var(--ink-30); padding: .2rem 0; }

/* ── Code snippet ────────────────────────────────────────────────────────────── */
.code-snippet {
  background: var(--ink);
  color: #C5E07A;
  padding: 1rem 1.25rem;
  border-radius: 8px;
  font-family: 'Courier New', monospace;
  font-size: .78rem;
  line-height: 1.6;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

/* ── Customer drawer ─────────────────────────────────────────────────────────── */
.drawer {
  position: fixed;
  right: 0; top: 0; bottom: 0;
  width: min(480px, 100vw);
  background: var(--cream);
  box-shadow: -4px 0 24px rgba(0,0,0,.15);
  z-index: 200;
  overflow-y: auto;
  padding: 1.5rem;
  transform: translateX(0);
  transition: transform .25s ease;
}
.drawer.hidden { transform: translateX(100%); display: block !important; pointer-events: none; }
.drawer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}
.drawer-header h3 { font-family: 'Caveat', cursive; font-size: 1.4rem; }
.drawer-header button {
  background: none; border: none; font-size: 1.2rem; cursor: pointer; color: var(--ink-60);
  transition: color var(--transition);
}
.drawer-header button:hover { color: var(--red); }

/* ── Toast ────────────────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: white;
  padding: .6rem 1.5rem;
  border-radius: 24px;
  font-size: .9rem;
  font-weight: 600;
  z-index: 300;
  opacity: 0;
  transition: opacity .2s ease;
  pointer-events: none;
}
.toast.show { opacity: 1; }

/* ── Misc ─────────────────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 3rem;
  color: var(--ink-60);
  font-size: .95rem;
}
.empty-state .empty-icon { font-size: 2.5rem; margin-bottom: .5rem; }
.sub-chip  { font-size: .75rem; }
.customer-link { color: var(--orange); cursor: pointer; font-weight: 600; text-decoration: underline; text-decoration-color: transparent; transition: text-decoration-color var(--transition); }
.customer-link:hover { text-decoration-color: var(--orange); }

/* ── Responsive ──────────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  .tab-content { padding: 1rem; }
  .header { padding: .6rem 1rem; }
  .stat-value { font-size: 1.4rem; }
}
