/* RepairDesk — blue/gray theme with light/dark modes */
:root {
  --bg: #f3f5f9;
  --surface: #ffffff;
  --raised: #f8fafc;
  --line: #e2e8f0;
  --ink: #0f172a;
  --muted: #64748b;
  --accent: #2563eb;
  --accent-ink: #ffffff;
  --accent-soft: #dbeafe;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --ok: #16a34a;
  --ok-soft: #dcfce7;
  --warn: #d97706;
  --warn-soft: #fef3c7;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 1px 2px rgba(15, 23, 42, .04);
}
[data-theme="dark"] {
  --bg: #0b1220;
  --surface: #101a2e;
  --raised: #16233c;
  --line: #23324e;
  --ink: #e6edf7;
  --muted: #8fa3bf;
  --accent: #3b82f6;
  --accent-ink: #ffffff;
  --accent-soft: #1e3a8a;
  --danger: #f87171;
  --danger-soft: #451a1a;
  --ok: #4ade80;
  --ok-soft: #14311f;
  --warn: #fbbf24;
  --warn-soft: #3a2c0e;
  --shadow: 0 1px 3px rgba(0, 0, 0, .4);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; letter-spacing: -.01em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }

/* ---- Shell layout ---- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 232px; flex-shrink: 0; display: flex; flex-direction: column;
  background: var(--surface); border-right: 1px solid var(--line);
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: .6rem; padding: 1.1rem 1rem; font-weight: 700; font-size: 1.05rem; }
.brand-mark {
  display: inline-grid; place-items: center; width: 32px; height: 32px;
  background: var(--accent); color: var(--accent-ink); border-radius: 8px; font-size: .8rem; font-weight: 800;
}
.sidebar nav { display: flex; flex-direction: column; gap: 2px; padding: .5rem; flex: 1; }
.sidebar nav a {
  display: flex; align-items: center; gap: .65rem; padding: .55rem .75rem;
  border-radius: 8px; color: var(--muted); font-weight: 500;
}
.sidebar nav a svg { width: 18px; height: 18px; }
.sidebar nav a:hover { background: var(--raised); color: var(--ink); text-decoration: none; }
.sidebar nav a.active { background: var(--accent-soft); color: var(--accent); }
[data-theme="dark"] .sidebar nav a.active { color: #bfdbfe; }
.sidebar-foot { padding: 1rem; border-top: 1px solid var(--line); font-size: .85rem; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: .7rem; padding: .7rem 1.25rem;
  background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.topbar-spacer { flex: 1; }
.user-chip { display: flex; align-items: center; gap: .5rem; font-size: .9rem; }
.avatar {
  display: inline-grid; place-items: center; width: 30px; height: 30px;
  border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: .8rem;
}
[data-theme="dark"] .avatar { color: #bfdbfe; }
.content { padding: 1.5rem; max-width: 1200px; width: 100%; margin: 0 auto; }
.content.bare { max-width: none; padding: 0; min-height: 100vh; display: grid; place-items: center; }

.menu-btn { display: none; }
.backdrop { display: none; }

@media (max-width: 860px) {
  .sidebar { position: fixed; left: -240px; transition: left .2s ease; z-index: 40; }
  .sidebar.open { left: 0; }
  .backdrop.show { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 30; }
  .menu-btn { display: inline-grid; }
  .user-name { display: none; }
  .content { padding: 1rem; }
}

/* ---- Components ---- */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 12px; padding: 1.1rem 1.25rem; box-shadow: var(--shadow);
}
.grid { display: grid; gap: 1rem; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 1000px) { .grid-4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 640px) { .grid-4, .grid-2 { grid-template-columns: 1fr; } }

.stat-label { color: var(--muted); font-size: .82rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.stat-value { font-size: 1.9rem; font-weight: 800; letter-spacing: -.02em; }

.btn {
  display: inline-flex; align-items: center; gap: .4rem; padding: .5rem .9rem;
  border-radius: 8px; border: 1px solid transparent; font: inherit; font-weight: 600; font-size: .9rem;
  cursor: pointer; white-space: nowrap;
}
.btn:hover { text-decoration: none; filter: brightness(1.05); }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn-ghost:hover { background: var(--raised); }
.btn-danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-sm { padding: .3rem .6rem; font-size: .82rem; }
.icon-btn {
  display: inline-grid; place-items: center; width: 34px; height: 34px; font-size: 1rem;
  border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer;
}
.icon-btn:hover { background: var(--raised); text-decoration: none; }

.field {
  width: 100%; padding: .55rem .7rem; border-radius: 8px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); font: inherit;
}
.field:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }
textarea.field { resize: vertical; min-height: 80px; }
.lbl { display: block; font-size: .82rem; font-weight: 600; color: var(--muted); margin: 0 0 .3rem; }
.form-row { margin-bottom: .9rem; }

table.data { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.data th {
  text-align: left; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); padding: .55rem .75rem; border-bottom: 1px solid var(--line);
}
table.data td { padding: .65rem .75rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.data tr:last-child td { border-bottom: none; }
table.data tr:hover td { background: var(--raised); }
.table-wrap { overflow-x: auto; }

.badge {
  display: inline-block; padding: .18rem .6rem; border-radius: 99px;
  font-size: .76rem; font-weight: 700; white-space: nowrap;
}
.st-received { background: var(--accent-soft); color: var(--accent); }
[data-theme="dark"] .st-received { color: #bfdbfe; }
.st-diagnosing { background: var(--warn-soft); color: var(--warn); }
.st-waiting-for-parts { background: #f3e8ff; color: #9333ea; }
[data-theme="dark"] .st-waiting-for-parts { background: #3b0764; color: #d8b4fe; }
.st-repairing { background: #ffedd5; color: #ea580c; }
[data-theme="dark"] .st-repairing { background: #431407; color: #fdba74; }
.st-ready-for-pickup { background: #cffafe; color: #0891b2; }
[data-theme="dark"] .st-ready-for-pickup { background: #164e63; color: #a5f3fc; }
.st-completed { background: var(--ok-soft); color: var(--ok); }

/* Pipeline stepper */
.pipeline { display: flex; gap: 0; overflow-x: auto; padding: .25rem 0; }
.pipe-step { display: flex; align-items: center; flex: 1; min-width: 110px; }
.pipe-btn {
  display: flex; flex-direction: column; align-items: center; gap: .35rem; width: 100%;
  background: none; border: none; cursor: pointer; font: inherit; color: var(--muted); padding: .35rem .25rem; border-radius: 8px;
}
.pipe-btn:hover { background: var(--raised); }
.pipe-dot {
  width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
  border: 2px solid var(--line); background: var(--surface); font-size: .72rem; font-weight: 800; color: var(--muted);
}
.pipe-step.done .pipe-dot { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.pipe-step.current .pipe-dot { border-color: var(--accent); color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.pipe-step.current .pipe-label { color: var(--ink); font-weight: 700; }
.pipe-label { font-size: .72rem; text-align: center; line-height: 1.2; }
.pipe-bar { height: 2px; flex: 1; background: var(--line); min-width: 8px; }
.pipe-step.done + .pipe-step .pipe-bar-lead,
.pipe-bar.filled { background: var(--accent); }

/* Timeline */
.timeline { list-style: none; margin: 0; padding: 0 0 0 1.35rem; position: relative; }
.timeline::before { content: ""; position: absolute; left: 6px; top: 6px; bottom: 6px; width: 2px; background: var(--line); }
.timeline li { position: relative; padding: 0 0 1.1rem .4rem; }
.timeline li::before {
  content: ""; position: absolute; left: -1.35rem; top: .35rem; width: 12px; height: 12px;
  border-radius: 50%; background: var(--accent); border: 2px solid var(--surface);
}
.timeline li.internal::before { background: var(--warn); }
.tl-meta { font-size: .78rem; color: var(--muted); }
.tl-internal-tag {
  font-size: .68rem; font-weight: 800; text-transform: uppercase; letter-spacing: .05em;
  color: var(--warn); background: var(--warn-soft); border-radius: 5px; padding: .05rem .4rem; margin-left: .4rem;
}

/* Toasts */
.toasts { position: fixed; right: 1rem; bottom: 1rem; display: flex; flex-direction: column; gap: .5rem; z-index: 100; }
.toast {
  background: var(--ink); color: var(--bg); padding: .65rem 1rem; border-radius: 10px;
  box-shadow: var(--shadow); font-size: .9rem; font-weight: 600; max-width: 340px;
  animation: toast-in .25s ease;
}
.toast.error { background: var(--danger); color: #fff; }
.toast.success { background: var(--ok); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* Misc */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.1rem; flex-wrap: wrap; }
.chips { display: flex; gap: .4rem; flex-wrap: wrap; }
.chip {
  padding: .3rem .75rem; border-radius: 99px; border: 1px solid var(--line);
  font-size: .82rem; font-weight: 600; color: var(--muted); background: var(--surface);
}
.chip:hover { text-decoration: none; background: var(--raised); }
.chip.active { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.muted { color: var(--muted); }
.small { font-size: .84rem; }
.mt { margin-top: 1rem; }
.mb { margin-bottom: 1rem; }
.flex { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.right { margin-left: auto; }
.empty { text-align: center; color: var(--muted); padding: 2.2rem 1rem; }
.attach-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: .75rem; }
.attach {
  border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--raised);
  display: flex; flex-direction: column;
}
.attach img { width: 100%; height: 96px; object-fit: cover; display: block; }
.attach .doc { height: 96px; display: grid; place-items: center; font-size: 1.6rem; }
.attach-meta { padding: .45rem .55rem; font-size: .75rem; }
.login-card { width: min(400px, 92vw); }
.login-brand { display: flex; align-items: center; gap: .7rem; justify-content: center; margin-bottom: 1.2rem; font-weight: 800; font-size: 1.2rem; }

/* Print / invoice */
@media print {
  body { background: #fff; color: #000; }
  .no-print { display: none !important; }
  .print-sheet { box-shadow: none !important; border: none !important; }
  .content { padding: 0; max-width: none; }
}
.invoice-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; border-bottom: 2px solid var(--ink); padding-bottom: 1rem; margin-bottom: 1.25rem; }
.invoice-total td { font-weight: 800; font-size: 1.05rem; border-top: 2px solid var(--ink) !important; }
