/* SiFi Ops — single stylesheet. System fonts, responsive, dark-mode aware. */

:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --panel-2: #f0f2f5;
  --text: #1b1f24;
  --muted: #667085;
  --border: #dfe3e8;
  --brand: #1f6feb;
  --brand-ink: #ffffff;
  --ok: #1a7f37;
  --warn: #9a6700;
  --amber-bg: #fff4d6;
  --red: #cf222e;
  --red-bg: #ffe9e9;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.1);
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117; --panel: #161b22; --panel-2: #1c232c; --text: #e6edf3;
    --muted: #9aa5b1; --border: #30363d; --brand: #4493f8; --brand-ink: #0d1117;
    --ok: #3fb950; --warn: #d29922; --amber-bg: #3a2f10; --red: #f85149; --red-bg: #3a1414;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg); color: var(--text);
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.4rem; margin: .2rem 0 1rem; }
h2 { font-size: 1.1rem; margin: 1.2rem 0 .6rem; }

/* ── Topbar / nav ── */
.topbar {
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  padding: .6rem 1rem; background: var(--panel); border-bottom: 1px solid var(--border);
}
.brand { display: inline-flex; align-items: center; gap: .5rem; font-weight: 700; font-size: 1.05rem; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-icon { height: 26px; width: auto; display: block; }
.brand-word { letter-spacing: .01em; }

/* No-JS theme swap: show the variant matching the OS colour scheme. */
.only-dark { display: none; }
@media (prefers-color-scheme: dark) {
  .only-light { display: none; }
  .only-dark { display: block; }
}

/* Login logo — explicit, specificity beats the generic .only-* swap */
.login-logo img { width: 100%; max-width: 260px; height: auto; margin: 0 auto .25rem; }
.login-logo img.only-light { display: block; }
.login-logo img.only-dark  { display: none; }
@media (prefers-color-scheme: dark) {
  .login-logo img.only-light { display: none; }
  .login-logo img.only-dark  { display: block; }
}
.login-sub { text-align: center; color: var(--muted); margin: 0 0 1rem; font-size: .9rem; }
.mainnav { display: flex; gap: .25rem; flex: 1; flex-wrap: wrap; }
.mainnav a { padding: .35rem .6rem; border-radius: 8px; color: var(--muted); }
.mainnav a:hover { background: var(--panel-2); text-decoration: none; }
.mainnav a.active { color: var(--text); background: var(--panel-2); font-weight: 600; }
.userbox { display: flex; align-items: center; gap: .6rem; }
.who { color: var(--muted); font-size: .85rem; }

/* Phones: single-row scrollable nav instead of stacking 3-4 wrapped rows. */
@media (max-width: 600px) {
  .topbar { padding: .45rem .6rem; gap: .5rem; }
  .brand-word { display: none; }       /* icon only — frees room for tabs */
  .mainnav { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .mainnav::-webkit-scrollbar { display: none; }
  .mainnav a { padding: .3rem .5rem; white-space: nowrap; }
  .who { display: none; }              /* name is redundant on a tiny screen; Log out stays top-right */
}

.container { max-width: 1100px; margin: 0 auto; padding: 1rem; }
.container-wide { max-width: none; }
.footer { max-width: 1100px; margin: 2rem auto 1rem; padding: 0 1rem; color: var(--muted); font-size: .82rem; }

/* ── Buttons ── */
.btn {
  display: inline-block; padding: .4rem .8rem; border-radius: 8px; border: 1px solid var(--border);
  background: var(--panel); color: var(--text); cursor: pointer; font-size: .9rem; line-height: 1.3;
}
.btn:hover { text-decoration: none; border-color: var(--muted); }
.btn-primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn-ghost { background: transparent; }
.btn-danger { color: var(--red); border-color: var(--red); }
.btn-sm { padding: .25rem .5rem; font-size: .8rem; }

/* ── Flash ── */
.flash { padding: .6rem .8rem; border-radius: 8px; margin: .5rem 0; border: 1px solid var(--border); }
.flash-error { background: var(--red-bg); border-color: var(--red); }
.flash-success { background: color-mix(in srgb, var(--ok) 15%, var(--panel)); }
.flash-info { background: var(--panel-2); }

/* ── Tables ── */
.table-wrap { overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; background: var(--panel); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
table.grid th, table.grid td { text-align: left; padding: .55rem .7rem; border-bottom: 1px solid var(--border); vertical-align: top; }
table.grid th { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); background: var(--panel-2); }
table.grid tr:last-child td { border-bottom: none; }
table.grid tr.row-overdue td { background: var(--red-bg); }
table.grid tr.row-amber td { background: var(--amber-bg); }

/* ── Badges ── */
.badge { display: inline-block; padding: .1rem .45rem; border-radius: 999px; font-size: .75rem; border: 1px solid var(--border); background: var(--panel-2); white-space: nowrap; }
.badge-prod { font-variant-numeric: tabular-nums; }
.badge-status { font-weight: 600; }
.badge-high { background: var(--red); color: #fff; border-color: var(--red); }
.badge-stale { background: var(--amber-bg); color: var(--warn); border-color: var(--warn); }
.badge-paid { background: color-mix(in srgb, var(--ok) 22%, var(--panel)); color: var(--ok); border-color: var(--ok); font-weight: 600; }
.badge-billing { background: color-mix(in srgb, var(--brand) 14%, var(--panel)); color: var(--brand); border-color: var(--brand); }
.badge-excluded { background: var(--panel-2); color: var(--muted); border-style: dashed; }
/* Service / consulting order — no devices, no shipping. */
.badge-service { background: var(--panel-2); color: var(--brand); border-color: var(--brand); }
.inline-lbl { display: inline-flex; align-items: center; gap: .35rem; margin: 0; font-size: .85rem; }
.inline-lbl select { width: auto; }
.pill-muted { color: var(--muted); }

/* ── Cards / panels ── */
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); margin-bottom: 1rem; }
.panel h2 { margin-top: 0; }
.cols { display: grid; grid-template-columns: 2fr 1fr; gap: 1rem; }
@media (max-width: 800px) { .cols { grid-template-columns: 1fr; } }

/* ── Forms ── */
label { display: block; margin: .5rem 0; font-size: .9rem; }
input, select, textarea {
  width: 100%; padding: .45rem .55rem; border: 1px solid var(--border); border-radius: 8px;
  background: var(--panel); color: var(--text); font: inherit;
}
textarea { min-height: 4rem; resize: vertical; }
.form-row { display: grid; grid-template-columns: repeat(2, 1fr); gap: .6rem; }
@media (max-width: 600px) { .form-row { grid-template-columns: 1fr; } }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .8rem; }

/* ── Rollup hero (dashboard) ── */
.rollup { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
@media (max-width: 600px) { .rollup { grid-template-columns: 1fr; } }
.rollup .stat { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; text-align: center; box-shadow: var(--shadow); }
.rollup .num { font-size: 2.4rem; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.rollup .lbl { color: var(--muted); margin-top: .3rem; }
.rollup .sub { font-size: .8rem; margin-top: .3rem; min-height: 1.1em; display: flex; gap: .5rem; justify-content: center; flex-wrap: wrap; }
.rollup .sub-urgent { color: var(--red); font-weight: 600; }
.rollup .sub-pipe { color: var(--muted); }

/* ── Timeline ── */
.timeline { list-style: none; margin: 0; padding: 0; border-left: 2px solid var(--border); }
.timeline li { position: relative; padding: .3rem 0 .8rem 1rem; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: .55rem; width: 10px; height: 10px; border-radius: 50%; background: var(--brand); }
.timeline .meta { color: var(--muted); font-size: .8rem; }
/* A comment left on a stage move — quoted so it reads as someone's words. */
.tl-comment { margin: .25rem 0 0; padding: .25rem .5rem; border-left: 3px solid var(--brand);
  background: var(--panel-2); border-radius: 0 4px 4px 0; font-size: .85rem; white-space: pre-wrap; }

/* ── Notes & comments feed ── */
.feed { list-style: none; margin: 0 0 .8rem; padding: 0; display: flex; flex-direction: column; gap: .5rem; }
.feed li { border: 1px solid var(--border); border-radius: var(--radius); padding: .4rem .6rem; background: var(--panel-2); }
.feed li.feed-comment { border-left: 3px solid var(--brand); }
.feed .feed-text { white-space: pre-wrap; font-size: .88rem; }
.feed .meta { color: var(--muted); font-size: .76rem; margin-top: .2rem; }
.feed-edit > summary { color: var(--muted); font-size: .74rem; cursor: pointer; margin-top: .25rem; list-style: none; }
.feed-edit > summary:hover { color: var(--fg); text-decoration: underline; }
.feed-edit textarea { font-size: .85rem; }

/* Shipping-leg badges on repair documents (an RMA ships both ways). */
.badge.leg-inbound  { background: #2a3d55; color: #cfe4ff; }
.badge.leg-outbound { background: #2f4a37; color: #d3f2dd; }

/* ── Tracking block ── the number you reach for, made obvious ── */
.track-block { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: .1rem .6rem;
  border: 1px solid var(--border); border-left: 3px solid var(--brand); border-radius: var(--radius);
  background: var(--panel-2); padding: .5rem .7rem; margin-bottom: .5rem; }
.track-block .track-cap { grid-column: 1 / -1; color: var(--muted); font-size: .72rem;
  text-transform: uppercase; letter-spacing: .04em; }
.track-block .track-num { font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 1.02rem; font-weight: 600; overflow-wrap: anywhere; }
.track-block .track-meta { grid-column: 1; color: var(--muted); font-size: .78rem; }
.track-block .track-go { grid-column: 2; grid-row: 2 / 4; white-space: nowrap; }

/* ── Board ── */
.board { display: flex; gap: .6rem; overflow-x: auto; padding-bottom: 1rem; align-items: flex-start; }
/* Columns share the full width and shrink to fit; scroll only when truly narrow. */
.board .col { flex: 1 1 0; min-width: 150px; background: var(--panel-2); border: 1px solid var(--border); border-radius: var(--radius); padding: .5rem; }
/* Phones: wider readable columns; horizontal scroll + the Move-to select do the work. */
@media (max-width: 600px) {
  .board .col { min-width: 220px; }
}
.board .col h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); margin: .2rem .2rem .5rem; display: flex; justify-content: space-between; }
.board .card { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: .55rem; margin-bottom: .5rem; box-shadow: var(--shadow); }
.board .card.dragging { opacity: .5; }
.board .col.dragover { outline: 2px dashed var(--brand); }
.card .cust { font-weight: 600; }
.card .row2 { display: flex; justify-content: space-between; align-items: center; margin-top: .35rem; gap: .3rem; flex-wrap: wrap; font-size: .82rem; }
.card form.move { margin-top: .4rem; }
.card form.move select { padding: .2rem .3rem; font-size: .8rem; }
.card .due-over { color: var(--red); font-weight: 600; }
.card .due-soon { color: var(--warn); font-weight: 600; }
/* Latest stage-move comment, so the board shows why something moved. */
.card .card-comment { margin-top: .35rem; padding-left: .4rem; border-left: 2px solid var(--brand);
  color: var(--muted); font-size: .78rem; overflow-wrap: anywhere; }

/* ── Filters bar ── */
.filters { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin-bottom: 1rem; }
.filters input[type="search"] { width: auto; flex: 1; min-width: 160px; }
.filters select { width: auto; }
.inline-check { display: inline-flex; align-items: center; gap: .3rem; margin: 0; white-space: nowrap; }
.inline-check input { width: auto; }

/* ── Needs-attention strip ── */
.attention { display: flex; gap: .5rem; flex-wrap: wrap; }
.attention .badge { font-size: .85rem; padding: .25rem .6rem; }
.att-tag { cursor: pointer; appearance: none; font: inherit; font-size: .85rem; }
.att-tag.att-active { outline: 2px solid currentColor; outline-offset: 1px; }
.att-list { margin-top: .6rem; }
.att-list ul { margin: .3rem 0 0; padding-left: 1.1rem; }
.att-hint { margin-top: .6rem; }

/* Pulse a row when its attention tag is clicked. */
@keyframes rowflash {
  0%, 100% { background: transparent; }
  25%, 60% { background: color-mix(in srgb, var(--brand) 28%, var(--panel)); }
}
tr.row-flash td { animation: rowflash 1.3s ease 2; }

/* ── Login ── */
.login-body { display: grid; place-items: center; min-height: 100vh; }
.login-card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.5rem; width: min(360px, 92vw); box-shadow: var(--shadow); }
.login-card h1 { text-align: center; }

/* ── Documents ── */
.doc-group { margin-bottom: .8rem; }
.doc-group h3 { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); margin: .2rem 0 .3rem; }
.doc-list { list-style: none; margin: 0; padding: 0; }
.doc-list li { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; padding: .3rem 0; border-bottom: 1px solid var(--border); }
.doc-list li:last-child { border-bottom: none; }
.doc-list .muted { font-size: .8rem; }
.inline-del { margin-left: auto; }
.inline-del .btn { padding: .05rem .4rem; line-height: 1.2; }
.dropzone { border: 1.5px dashed var(--border); border-radius: var(--radius); padding: .8rem; margin-top: .8rem; }
.dropzone.dragover { border-color: var(--brand); background: color-mix(in srgb, var(--brand) 8%, var(--panel)); }
.dz-hint { color: var(--muted); font-size: .82rem; margin-bottom: .5rem; }

/* ── Order modal (Trello-style overlay) ── */
.order-modal-overlay { position: fixed; inset: 0; z-index: 1000; background: rgba(0,0,0,.55);
  display: flex; align-items: flex-start; justify-content: center; padding: 2vh 1rem; }
.order-modal { position: relative; width: min(940px, 96vw); height: 96vh; background: var(--panel);
  border-radius: var(--radius); box-shadow: 0 10px 40px rgba(0,0,0,.45); overflow: hidden; }
.order-modal-frame { width: 100%; height: 100%; border: 0; background: var(--bg); display: block; }
.order-modal-close { position: absolute; top: .45rem; right: .55rem; z-index: 2; width: 32px; height: 32px;
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text); border-radius: 50%;
  font-size: 1.2rem; line-height: 1; cursor: pointer; }
.order-modal-close:hover { border-color: var(--muted); }
/* Bare page (inside the modal iframe) */
body.bare { background: var(--bg); }
body.bare .container { padding-top: 1.4rem; }

/* ── Stats page ── */
.kpi-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; margin-bottom: .4rem; }
@media (max-width: 800px) { .kpi-row { grid-template-columns: repeat(2, 1fr); } }
.kpi { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); }
.kpi-num { font-size: 1.9rem; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpi-lbl { color: var(--text); font-weight: 600; margin-top: .2rem; }
.kpi-sub { color: var(--muted); font-size: .78rem; margin-top: .1rem; }
.stats-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1rem; }
@media (max-width: 900px) { .stats-grid { grid-template-columns: 1fr; } }
.stat-card { margin-bottom: 0; }
.stat-head { display: flex; justify-content: space-between; align-items: baseline; gap: .5rem; }
.stat-head h2 { margin: 0; }
.stat-csv { font-size: .75rem; text-decoration: none; border: 1px solid var(--border); border-radius: 6px; padding: .05rem .4rem; }
.stat-note { font-size: .8rem; margin: .2rem 0 .6rem; }

/* SVG charts (theme-aware via CSS vars; palette for stacked segments) */
svg.chart { width: 100%; height: auto; display: block; margin: .3rem 0 .6rem; }
svg.chart .chart-bar { fill: var(--brand); }
svg.chart .chart-lbl { fill: var(--text); font-size: 13px; }
svg.chart .chart-val { fill: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
svg.chart .chart-axis { fill: var(--muted); font-size: 11px; }
svg.chart .chart-seg { fill: #fff; font-size: 11px; font-variant-numeric: tabular-nums; }
svg.chart .chart-note { fill: var(--muted); font-size: 11px; }
svg.chart .cat-0 { fill: #1f6feb; }
svg.chart .cat-1 { fill: #1f9e89; }
svg.chart .cat-2 { fill: #d9a521; }
svg.chart .cat-3 { fill: #8a94a6; }
svg.chart .chart-grid { stroke: var(--border); stroke-width: 1; opacity: .5; }
svg.chart .chart-gridlbl { fill: var(--muted); font-size: 10px; }
svg.chart .funnel-seg { fill: var(--brand); }
svg.chart .funnel-lbl { fill: #fff; font-size: 13px; font-weight: 600; }

/* Sortable table headers */
th.th-sort { cursor: pointer; user-select: none; }
th.th-sort:hover { color: var(--text); }
th.th-sort::after { content: " \2195"; opacity: .35; font-size: .8em; }
th.th-sort[data-sort="asc"]::after { content: " \2191"; opacity: 1; }
th.th-sort[data-sort="desc"]::after { content: " \2193"; opacity: 1; }

.addr { white-space: pre-wrap; margin: .2rem 0 .6rem; font: inherit; background: var(--panel-2); padding: .5rem .6rem; border-radius: 8px; font-size: .85rem; }
.addr-ship { border-left: 3px solid var(--brand); }

.muted { color: var(--muted); }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.stack > * + * { margin-top: .5rem; }
