:root {
  --primary:    #C4785A;
  --primary-lt: #F0D9CE;
  --bg:         #F8F5F1;
  --card:       #FFFFFF;
  --text:       #2D2D2D;
  --muted:      #888888;
  --green:      #4A8C5C;
  --green-lt:   #DCF0E3;
  --red:        #C05050;
  --red-lt:     #FDEAEA;
  --amber:      #C08030;
  --amber-lt:   #FFF3DC;
  --border:     #EBEBEB;
  --nav-h:      64px;
  --top-h:      52px;
  --radius:     12px;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  overscroll-behavior: none;
}

/* ── Overlay ── */
.overlay {
  position: fixed; inset: 0; z-index: 100;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
}
.seller-box {
  text-align: center; padding: 40px 32px;
  display: flex; flex-direction: column; align-items: center; gap: 16px;
}
.seller-logo { font-size: 56px; }
.seller-box h1 { font-size: 26px; font-weight: 700; color: var(--primary); }
.seller-box p  { color: var(--muted); font-size: 16px; }
.seller-btn {
  width: 220px; padding: 18px;
  background: var(--primary); color: #fff;
  border: none; border-radius: var(--radius);
  font-size: 20px; font-weight: 600; cursor: pointer;
  transition: opacity .15s;
}
.seller-btn:active { opacity: .75; }

/* ── App shell ── */
#app { height: 100%; display: flex; flex-direction: column; }

/* Top bar */
#topbar {
  height: var(--top-h);
  background: var(--card);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
  position: sticky; top: 0; z-index: 10;
}
#topbar-title { font-size: 18px; font-weight: 700; color: var(--primary); }
#seller-badge {
  background: var(--primary-lt); color: var(--primary);
  padding: 5px 12px; border-radius: 20px;
  font-size: 13px; font-weight: 600; cursor: pointer;
}

/* Main content */
#main-content {
  flex: 1; overflow: hidden; position: relative;
}
.view {
  position: absolute; inset: 0;
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  display: none;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom));
}
.view.active { display: block; }

/* Bottom nav */
#bottom-nav {
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--card);
  border-top: 1px solid var(--border);
  display: flex;
  position: sticky; bottom: 0; z-index: 10;
}
.nav-btn {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 3px;
  background: none; border: none; cursor: pointer;
  color: var(--muted);
  transition: color .15s;
}
.nav-btn.active { color: var(--primary); }
.nav-icon  { font-size: 22px; }
.nav-label { font-size: 11px; font-weight: 500; }

/* ── Cards ── */
.card {
  background: var(--card);
  border-radius: var(--radius);
  margin: 10px 12px;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
  overflow: hidden;
}

/* Series card */
.series-card {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px; cursor: pointer;
  transition: background .1s;
}
.series-card:active { background: var(--bg); }
.series-card + .series-card { border-top: 1px solid var(--border); }
.series-info { flex: 1; }
.series-name { font-size: 16px; font-weight: 600; }
.series-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.series-metres {
  font-size: 14px; font-weight: 700; color: var(--primary);
  white-space: nowrap;
}
.series-arrow { color: var(--muted); font-size: 18px; }

.series-img {
  width: 52px; height: 52px; border-radius: 8px;
  object-fit: cover; flex-shrink: 0;
}
.series-img-placeholder {
  width: 52px; height: 52px; border-radius: 8px;
  background: var(--primary-lt);
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; flex-shrink: 0;
}

/* Expanded fabrics inside series */
.series-fabrics { background: var(--bg); }

/* Fabric row */
.fabric-row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px; cursor: pointer;
  border-top: 1px solid var(--border);
  transition: background .1s;
}
.fabric-row:active { background: var(--primary-lt); }
.fabric-img {
  width: 44px; height: 44px; border-radius: 6px;
  object-fit: cover; flex-shrink: 0;
}
.fabric-img-ph {
  background: var(--primary-lt);
}
.fabric-info { flex: 1; min-width: 0; }
.fabric-name { font-size: 13px; font-weight: 600; line-height: 1.3; }
.fabric-sub  { font-size: 12px; color: var(--muted); margin-top: 1px; }
.stock-pill {
  padding: 4px 10px; border-radius: 12px;
  font-size: 13px; font-weight: 700; white-space: nowrap;
}
.stock-good   { background: var(--green-lt);  color: var(--green); }
.stock-low    { background: var(--amber-lt);  color: var(--amber); }
.stock-zero   { background: #f0f0f0;           color: var(--muted); }

/* Search bar */
.search-bar { padding: 12px; background: var(--bg); position: sticky; top: 0; z-index: 5; }
.search-bar input {
  width: 100%; padding: 10px 14px;
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 15px; color: var(--text);
  outline: none;
}
.search-bar input:focus { border-color: var(--primary); }

/* Customer card */
.customer-card {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px; cursor: pointer;
  transition: background .1s;
}
.customer-card:active { background: var(--bg); }
.customer-card + .customer-card { border-top: 1px solid var(--border); }
.customer-avatar {
  width: 40px; height: 40px; border-radius: 20px;
  background: var(--primary-lt); color: var(--primary);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; font-weight: 700; flex-shrink: 0;
}
.customer-info { flex: 1; }
.customer-name { font-size: 16px; font-weight: 600; }
.customer-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.customer-total { font-size: 14px; font-weight: 700; color: var(--primary); }

/* Section header */
.section-hdr {
  padding: 16px 16px 6px;
  font-size: 12px; font-weight: 700;
  color: var(--muted); letter-spacing: .06em; text-transform: uppercase;
}

.empty-state {
  text-align: center; padding: 60px 24px;
  color: var(--muted); font-size: 15px;
}
.empty-state .emoji { font-size: 48px; margin-bottom: 12px; }

/* ── Sheet ── */
#sheet-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0,0,0,.35);
  backdrop-filter: blur(2px);
}
#sheet {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 60;
  background: var(--card);
  border-radius: 20px 20px 0 0;
  max-height: 92vh;
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  transition: transform .3s ease;
  padding-bottom: env(safe-area-inset-bottom);
}
#sheet.slide-in  { transform: translateY(0); }
.sheet-handle {
  width: 36px; height: 4px;
  background: #ddd; border-radius: 2px;
  margin: 10px auto 4px;
}

/* Sheet content */
.sheet-header {
  padding: 10px 20px 16px;
  border-bottom: 1px solid var(--border);
}
.sheet-series   { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.sheet-title    { font-size: 20px; font-weight: 700; margin-top: 2px; }
.sheet-subtitle { font-size: 13px; color: var(--muted); margin-top: 2px; }

.stock-display {
  text-align: center; padding: 20px 20px 12px;
}
.stock-big {
  font-size: 48px; font-weight: 800; line-height: 1;
}
.stock-label { font-size: 14px; color: var(--muted); margin-top: 4px; }

/* Action buttons */
.action-row {
  display: flex; gap: 10px;
  padding: 0 20px 16px;
}
.btn {
  flex: 1; padding: 14px;
  border: none; border-radius: var(--radius);
  font-size: 16px; font-weight: 700; cursor: pointer;
  transition: opacity .15s;
}
.btn:active { opacity: .75; }
.btn-sell    { background: var(--primary); color: #fff; }
.btn-restock { background: var(--green-lt); color: var(--green); }
.btn-cancel  { background: var(--bg); color: var(--muted); }
.btn-confirm { background: var(--green); color: #fff; }

/* Sell form */
.sell-form {
  padding: 0 20px 20px;
  border-top: 1px solid var(--border);
  margin-top: 4px;
}
.sell-form h3 { padding: 14px 0 12px; font-size: 16px; }
.field-label { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field-input {
  width: 100%; padding: 12px 14px;
  background: var(--bg); border: 1.5px solid var(--border);
  border-radius: 10px; font-size: 16px; color: var(--text);
  outline: none; margin-bottom: 14px;
}
.field-input:focus { border-color: var(--primary); background: #fff; }

/* Metres stepper */
.stepper {
  display: flex; align-items: center; gap: 0;
  background: var(--bg); border: 1.5px solid var(--border);
  border-radius: 10px; overflow: hidden; margin-bottom: 14px;
}
.stepper-btn {
  width: 52px; height: 50px;
  background: none; border: none; cursor: pointer;
  font-size: 22px; font-weight: 300; color: var(--primary);
  transition: background .1s;
}
.stepper-btn:active { background: var(--primary-lt); }
.stepper-val {
  flex: 1; text-align: center;
  font-size: 20px; font-weight: 700;
}
.stepper-unit { font-size: 13px; color: var(--muted); font-weight: 400; }

/* Transaction history */
.txn-list { padding: 0 20px 8px; }
.txn-list-hdr {
  font-size: 12px; font-weight: 700;
  color: var(--muted); letter-spacing: .05em; text-transform: uppercase;
  padding: 12px 0 8px;
  border-top: 1px solid var(--border);
}
.txn-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 0; border-top: 1px solid var(--border);
}
.txn-customer { flex: 1; font-size: 14px; font-weight: 500; }
.txn-meta     { font-size: 12px; color: var(--muted); }
.txn-metres   { font-size: 14px; font-weight: 700; }
.txn-sale     { color: var(--red); }
.txn-restock  { color: var(--green); }

/* Customer detail */
.order-row {
  padding: 12px 20px; border-top: 1px solid var(--border);
}
.order-fabric { font-size: 14px; font-weight: 600; }
.order-sub    { font-size: 12px; color: var(--muted); margin-top: 2px; }
.order-row-meta {
  display: flex; justify-content: space-between;
  margin-top: 4px;
  font-size: 13px; color: var(--muted);
}
.order-rrp { font-weight: 600; color: var(--text); }

.total-row {
  display: flex; justify-content: space-between;
  padding: 16px 20px;
  background: var(--primary-lt);
  font-weight: 700; font-size: 16px; color: var(--primary);
}

/* Success toast */
#toast {
  position: fixed; bottom: 100px; left: 50%; transform: translateX(-50%);
  background: var(--green); color: #fff;
  padding: 12px 24px; border-radius: 24px;
  font-size: 15px; font-weight: 600;
  box-shadow: 0 4px 16px rgba(0,0,0,.2);
  opacity: 0; pointer-events: none;
  transition: opacity .3s;
  white-space: nowrap; z-index: 200;
}
#toast.show { opacity: 1; }

.hidden { display: none !important; }
