:root {
  --etsy: #f56400;
  --etsy-dark: #d94f00;
  --bg: #f7f5f2;
  --card: #ffffff;
  --ink: #1a1a1a;
  --muted: #6b6b6b;
  --line: #e7e3dd;
  --good: #1a7f37;
  --shopA: #f56400;
  --shopB: #2e7cf6;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  overscroll-behavior-y: none;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.err { color: #c0392b; font-size: 14px; }

/* ---------- gate ---------- */
.gate {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.gate-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 28px 22px;
  width: 100%;
  max-width: 360px;
  text-align: center;
}
.brand { font-size: 24px; font-weight: 700; margin-bottom: 6px; }
.gate-card form { display: flex; flex-direction: column; gap: 12px; margin-top: 14px; }
input[type="password"], input[type="text"] {
  padding: 14px;
  font-size: 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: none;
}
input:focus { border-color: var(--etsy); }

.btn {
  border: none;
  border-radius: 10px;
  padding: 13px 16px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.btn-primary { background: var(--etsy); color: #fff; }
.btn-primary:active { background: var(--etsy-dark); }
.btn-ghost { background: transparent; color: var(--etsy); border: 1px solid var(--etsy); }
.btn-sm { padding: 8px 12px; font-size: 13px; }

/* ---------- app shell ---------- */
.app { min-height: 100dvh; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  padding: calc(10px + var(--safe-top)) 14px 10px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.brand-sm { font-weight: 700; font-size: 16px; }

.segmented { display: flex; background: var(--bg); border-radius: 999px; padding: 3px; }
.segmented button {
  border: none; background: transparent; color: var(--muted);
  padding: 7px 12px; font-size: 13px; font-weight: 600; border-radius: 999px; cursor: pointer;
}
.segmented button.active { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); }

.connect-strip { padding: 0 14px; }
.connect-card {
  margin-top: 12px; background: var(--card); border: 1px dashed var(--etsy);
  border-radius: var(--radius); padding: 16px; text-align: center;
}

.view { flex: 1; padding: 12px 14px calc(84px + var(--safe-bot)); }

/* cards */
.section-title { font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin: 16px 4px 8px; }
.shop-tag { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 700; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.dot.a { background: var(--shopA); }
.dot.b { background: var(--shopB); }

.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px; margin-bottom: 10px;
}
.order { display: flex; gap: 12px; align-items: flex-start; }
.order .meta { flex: 1; min-width: 0; }
.order .buyer { font-weight: 600; }
.order .items { font-size: 13px; color: var(--muted); margin-top: 2px; }
.order .total { font-weight: 700; white-space: nowrap; }
.row-actions { margin-top: 10px; display: flex; gap: 8px; }

.listing { display: flex; gap: 12px; align-items: center; }
.listing img { width: 56px; height: 56px; border-radius: 8px; object-fit: cover; background: var(--bg); }
.listing .l-title { font-size: 14px; font-weight: 600; line-height: 1.25; }
.listing .l-sub { font-size: 12px; color: var(--muted); margin-top: 3px; }
.badge { font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 999px; background: var(--bg); }
.badge.low { background: #fdecec; color: #c0392b; }

/* stats */
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px;
}
.stat .k { font-size: 12px; color: var(--muted); font-weight: 600; }
.stat .v { font-size: 22px; font-weight: 800; margin-top: 4px; }

/* messages placeholder */
.placeholder { text-align: center; padding: 30px 16px; color: var(--muted); }
.placeholder .big { font-size: 40px; }

/* empty / loading */
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }
.spinner {
  width: 26px; height: 26px; border: 3px solid var(--line); border-top-color: var(--etsy);
  border-radius: 50%; animation: spin 0.8s linear infinite; margin: 30px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* tab bar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  background: var(--card); border-top: 1px solid var(--line);
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding-bottom: var(--safe-bot);
}
.tab {
  border: none; background: transparent; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 9px 0 8px; font-size: 18px; color: var(--muted);
}
.tab span { font-size: 10px; font-weight: 600; }
.tab.active { color: var(--etsy); }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: calc(80px + var(--safe-bot)); transform: translateX(-50%);
  background: #1a1a1a; color: #fff; padding: 10px 16px; border-radius: 999px;
  font-size: 13px; z-index: 50; max-width: 90%;
}

.notif-banner {
  margin: 12px 14px 0; background: #fff7ef; border: 1px solid #ffd8b3;
  border-radius: var(--radius); padding: 12px; display: flex; gap: 10px; align-items: center;
}
.notif-banner .txt { flex: 1; font-size: 13px; }

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17150f; --card: #211e18; --ink: #f2efe9; --muted: #a7a196; --line: #332f27;
  }
  .segmented { background: #17150f; }
  .badge { background: #17150f; }
}
