/* ==========================================================================
   Purkhe admin
   The storefront is editorial; this is a workbench. Same palette so it feels
   like one product, but denser, plainer, and built for scanning fast.
   ========================================================================== */

:root {
  /* Same brand pair as the storefront: oxblood and gold from the logo. */
  --paper: #f4efe7;
  --card: #ffffff;
  --ink: #2e1a1c;
  --ink-soft: #6b5253;
  --ink-faint: #9a8384;
  --rule: #e0d5c6;
  --oxblood: #74252b;
  --gold: #d3aa72;
  --accent: #74252b;
  --accent-soft: #f6e9d9;
  --ok: #2f7a55;
  --ok-soft: #e3f2ea;
  --warn: #9a6a12;
  --warn-soft: #fbf1dc;
  --danger: #a33323;
  --danger-soft: #fbe6e2;
  --radius: 6px;
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 15px/1.55 Karla, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}

a { color: var(--accent); }
img { max-width: 100%; display: block; }

h1, h2, h3 { margin: 0; line-height: 1.2; font-weight: 600; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }

/* ---------------------------------------------------------------- shell -- */
.layout { display: grid; grid-template-columns: 15rem 1fr; min-height: 100vh; }

.sidebar {
  background: var(--oxblood);
  color: #cfd6e2;
  padding: 1.25rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1.4rem;
}
.sidebar .brand {
  font-family: Fraunces, Georgia, serif;
  font-size: 1.3rem;
  color: var(--gold);
  text-decoration: none;
  line-height: 1;
}
.sidebar .brand small { display: block; font-size: 0.68rem; color: #8b96ab; font-family: Karla, sans-serif; letter-spacing: 0.06em; margin-top: 0.3rem; }
.sidebar nav { display: flex; flex-direction: column; gap: 0.15rem; }
.sidebar nav a {
  color: #cfd6e2;
  text-decoration: none;
  padding: 0.5rem 0.65rem;
  border-radius: var(--radius);
  font-size: 0.92rem;
  display: flex; justify-content: space-between; align-items: center; gap: 0.5rem;
}
.sidebar nav a:hover { background: rgba(255,255,255,0.07); color: #fff; }
.sidebar nav a.active { background: rgba(255,255,255,0.14); color: #fff; font-weight: 600; }
.sidebar .spacer { flex: 1; }
.sidebar .who { font-size: 0.8rem; color: #8b96ab; border-top: 1px solid rgba(255,255,255,.12); padding-top: 0.9rem; }
.sidebar .who a { color: #cfd6e2; }

.content { padding: 1.75rem 2rem 4rem; max-width: 76rem; }


.page-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap; margin-bottom: 1.5rem;
}
.page-head p { margin: 0.35rem 0 0; color: var(--ink-soft); font-size: 0.92rem; }

/* ----------------------------------------------------------------- bits -- */
.card {
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}
.card > h2 { margin-bottom: 0.9rem; }
.card .hint { color: var(--ink-soft); font-size: 0.87rem; margin: -0.5rem 0 1rem; }

.grid { display: grid; gap: 1.25rem; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(20rem, 1fr)); }
.grid.stats { grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr)); }

.stat { background: var(--card); border: 1px solid var(--rule); border-radius: var(--radius); padding: 1rem; }
.stat .n { font-size: 1.9rem; font-family: Fraunces, Georgia, serif; line-height: 1; }
.stat .l { color: var(--ink-soft); font-size: 0.85rem; margin-top: 0.35rem; }
.stat a { text-decoration: none; }

table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
th, td { text-align: left; padding: 0.6rem 0.7rem; border-bottom: 1px solid var(--rule); vertical-align: top; }
th { color: var(--ink-soft); font-weight: 600; font-size: 0.82rem; }
tbody tr:hover { background: #fafaf8; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }

.pill {
  display: inline-block; padding: 0.15rem 0.55rem; border-radius: 999px;
  font-size: 0.76rem; font-weight: 600; white-space: nowrap;
  background: var(--accent-soft); color: var(--accent);
}
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.danger { background: var(--danger-soft); color: var(--danger); }
.pill.muted { background: #eceae5; color: var(--ink-soft); }

/* ---------------------------------------------------------------- forms -- */
label { display: block; font-weight: 600; font-size: 0.88rem; margin-bottom: 0.3rem; }
.field { margin-bottom: 1.1rem; }
.field .help { color: var(--ink-soft); font-size: 0.83rem; margin-top: 0.3rem; }

input[type=text], input[type=email], input[type=password], input[type=number],
select, textarea {
  width: 100%; padding: 0.55rem 0.7rem;
  border: 1px solid var(--rule); border-radius: var(--radius);
  background: #fff; color: var(--ink); font: inherit;
}
textarea { min-height: 7rem; resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.87rem; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }

.btn {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.55rem 1rem; border-radius: var(--radius);
  background: var(--ink); color: #fff; border: 1px solid var(--ink);
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn:hover { background: #5b1b20; }
.btn.secondary { background: #fff; color: var(--ink); border-color: var(--rule); }
.btn.secondary:hover { background: #f6f5f1; }
.btn.ok { background: var(--ok); border-color: var(--ok); }
.btn.danger { background: var(--danger); border-color: var(--danger); }
.btn.small { padding: 0.32rem 0.65rem; font-size: 0.85rem; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }

.actions { display: flex; gap: 0.6rem; flex-wrap: wrap; align-items: center; }

.flash { padding: 0.75rem 1rem; border-radius: var(--radius); margin-bottom: 1.25rem; font-size: 0.92rem; }
.flash.ok { background: var(--ok-soft); color: var(--ok); }
.flash.err { background: var(--danger-soft); color: var(--danger); }
.flash.warn { background: var(--warn-soft); color: var(--warn); }

/* -------------------------------------------------------------- login --- */
.login-page {
  min-height: 100vh; display: grid; place-items: center; padding: 2rem;
  background: var(--oxblood);
}
.login-card { background: var(--card); border-radius: 10px; padding: 2rem; width: min(100%, 24rem); }
.login-card .brand {
  font-family: Fraunces, Georgia, serif;
  font-size: 1.6rem;
  font-weight: 400;
  margin: 0 0 0.25rem;
  color: var(--oxblood);
}
.login-card .sub { color: var(--ink-soft); font-size: 0.9rem; margin-bottom: 1.5rem; }

/* ------------------------------------------------------------ whatsapp -- */
.wa-status { display: flex; align-items: center; gap: 0.7rem; font-weight: 600; }
.dot { width: 0.7rem; height: 0.7rem; border-radius: 50%; background: var(--ink-faint); flex: none; }
.dot.open { background: var(--ok); }
.dot.qr { background: var(--warn); }
.dot.err { background: var(--danger); }
.qr-box { text-align: center; padding: 1.5rem; }
.qr-box img { margin: 0 auto; border: 1px solid var(--rule); border-radius: var(--radius); }
.steps { counter-reset: s; padding-left: 0; list-style: none; max-width: 30rem; margin: 1.25rem auto 0; text-align: left; }
.steps li { counter-increment: s; padding: 0.3rem 0 0.3rem 2rem; position: relative; color: var(--ink-soft); font-size: 0.92rem; }
.steps li::before {
  content: counter(s); position: absolute; left: 0; top: 0.35rem;
  width: 1.4rem; height: 1.4rem; border-radius: 50%; background: var(--accent-soft);
  color: var(--accent); font-size: 0.78rem; font-weight: 700; display: grid; place-items: center;
}

/* ----------------------------------------------------------------- chat -- */
.chat { display: flex; flex-direction: column; gap: 0.55rem; max-height: 30rem; overflow-y: auto; padding: 0.5rem; background: #f7f6f2; border-radius: var(--radius); }
.bubble { max-width: 78%; padding: 0.55rem 0.8rem; border-radius: 12px; font-size: 0.92rem; white-space: pre-wrap; word-break: break-word; }
.bubble.in { align-self: flex-start; background: #fff; border: 1px solid var(--rule); }
.bubble.out { align-self: flex-end; background: var(--accent-soft); }
.bubble .meta { display: block; font-size: 0.7rem; color: var(--ink-faint); margin-top: 0.3rem; }

.empty { color: var(--ink-faint); text-align: center; padding: 2.5rem 1rem; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }


/* ==========================================================================
   MOBILE
   Shivi will run this shop from a phone, so the admin has to work there first.
   Below 56rem the sidebar becomes a slide-in drawer behind a top bar, and the
   data tables reflow into cards rather than scrolling sideways.
   ========================================================================== */

/* The drawer toggle is a hidden checkbox, so the nav works with CSS alone and
   never depends on JavaScript having loaded. */
#navToggle { position: absolute; opacity: 0; pointer-events: none; }

/* Both of these are mobile-only furniture. They MUST be display:none outside
   the media query — .scrim is a child of .layout, so leaving it displayed
   makes it a grid item that occupies the first cell and shunts the sidebar
   into column 2 and the content onto row 2. */
.topbar { display: none; }
.scrim  { display: none; }

@media (max-width: 56rem) {
  .layout { grid-template-columns: 1fr; }

  .topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    position: sticky;
    top: 0;
    z-index: 30;
    background: var(--oxblood);
    color: var(--gold);
    padding: 0.7rem 1rem;
  }
  .topbar .brand {
    font-family: Fraunces, Georgia, serif;
    font-size: 1.15rem;
    color: var(--gold);
    text-decoration: none;
  }
  .topbar .burger {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.4rem 0.7rem;
    border: 1px solid rgba(255,255,255,.28);
    border-radius: var(--radius);
    color: #fff;
    font: inherit;
    font-size: 0.88rem;
    cursor: pointer;
    background: none;
  }
  .topbar .burger svg { width: 1.05em; height: 1.05em; fill: currentColor; }
  .topbar .alert { background: var(--warn); color: #241a05; border-radius: 999px;
                   padding: 0 .4rem; font-size: .72rem; font-weight: 700; }

  .sidebar {
    position: fixed;
    inset: 0 30% 0 0;
    z-index: 40;
    overflow-y: auto;
    transform: translateX(-100%);
    transition: transform 220ms ease;
    box-shadow: 0 0 0 100vmax rgba(15, 20, 30, 0);
  }
  #navToggle:checked ~ .layout .sidebar {
    transform: translateX(0);
    box-shadow: 0 0 0 100vmax rgba(15, 20, 30, .45);
  }
  /* Tapping the dimmed area closes the drawer. Shown only while open. */
  #navToggle:checked ~ .layout .scrim {
    display: block; position: fixed; inset: 0; z-index: 35;
  }
  .sidebar nav a { padding: 0.7rem 0.65rem; font-size: 1rem; }

  .content { padding: 1.1rem 1rem 3.5rem; }
  .page-head { gap: 0.75rem; }
  .page-head h1 { font-size: 1.3rem; }

  .grid.two { grid-template-columns: 1fr; }
  .grid.stats { grid-template-columns: repeat(auto-fit, minmax(8.5rem, 1fr)); gap: 0.7rem; }
  .stat { padding: 0.8rem; }
  .stat .n { font-size: 1.45rem; }

  .card { padding: 1rem; }

  /* Sticky action bars must not eat half a small screen. */
  .card[style*="sticky"] { position: static !important; }

  /* --- tables become cards ------------------------------------------------
     Each row turns into a stacked block, with the column name from the
     cell's data-label. Reads far better than a sideways scroll on a phone. */
  table.reflow thead { display: none; }
  table.reflow, table.reflow tbody, table.reflow tr, table.reflow td {
    display: block; width: 100%;
  }
  table.reflow tr {
    border: 1px solid var(--rule);
    border-radius: var(--radius);
    padding: 0.7rem 0.85rem;
    margin-bottom: 0.7rem;
    background: #fff;
  }
  table.reflow tr:hover { background: #fff; }
  table.reflow td {
    border: none;
    padding: 0.2rem 0;
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 1rem;
    text-align: right;
  }
  table.reflow td::before {
    content: attr(data-label);
    color: var(--ink-soft);
    font-size: 0.8rem;
    font-weight: 600;
    text-align: left;
    flex: 0 0 auto;
  }
  /* A cell with no label (the lead cell) spans the row as a heading. */
  table.reflow td:not([data-label]) {
    display: block;
    text-align: left;
    font-size: 1.02rem;
    padding-bottom: 0.4rem;
  }
  table.reflow td.num { text-align: right; }
  table.reflow tfoot { display: block; }
  table.reflow tfoot tr { border: none; padding: 0; }

  .chat { max-height: 60vh; }
  .bubble { max-width: 88%; }

  /* Comfortable tap targets. */
  .btn { padding: 0.6rem 1rem; }
  .btn.small { padding: 0.4rem 0.7rem; }
  input, select, textarea { font-size: 16px; }  /* stops iOS zooming on focus */
}

@media (max-width: 30rem) {
  .actions { width: 100%; }
  .actions .btn { flex: 1 1 auto; justify-content: center; }
  .page-head { flex-direction: column; align-items: stretch; }
}

/* Invoice / packing slip / back, grouped in the order page header. */
.head-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
