/* Earthy farm theme — matches 3strands.co */
:root {
  --font-display: 'Newsreader', 'Source Serif 4', Georgia, serif;
  --font-body: 'Geist', -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;

  --bg: #F5F0E1;            /* cream */
  --card: #FFFEF9;          /* warm white */
  --border: #DED6C8;        /* sand gray */
  --text: #2E241A;          /* dark earth */
  --muted: #6F6355;
  --accent: #5C4033;        /* saddle brown */
  --accent-dark: #3D2B22;
  --accent-contrast: #FFFEF9;
  --gold: #C9A227;
  --danger: #B3362B;
  --warn: #92660B;
  --ok: #2F7D46;
  --soft: #F7F3EB;
  --hover: #F0EBE3;
  --accent-soft: #EDE4D3;   /* ivory */
  --accent-soft-border: #D9CDBF;
  --chip-bg: #EDE4D3;
  --chip-text: #564A3D;
  --danger-soft: #F8EAE4;
  --danger-border: #E3C3B8;
  --ok-soft: #EAF2E4;
  --ok-border: #C6D9BC;
  --toast-bg: #2E241A;
  --toast-text: #F5F0E1;
  --focus-ring: rgba(92, 64, 51, .18);
  --radius: 10px;
  --shadow: 0 1px 3px rgba(46, 36, 26, .1);
  color-scheme: light;
}
html[data-theme="dark"] {
  --bg: #1F1810;            /* deep earth */
  --card: #2E241A;
  --border: #433929;
  --text: #F0EBE3;
  --muted: #9C8E7C;
  --accent: #D4B84A;        /* gold takes over in the dark */
  --accent-dark: #C9A227;
  --accent-contrast: #1F1810;
  --gold: #D4B84A;
  --danger: #E8836F;
  --warn: #F0B44C;
  --ok: #7DC98F;
  --soft: #281F14;
  --hover: #3A2E1F;
  --accent-soft: #3B2F15;
  --accent-soft-border: #6B5A2A;
  --chip-bg: #433929;
  --chip-text: #D9CDBF;
  --danger-soft: #40241D;
  --danger-border: #6B3C30;
  --ok-soft: #22331F;
  --ok-border: #3D5C36;
  --toast-bg: #F0EBE3;
  --toast-text: #2E241A;
  --focus-ring: rgba(212, 184, 74, .25);
  --shadow: 0 1px 3px rgba(0, 0, 0, .45);
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-body);
  background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.45;
}
h1 { font-family: var(--font-display); font-size: 26px; font-weight: 600; margin: 0; letter-spacing: .01em; }
h2 { font-family: var(--font-display); font-size: 18px; font-weight: 600; margin: 0; }
a { color: var(--accent); text-decoration: none; }

/* ---------------- layout ---------------- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px; flex-shrink: 0; background: var(--card); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 16px 10px; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 10px 18px; }
.brand-mark { width: 42px; height: 42px; object-fit: contain; flex-shrink: 0; }
.brand-name { font-family: var(--font-display); font-weight: 600; font-size: 15px; line-height: 1.15; }
.brand-name span { font-weight: 500; color: var(--muted); font-size: 12px; }
.loc-switch {
  display: flex; align-items: center; gap: 8px; margin: 0 6px 14px; padding: 7px 10px;
  border: 1px solid var(--border); border-radius: 8px; background: var(--soft);
}
.loc-switch svg { width: 16px; height: 16px; fill: var(--accent); flex-shrink: 0; }
.loc-switch select {
  border: none; background: none; padding: 0; font-weight: 600; width: 100%; cursor: pointer;
}
.loc-switch select:focus { box-shadow: none; }
nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-link {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px;
  color: var(--text); font-weight: 500;
}
.nav-link svg { width: 18px; height: 18px; fill: var(--muted); flex-shrink: 0; }
.nav-link:hover { background: var(--hover); }
.nav-link.active { background: var(--accent-soft); color: var(--accent); }
.nav-link.active svg { fill: var(--accent); }
.nav-badge {
  margin-left: auto; background: var(--danger); color: #fff; border-radius: 10px;
  font-size: 11px; padding: 1px 7px; font-weight: 700;
}
.sidebar-foot { padding: 0 6px; display: flex; flex-direction: column; gap: 2px; }
.whoami { font-size: 12px; padding: 4px 10px; }
.main { flex: 1; padding: 26px 32px 96px; min-width: 0; }
.view-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }

/* ---------------- cards / stats ---------------- */
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px; margin-bottom: 18px;
}
.card-head { margin-bottom: 10px; }
.table-card { padding: 0; overflow-x: auto; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px 18px;
}
.stat .stat-label { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.stat .stat-value { font-family: var(--font-display); font-size: 26px; font-weight: 600; margin-top: 4px; }
.stat.stat-warn .stat-value { color: var(--warn); }
.stat.stat-danger .stat-value { color: var(--danger); }

/* ---------------- toolbar ---------------- */
.toolbar { display: flex; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; align-items: center; }
.search-input { flex: 1; min-width: 220px; }
input[type="search"], input[type="text"], input[type="number"], input[type="password"], select, textarea {
  font: inherit; padding: 8px 11px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--card); color: var(--text); outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus-ring); }
.check-label { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-weight: 500; }

.bulkbar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  background: var(--accent-soft); border: 1px solid var(--accent-soft-border);
  padding: 8px 12px; border-radius: 8px; margin-bottom: 12px; font-weight: 600;
}

/* ---------------- table ---------------- */
.items-table { width: 100%; border-collapse: collapse; }
.items-table th, .items-table td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--border); }
.items-table th {
  font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted);
  font-weight: 600; white-space: nowrap; background: var(--soft);
}
.items-table tbody tr:hover { background: var(--hover); cursor: pointer; }
.items-table tbody tr:last-child td { border-bottom: none; }
.items-table .num { text-align: right; }
.col-check { width: 34px; }
.sortable { cursor: pointer; user-select: none; }
.sortable.sorted-asc::after { content: " ▲"; font-size: 9px; }
.sortable.sorted-desc::after { content: " ▼"; font-size: 9px; }
.item-name { font-weight: 600; }
.item-sub { color: var(--muted); font-size: 12px; }
.chip {
  display: inline-block; background: var(--chip-bg); border-radius: 20px; padding: 2px 10px;
  font-size: 12px; font-weight: 500; color: var(--chip-text);
}
.row-active { background: var(--accent-soft); }
.actions-cell { white-space: nowrap; }
.loc-line { font-size: 12px; color: var(--muted); white-space: nowrap; }
.loc-line strong { color: var(--text); }
.loc-overview-head { padding: 16px 18px 6px; margin-bottom: 0; }
.stock-pill { font-weight: 700; }
.stock-pill.out { color: var(--danger); }
.stock-pill.low { color: var(--warn); }
.stock-pill.ok { color: var(--ok); }
.empty { padding: 34px; text-align: center; color: var(--muted); }
.muted { color: var(--muted); }

/* ---------------- buttons ---------------- */
.btn {
  font: inherit; font-weight: 600; padding: 8px 15px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--border); background: var(--card); color: var(--text); display: inline-flex;
  align-items: center; gap: 6px; text-decoration: none;
}
.btn:hover { background: var(--hover); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.btn-primary:hover { background: var(--accent-dark); }
.btn-danger { color: var(--danger); border-color: var(--danger-border); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-sm { padding: 5px 11px; font-size: 13px; }
.btn-ghost { border: none; background: none; color: var(--muted); width: 100%; }
.btn-block { width: 100%; justify-content: center; }
.icon-btn {
  border: none; background: none; font-size: 16px; cursor: pointer; color: var(--muted);
  padding: 6px; border-radius: 6px;
}
.icon-btn:hover { background: var(--hover); }
.spacer { flex: 1; }

/* ---------------- drawer ---------------- */
.drawer-overlay, .modal-overlay {
  position: fixed; inset: 0; background: rgba(20,22,26,.45); z-index: 40;
}
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: 480px; max-width: 95vw; background: var(--card);
  z-index: 50; display: flex; flex-direction: column; box-shadow: -8px 0 30px rgba(0,0,0,.15);
}
.drawer-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.drawer-body { flex: 1; overflow-y: auto; padding: 18px 20px; }
.drawer-foot {
  display: flex; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--border); align-items: center;
}
.drawer-sub { font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 20px 0 8px; }
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 13px; }
.field > span { font-weight: 600; font-size: 13px; }
.field input, .field select, .field textarea { width: 100%; }
.field-row { display: flex; gap: 14px; align-items: center; }
.field-row .field { flex: 1; }
.archived-check { margin-top: 10px; }
.variation-editor {
  border: 1px solid var(--border); border-radius: 8px; padding: 14px; margin-bottom: 12px; background: var(--soft);
}
.variation-editor .vhead { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.variation-editor .vhead strong { font-size: 13px; }
.vgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; }
.vgrid .field { margin-bottom: 0; }
.stock-block { margin-top: 12px; }
.stock-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.stock-table th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); padding: 4px 8px; border-bottom: 1px solid var(--border);
}
.stock-table td { padding: 6px 8px; border-bottom: 1px solid var(--border); }
.stock-table tr:last-child td { border-bottom: none; }
.stock-table .num { text-align: right; }
.stock-table .qty { font-weight: 700; }
.mini { width: 84px; padding: 5px 8px; text-align: right; }

/* ---------------- modal ---------------- */
.modal-overlay { display: flex; align-items: center; justify-content: center; z-index: 60; }
.modal { background: var(--card); border-radius: 12px; width: 440px; max-width: 92vw; box-shadow: 0 12px 40px rgba(0,0,0,.25); }
.modal-body { padding: 18px 20px; max-height: 60vh; overflow-y: auto; }
.history-details summary { cursor: pointer; font-weight: 600; color: var(--muted); margin-top: 6px; }
.history-row { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.history-row:last-child { border-bottom: none; }

/* ---------------- import ---------------- */
.import-row { display: flex; gap: 10px; align-items: center; margin-top: 10px; flex-wrap: wrap; }
.import-result { margin-top: 12px; padding: 12px; border-radius: 8px; background: var(--ok-soft); border: 1px solid var(--ok-border); }
.import-result.err { background: var(--danger-soft); border-color: var(--danger-border); }

/* ---------------- theme toggle ---------------- */
.theme-fab {
  /* bottom-right so it never covers page headers; sits below overlays (z 40+)
     so open drawers/modals cover it rather than the other way around */
  position: fixed; bottom: 18px; right: 20px; z-index: 35;
  width: 42px; height: 42px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--card); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow);
}
.theme-fab svg { width: 20px; height: 20px; fill: var(--warn); }
html[data-theme="dark"] .theme-fab svg { fill: var(--gold); }
.theme-fab:hover { background: var(--hover); }

/* ---------------- toast ---------------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--toast-bg); color: var(--toast-text); padding: 10px 18px; border-radius: 8px; z-index: 100;
  font-weight: 600; box-shadow: 0 4px 16px rgba(0,0,0,.3);
}

/* ---------------- login ---------------- */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card {
  background: var(--card); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow);
  padding: 36px; width: 340px; display: flex; flex-direction: column; gap: 12px; text-align: center;
}
.login-card h1 { font-size: 24px; }
.login-sub { color: var(--muted); margin: 0 0 6px; }
.login-logo { width: 84px; height: 84px; object-fit: contain; margin: 0 auto; }
.login-error { background: var(--danger-soft); border: 1px solid var(--danger-border); color: var(--danger); border-radius: 8px; padding: 8px; }

/* ---------------- responsive ---------------- */
@media (max-width: 1100px) {
  /* trim secondary columns first */
  #view-items .items-table th:nth-child(6), #view-items .items-table td:nth-child(6),   /* cost */
  #view-items .items-table th:nth-child(7), #view-items .items-table td:nth-child(7) {  /* margin */
    display: none;
  }
}

@media (max-width: 860px) {
  /* sidebar becomes a sticky top bar */
  .layout { flex-direction: column; }
  .sidebar {
    width: 100%; height: auto; position: sticky; top: 0; z-index: 30;
    flex-flow: row wrap; align-items: center; gap: 8px; padding: 10px 12px;
    border-right: none; border-bottom: 1px solid var(--border);
  }
  .brand { padding: 0; }
  .brand-name { display: none; }
  .brand-mark { width: 34px; height: 34px; }
  .loc-switch { flex: 1; min-width: 140px; margin: 0; }
  nav {
    order: 3; flex-basis: 100%; flex-direction: row; gap: 4px;
    overflow-x: auto; -webkit-overflow-scrolling: touch;
  }
  .nav-link { white-space: nowrap; padding: 7px 10px; font-size: 13px; }
  .sidebar-foot { flex-direction: row; padding: 0; gap: 0; }
  .whoami { display: none; }
  .sidebar-foot .btn-ghost { width: auto; font-size: 13px; padding: 6px 8px; }

  .main { padding: 14px 12px 92px; }
  .view-head { margin-bottom: 12px; }
  .view-head h1 { font-size: 22px; }
  .stat-grid { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; }
  .stat { padding: 12px 14px; }
  .stat .stat-value { font-size: 21px; }
  .items-table th, .items-table td { padding: 9px 10px; }
  .card { padding: 14px; }
  .table-card { padding: 0; }

  .theme-fab { right: 14px; }

  /* full-width editor drawer */
  .drawer { width: 100vw; max-width: 100vw; }

  /* hide more secondary columns */
  #view-items .items-table th:nth-child(4), #view-items .items-table td:nth-child(4) { display: none; }        /* sku */
  #view-lowstock .items-table th:nth-child(5), #view-lowstock .items-table td:nth-child(5) { display: none; }  /* alert at */
  #view-history .items-table th:nth-child(6), #view-history .items-table td:nth-child(6) { display: none; }    /* new qty */
  #view-users .items-table th:nth-child(3), #view-users .items-table td:nth-child(3) { display: none; }        /* created */
  #view-locations .items-table th:nth-child(3), #view-locations .items-table td:nth-child(3) { display: none; }/* skus */
  #view-locations .items-table th:nth-child(4), #view-locations .items-table td:nth-child(4) { display: none; }/* created */
  #loc-overview .items-table th:nth-child(3), #loc-overview .items-table td:nth-child(3) { display: none; }    /* retail */
}

@media (max-width: 560px) {
  /* prevent iOS focus-zoom and tighten further */
  input[type="search"], input[type="text"], input[type="number"], input[type="password"], select, textarea {
    font-size: 16px;
  }
  .vgrid { grid-template-columns: 1fr; }
  .field-row { flex-direction: column; align-items: stretch; }
  #view-items .items-table th:nth-child(3), #view-items .items-table td:nth-child(3) { display: none; }        /* category */
  #view-lowstock .items-table th:nth-child(2), #view-lowstock .items-table td:nth-child(2) { display: none; }  /* category */
  #view-history .items-table th:nth-child(7), #view-history .items-table td:nth-child(7) { display: none; }    /* note */
  .drawer-foot { flex-wrap: wrap; }
  .modal { width: 96vw; max-width: 96vw; }
  .login-card { width: 92vw; padding: 26px; }
}
