/* BuggyBricks Order Tracker — styles */
:root, html[data-theme="light"] {
  --primary: #2563eb;
  --accent: #f59e0b;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface2: #eef0f3;
  --text: #1c2330;
  --muted: #68707e;
  --border: #d9dde3;
  --danger: #c0392b;
  --ok: #1e8449;
  --warn: #b7950b;
  --shadow: 0 8px 30px rgba(0,0,0,.18);
}
html[data-theme="dark"] {
  --bg: #14171c;
  --surface: #1e232b;
  --surface2: #262c36;
  --text: #e8ebef;
  --muted: #9aa3b0;
  --border: #39404c;
  --shadow: 0 8px 30px rgba(0,0,0,.5);
}
@media (prefers-color-scheme: dark) {
  html[data-theme="system"] {
    --bg: #14171c; --surface: #1e232b; --surface2: #262c36;
    --text: #e8ebef; --muted: #9aa3b0; --border: #39404c;
    --shadow: 0 8px 30px rgba(0,0,0,.5);
  }
}
* { box-sizing: border-box; }
body { margin: 0; font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
h1, h2, h3 { margin: 0 0 .5rem; }
a { color: var(--primary); }

/* ---------- buttons & forms ---------- */
.btn { border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: .45rem .8rem; border-radius: 8px; cursor: pointer; font-size: .92rem; }
.btn:hover { border-color: var(--primary); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.btn.accent { background: var(--accent); border-color: var(--accent); color: #1c2330; font-weight: 600; }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.ghost { background: transparent; }
.btn.big { width: 100%; padding: .7rem; font-size: 1rem; }
.btn.small { padding: .25rem .55rem; font-size: .85rem; }
label { display: block; font-size: .8rem; font-weight: 600; letter-spacing: .02em; color: var(--muted); margin: .6rem 0 .25rem; text-transform: uppercase; }
input, select, textarea { width: 100%; padding: .5rem .6rem; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text); font-size: .95rem; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 0; }
.form-error { color: var(--danger); min-height: 1.2em; font-size: .9rem; }
.row { display: flex; gap: .6rem; flex-wrap: wrap; }
.row > * { flex: 1; }
.checkline { display: flex; align-items: center; gap: .5rem; text-transform: none; font-size: .95rem; color: var(--text); }
.checkline input { width: auto; }

/* ---------- auth ---------- */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.auth-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 2rem; width: 100%; max-width: 380px; text-align: center; box-shadow: var(--shadow); }
.auth-card form { text-align: left; margin-top: 1rem; }
.auth-logo { font-size: 2.6rem; }
.auth-switch { font-size: .9rem; margin-top: .8rem; }

/* ---------- layout ---------- */
#app-view { display: flex; min-height: 100vh; }
#sidebar { width: 230px; flex: 0 0 230px; background: var(--surface); border-right: 1px solid var(--border);
  padding: 1rem; display: flex; flex-direction: column; gap: 1rem; position: sticky; top: 0; height: 100vh; }
.shop-brand { display: flex; gap: .6rem; align-items: center; }
.brand-logo { width: 44px; height: 44px; object-fit: contain; border-radius: 8px; }
.brand-name { font-weight: 700; font-size: 1.05rem; }
.brand-sub { color: var(--muted); font-size: .8rem; word-break: break-all; }
#sidebar nav { display: flex; flex-direction: column; gap: .3rem; }
.nav-btn { text-align: left; border: none; background: transparent; color: var(--text); padding: .6rem .7rem;
  border-radius: 8px; cursor: pointer; font-size: .98rem; }
.nav-btn:hover { background: var(--surface2); }
.nav-btn.active { background: var(--primary); color: #fff; font-weight: 600; }
.logout { margin-top: auto; }
#main { flex: 1; padding: 1.2rem; max-width: 1100px; margin: 0 auto; width: 100%; }

/* ---------- generic UI ---------- */
.toolbar { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; margin-bottom: 1rem; }
.toolbar .spacer { flex: 1; }
.toolbar input[type="search"] { max-width: 260px; }
.toolbar select { width: auto; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 1rem; margin-bottom: .8rem; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: .6rem; }
.badge { display: inline-block; padding: .12rem .55rem; border-radius: 999px; font-size: .78rem; font-weight: 700; }
.badge.paid { background: #d5f5e3; color: var(--ok); }
.badge.partial { background: #fcf3cf; color: var(--warn); }
.badge.unpaid { background: #fadbd8; color: var(--danger); }
.badge.cancelled { background: var(--surface2); color: var(--muted); }
html[data-theme="dark"] .badge.paid, html[data-theme="dark"] .badge.partial, html[data-theme="dark"] .badge.unpaid { filter: brightness(.85); }
.menu-wrap { position: relative; }
.menu { position: absolute; right: 0; top: 110%; background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: var(--shadow); min-width: 170px; z-index: 40; padding: .3rem; }
.menu button { display: block; width: 100%; text-align: left; background: none; border: none; color: var(--text);
  padding: .5rem .6rem; border-radius: 6px; cursor: pointer; font-size: .92rem; }
.menu button:hover { background: var(--surface2); }
.menu button.danger { color: var(--danger); }
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: .6rem; margin-top: .6rem; }
.kv .k { background: var(--surface2); border-radius: 8px; padding: .5rem .6rem; }
.kv .k .lab { font-size: .72rem; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.kv .k .val { font-size: 1.05rem; font-weight: 700; margin-top: .15rem; }
table.plain { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.plain th, table.plain td { text-align: left; padding: .45rem .5rem; border-bottom: 1px solid var(--border); }
table.plain th { color: var(--muted); font-size: .75rem; text-transform: uppercase; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: .8rem; margin-bottom: 1rem; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: .9rem 1rem; }
.stat .lab { color: var(--muted); font-size: .78rem; text-transform: uppercase; font-weight: 700; }
.stat .val { font-size: 1.5rem; font-weight: 800; margin-top: .2rem; }
.bar-row { display: flex; align-items: center; gap: .6rem; margin: .35rem 0; font-size: .9rem; }
.bar-row .bar-lab { width: 110px; color: var(--muted); }
.bar-track { flex: 1; background: var(--surface2); border-radius: 6px; height: 18px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 6px; }
.feed-item { padding: .45rem 0; border-bottom: 1px solid var(--border); font-size: .93rem; }
.feed-item:last-child { border-bottom: none; }
.part-img { width: 44px; height: 44px; object-fit: contain; background: #fff; border: 1px solid var(--border); border-radius: 6px; }
.line-row { display: grid; grid-template-columns: 92px 1fr auto; gap: .6rem; align-items: end;
  border: 1px solid var(--border); border-radius: 10px; padding: .6rem; margin-bottom: .6rem; background: var(--surface2); }
.line-row .fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: .5rem; }
.color-list { max-height: 130px; overflow: auto; border: 1px solid var(--border); border-radius: 8px; padding: .4rem; background: var(--surface); }
.color-list label { display: flex; gap: .45rem; align-items: center; text-transform: none; color: var(--text); font-size: .9rem; margin: .25rem 0; font-weight: 400; }
.color-list input { width: auto; }
.detail-panel { border-left: 3px solid var(--accent); }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: .7rem 1.1rem; border-radius: 10px; box-shadow: var(--shadow); z-index: 200; max-width: 90vw; font-size: .95rem; }

/* ---------- modal ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: flex-start; justify-content: center;
  overflow-y: auto; padding: 1rem; z-index: 100; }
.modal { background: var(--surface); color: var(--text); border-radius: 14px; padding: 1.2rem; width: 100%; max-width: 640px; box-shadow: var(--shadow); margin: auto 0; }
.modal.wide { max-width: 780px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: .5rem; }
.x-btn { background: none; border: none; font-size: 1.3rem; cursor: pointer; color: var(--muted); }

/* ---------- order sheet ---------- */
.sheet { background: #fff; color: #111; padding: 1.4rem; font-size: 14px; }
.sheet h2 { margin-bottom: .2rem; }
.sheet table { width: 100%; border-collapse: collapse; margin: 1rem 0; }
.sheet th, .sheet td { border-bottom: 1px solid #ccc; padding: .4rem .45rem; text-align: left; }
.sheet th { font-size: .72rem; text-transform: uppercase; color: #555; }
.sheet .totals { margin-left: auto; width: 280px; }
.sheet .totals td { border-bottom: none; padding: .25rem .45rem; }
.sheet .totals .grand td { font-weight: 800; border-top: 2px solid #111; }
.sheet-head { display: flex; justify-content: space-between; gap: 1rem; }
.sheet-logo { max-width: 110px; max-height: 70px; object-fit: contain; }
.print-only { display: none; }

@media print {
  body * { visibility: hidden; }
  #print-area, #print-area * { visibility: visible; }
  #print-area { display: block; position: absolute; inset: 0; }
  .no-print { display: none !important; }
}

/* ---------- small screens ---------- */
@media (max-width: 720px) {
  #app-view { flex-direction: column; }
  #sidebar { width: 100%; flex: none; height: auto; position: static; flex-direction: row; flex-wrap: wrap; align-items: center; }
  #sidebar nav { flex-direction: row; flex-wrap: wrap; }
  .logout { margin-top: 0; margin-left: auto; }
  #main { padding: .8rem; }
  .line-row { grid-template-columns: 64px 1fr auto; }
}
