:root {
  --bg: #15171c;
  --panel: #1d2027;
  --panel-2: #232732;
  --border: #2e333e;
  --text: #e8eaee;
  --muted: #97a0ac;
  --accent: #d2212b;
  --accent-dim: #d2212b33;
  --green: #43c974;
  --red: #e05d5d;
  --yellow: #f0c24b;
  --dept-body: #e0563f;
  --dept-paint: #9b6ef3;
  --dept-glass: #4aa8ff;
  --dept-electric: #f0c24b;
  --dept-mechanic: #43c974;
  --dept-custom: #ff5ca8;
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  display: flex;
}
a { color: inherit; text-decoration: none; }

/* nav */
#nav {
  width: 190px; flex-shrink: 0; padding: 18px 10px;
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 2px;
  position: sticky; top: 0; height: 100vh;
}
.mark { font-weight: 900; font-size: 19px; letter-spacing: 1px; padding: 6px 12px 18px; }
.mark span { color: var(--accent); font-weight: 700; font-size: 12px; letter-spacing: 3px; display: block; }
#nav a { padding: 9px 12px; border-radius: 8px; color: var(--muted); font-weight: 500; }
#nav a:hover { background: var(--panel); color: var(--text); }
#nav a.active { background: var(--panel-2); color: var(--text); box-shadow: inset 3px 0 0 var(--accent); }
.nav-spacer { flex: 1; }

/* layout */
#view { flex: 1; padding: 26px 30px 80px; min-width: 0; }
.page-head { display: flex; align-items: center; gap: 14px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 22px; font-weight: 800; letter-spacing: .3px; }
.page-head .grow { flex: 1; }

/* controls */
.btn {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
  padding: 8px 14px; border-radius: 8px; font: inherit; font-weight: 600; cursor: pointer;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.1); }
.btn.danger { color: var(--red); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn.wide { width: 100%; }
input, select, textarea {
  background: var(--bg); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; font: inherit; width: 100%;
}
input:focus, select:focus, textarea:focus, .btn:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent;
}
label { display: block; font-size: 13px; color: var(--muted); font-weight: 600; margin-bottom: 12px; }
label input, label select, label textarea { margin-top: 4px; }
.search { max-width: 300px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }

/* cards & tables */
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
table.list { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
table.list th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 1.2px; color: var(--muted); padding: 10px 14px; border-bottom: 1px solid var(--border); }
table.list td { padding: 11px 14px; border-bottom: 1px solid var(--border); }
table.list tr:last-child td { border-bottom: none; }
table.list tbody tr { cursor: pointer; }
table.list tbody tr:hover { background: var(--panel-2); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* chips */
.chip { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11px; font-weight: 700; letter-spacing: .5px; text-transform: uppercase; }
.chip.dept { border: 1px solid; background: transparent; }
.chip.body { color: var(--dept-body); border-color: var(--dept-body); }
.chip.paint { color: var(--dept-paint); border-color: var(--dept-paint); }
.chip.glass { color: var(--dept-glass); border-color: var(--dept-glass); }
.chip.electric { color: var(--dept-electric); border-color: var(--dept-electric); }
.chip.mechanic { color: var(--dept-mechanic); border-color: var(--dept-mechanic); }
.chip.custom { color: var(--dept-custom); border-color: var(--dept-custom); }
.chip.st { background: var(--panel-2); color: var(--muted); }
.chip.st.estimate { color: var(--yellow); }
.chip.st.approved { color: var(--dept-glass); }
.chip.st.in_progress { color: var(--accent); }
.chip.st.ready { color: var(--green); }
.chip.st.delivered { color: var(--muted); }
.chip.st.paid, .chip.st.available { color: var(--green); }
.chip.st.open, .chip.st.rented, .chip.st.active { color: var(--yellow); }
.chip.st.void, .chip.st.overdue, .chip.st.service { color: var(--red); }

/* dashboard */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 22px; }
.stat { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.stat .v { font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat .l { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }
.stat.warn .v { color: var(--red); }

/* board */
.board { display: grid; grid-template-columns: repeat(5, minmax(210px, 1fr)); gap: 12px; overflow-x: auto; align-items: start; }
.col { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; min-height: 120px; }
.col h2 { font-size: 12px; text-transform: uppercase; letter-spacing: 1.5px; color: var(--muted); margin: 4px 6px 10px; display: flex; justify-content: space-between; }
.col.dragover { border-color: var(--accent); background: var(--accent-dim); }
.card { background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; margin-bottom: 8px; cursor: grab; }
.card:hover { border-color: var(--muted); }
.card .n { font-weight: 700; font-size: 13px; }
.card .c { font-size: 13px; }
.card .v { font-size: 12px; color: var(--muted); }
.card .chips { margin-top: 6px; display: flex; gap: 4px; flex-wrap: wrap; }

/* modal */
#modal-root:not(:empty) { position: fixed; inset: 0; background: #000a; display: flex; align-items: flex-start; justify-content: center; padding: 5vh 16px; overflow: auto; z-index: 50; }
.modal { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 22px; width: 100%; max-width: 560px; }
.modal h2 { margin: 0 0 16px; font-size: 18px; }
.modal .actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; }
.form-err { color: var(--red); font-size: 13px; min-height: 18px; margin-bottom: 8px; }

/* detail pages */
.detail-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; align-items: start; }
.items-table td input { padding: 4px 8px; }
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }
.photo-grid a { position: relative; display: block; }
.photo-grid img { width: 100%; height: 90px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); }
.photo-grid button { position: absolute; top: 4px; right: 4px; }
.dept-picker { display: flex; gap: 6px; flex-wrap: wrap; margin: 4px 0 12px; }
.dept-picker .chip { cursor: pointer; opacity: .35; }
.dept-picker .chip.on { opacity: 1; }

/* toast */
#toast { position: fixed; bottom: 20px; right: 20px; z-index: 100; display: flex; flex-direction: column; gap: 8px; }
.toast-msg { background: var(--panel-2); border: 1px solid var(--border); border-left: 3px solid var(--accent); padding: 10px 16px; border-radius: 8px; box-shadow: 0 8px 24px #0008; animation: pop .15s ease-out; }
.toast-msg.err { border-left-color: var(--red); }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .toast-msg { animation: none; } }

/* login */
.login-body { align-items: center; justify-content: center; }
.login-card { background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 34px; width: 100%; max-width: 380px; }
.login-mark { font-weight: 900; font-size: 26px; }
.login-mark span { color: var(--accent); font-size: 13px; letter-spacing: 4px; display: block; }
.login-sub { color: var(--muted); margin: 4px 0 24px; }

/* mobile */
@media (max-width: 860px) {
  body { flex-direction: column; }
  #nav { width: 100%; height: auto; position: static; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 4px; padding: 10px; }
  .mark { padding: 0 10px; font-size: 15px; }
  .mark span { display: inline; font-size: 10px; }
  #nav a { padding: 7px 10px; font-size: 13px; }
  #view { padding: 16px 14px 60px; }
  .board { grid-template-columns: repeat(5, 240px); }
  .detail-grid, .row3, .row2 { grid-template-columns: 1fr; }
}

/* intake form overlay */
.intake-frame { width: 100%; max-width: 940px; height: 90vh; background: #fff; border-radius: 12px; display: flex; flex-direction: column; overflow: hidden; }
.intake-bar { display: flex; align-items: center; justify-content: space-between; padding: 8px 14px; background: var(--panel); border-bottom: 1px solid var(--border); }
.intake-frame iframe { flex: 1; border: none; background: #fff; }

/* brand logo */
.nav-logo { width: 100%; max-width: 160px; display: block; border-radius: 6px; margin: 2px 6px 16px; }
.login-logo { width: 100%; border-radius: 8px; margin-bottom: 6px; }
@media (max-width: 860px) { .nav-logo { max-width: 110px; margin: 0 6px; } }

/* ---- calendar ---- */
.cal-head { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-bottom: 6px; }
.cal-head div { font-size: 11px; text-transform: uppercase; letter-spacing: 1.2px; color: var(--muted); padding: 0 4px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-cell { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; min-height: 104px; padding: 6px; cursor: pointer; overflow: hidden; }
.cal-cell:hover { border-color: var(--accent); }
.cal-cell.empty { background: transparent; border-color: transparent; cursor: default; }
.cal-cell.empty:hover { border-color: transparent; }
.cal-cell.today { border-color: var(--accent); }
.cal-cell.today .cal-d { color: var(--accent); font-weight: 800; }
.cal-cell.sel { background: var(--panel-2); box-shadow: 0 0 0 2px var(--accent-dim) inset; }
.cal-d { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.cal-ev { font-size: 11px; line-height: 1.35; padding: 2px 5px; margin-bottom: 3px; background: var(--panel-2);
  border-left: 3px solid var(--muted); border-radius: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-more { font-size: 10px; color: var(--muted); padding-left: 5px; }
@media (max-width: 800px) {
  .cal-cell { min-height: 72px; padding: 4px; }
  .cal-ev { font-size: 10px; }
}
.nav-badge { display: inline-block; min-width: 17px; padding: 1px 5px; margin-left: 6px; font-size: 10px; font-weight: 800;
  line-height: 15px; text-align: center; color: #fff; background: var(--accent); border-radius: 9px; vertical-align: middle; }
