:root { color-scheme: light; }
[hidden] { display: none !important; }
img { max-width: 100%; }

/* Layout: barra fixa com abas; conteúdo em uma coluna de até 960px.
   A OS aberta tem o formato de uma folha de formulário, com blocos separados por linhas.
   Tabelas rolam dentro do próprio contêiner. */
:root {
  --bg: #eef1f4;
  --surface: #ffffff;
  --surface-2: #f4f6f8;
  --fg: #14202b;
  --muted: #566677;
  --line: #d3dae1;
  --primary: #1f4e8c;
  --primary-fg: #ffffff;
  --primary-soft: #e1ebf7;
  --danger: #b3261e;
  --st-aberta: #4a5a6a;      --st-aberta-bg: #e4e9ee;
  --st-andamento: #7d5200;   --st-andamento-bg: #fbeec9;
  --st-concluida: #0a6551;   --st-concluida-bg: #d7f0e8;
  --st-fechada: #ffffff;     --st-fechada-bg: #33465a;
  --font-text: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-display: "IBM Plex Sans Condensed", "IBM Plex Sans", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1720; --surface: #17212c; --surface-2: #1d2936; --fg: #e6ecf2; --muted: #93a3b3;
    --line: #2c3b4b; --primary: #7aaeea; --primary-fg: #0b1522; --primary-soft: #1d3250; --danger: #f0867f;
    --st-aberta: #b4c1ce;    --st-aberta-bg: #263545;
    --st-andamento: #f3c969; --st-andamento-bg: #3d3216;
    --st-concluida: #7fd9bf; --st-concluida-bg: #143a31;
    --st-fechada: #0f1720;   --st-fechada-bg: #b9c7d6;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1720; --surface: #17212c; --surface-2: #1d2936; --fg: #e6ecf2; --muted: #93a3b3;
  --line: #2c3b4b; --primary: #7aaeea; --primary-fg: #0b1522; --primary-soft: #1d3250; --danger: #f0867f;
  --st-aberta: #b4c1ce;    --st-aberta-bg: #263545;
  --st-andamento: #f3c969; --st-andamento-bg: #3d3216;
  --st-concluida: #7fd9bf; --st-concluida-bg: #143a31;
  --st-fechada: #0f1720;   --st-fechada-bg: #b9c7d6;
  color-scheme: dark;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--fg); font-family: var(--font-text); font-size: 15px; line-height: 1.5; }

h1, h2, h3 { font-family: var(--font-display); font-weight: 600; margin: 0; text-wrap: balance; letter-spacing: 0.01em; }
a { color: var(--primary); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

/* barra superior */
.bar { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20; background: var(--surface); border-bottom: 1px solid var(--line); }
.bar-in { max-width: 960px; margin: 0 auto; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.25rem 1rem;
  padding: 0.5rem max(16px, env(safe-area-inset-right, 0px)) 0 max(16px, env(safe-area-inset-left, 0px)); }
.brand { display: flex; align-items: center; gap: 0.6rem; font-family: var(--font-display); font-weight: 700; font-size: 1.15rem; padding-bottom: 0.4rem; }
.brand-mark { font-family: var(--font-mono); font-weight: 500; font-size: 0.8rem; background: var(--primary); color: var(--primary-fg); padding: 0.15rem 0.4rem; border-radius: 3px; letter-spacing: 0.04em; }
.tabs { display: flex; gap: 0.25rem; }
.tabs a { text-decoration: none; color: var(--muted); font-weight: 500; padding: 0.55rem 0.8rem; border-bottom: 3px solid transparent; }
.tabs a[aria-current="page"] { color: var(--fg); border-bottom-color: var(--primary); }
.tabs a[hidden] { display: none; }

.main { max-width: 960px; margin: 0 auto; padding: 1.25rem max(16px, env(safe-area-inset-right, 0px)) 4rem max(16px, env(safe-area-inset-left, 0px)); }
.stack { display: flex; flex-direction: column; gap: 1rem; }
.row { display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: center; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.page-title { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 0.5rem 1rem; }
.page-title h1 { font-size: 1.6rem; }

/* controles */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem; min-height: 2.5rem; padding: 0.45rem 0.95rem; border-radius: 6px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; text-decoration: none; color: var(--fg); font-weight: 500; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-fg); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.small { min-height: 2rem; padding: 0.2rem 0.65rem; font-size: 0.85rem; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }
input[type=text], input[type=search], input[type=number], input[type=date], input[type=datetime-local], select, textarea {
  width: 100%; padding: 0.55rem 0.65rem; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); font-size: 16px; min-height: 2.5rem; }
textarea { resize: vertical; min-height: 5.5rem; }
label.f { display: flex; flex-direction: column; gap: 0.25rem; min-width: 0; }
label.f > span, .lbl { font-size: 0.78rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 15rem), 1fr)); gap: 0.9rem 1rem; }

/* situação */
.pill { display: inline-block; font-size: 0.75rem; font-weight: 600; padding: 0.1rem 0.55rem; border-radius: 99px; white-space: nowrap; letter-spacing: 0.02em; }
.st-aberta { color: var(--st-aberta); background: var(--st-aberta-bg); }
.st-andamento { color: var(--st-andamento); background: var(--st-andamento-bg); }
.st-concluida { color: var(--st-concluida); background: var(--st-concluida-bg); }
.st-fechada { color: var(--st-fechada); background: var(--st-fechada-bg); }
.tag-ex { font-size: 0.7rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); border: 1px dashed var(--muted); padding: 0 0.4rem; border-radius: 3px; }

/* lista */
.chips { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 99px; padding: 0.25rem 0.8rem; cursor: pointer; font-size: 0.875rem; }
.chip[aria-pressed="true"] { background: var(--primary); border-color: var(--primary); color: var(--primary-fg); }
.list { display: flex; flex-direction: column; gap: 0.5rem; }
.os { display: grid; gap: 0.15rem 1rem; grid-template-columns: 1fr auto; text-decoration: none; color: inherit; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 0.75rem 0.9rem; }
.os:hover { border-color: var(--primary); }
.os-num { font-family: var(--font-mono); font-size: 0.8rem; color: var(--muted); }
.os-cli { font-weight: 600; font-size: 1.02rem; min-width: 0; overflow-wrap: anywhere; }
.os-sub { color: var(--muted); font-size: 0.875rem; min-width: 0; overflow-wrap: anywhere; }
.os-side { grid-row: 1 / span 3; grid-column: 2; display: flex; flex-direction: column; align-items: flex-end; gap: 0.3rem; }
.os-foot { display: flex; flex-wrap: wrap; gap: 0.2rem 0.9rem; font-size: 0.8rem; color: var(--muted); margin-top: 0.2rem; }
.empty { background: var(--surface); border: 1px dashed var(--line); border-radius: 8px; padding: 1.5rem 1rem; text-align: center; color: var(--muted); display: flex; flex-direction: column; gap: 0.75rem; align-items: center; }

/* folha da OS */
.sheet { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
.sheet-head { padding: 1rem 1.1rem; border-bottom: 2px solid var(--fg); display: flex; flex-direction: column; gap: 0.35rem; }
.sheet-head .top { display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem; }
.sheet-head .num { font-family: var(--font-mono); font-weight: 500; font-size: 0.95rem; }
.sheet-head h1 { font-size: 1.5rem; overflow-wrap: anywhere; }
.blk { padding: 0.9rem 1.1rem 1rem; border-bottom: 1px solid var(--line); }
.blk:last-child { border-bottom: 0; }
.blk > h2 { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.09em; color: var(--muted); font-family: var(--font-text); font-weight: 600; margin-bottom: 0.6rem; }
dl.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 13rem), 1fr)); gap: 0.7rem 1.2rem; margin: 0; }
dl.kv dt { font-size: 0.75rem; color: var(--muted); }
dl.kv dd { margin: 0; overflow-wrap: anywhere; }
.prose { white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; }
.scroll { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 0.9rem; }
th, td { text-align: left; padding: 0.45rem 0.6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 600; white-space: nowrap; }
td.n, th.n { text-align: right; font-family: var(--font-mono); font-variant-numeric: tabular-nums; white-space: nowrap; }
tfoot td { font-weight: 600; border-bottom: 0; }
.sig-img { background: #fff; border: 1px solid var(--line); border-radius: 6px; max-width: 100%; width: 22rem; display: block; }
.actions { display: flex; flex-wrap: wrap; gap: 0.5rem; padding: 0.9rem 1.1rem; background: var(--surface-2); border-radius: 0 0 8px 8px; align-items: center; }
.note { background: var(--primary-soft); border-radius: 6px; padding: 0.6rem 0.8rem; font-size: 0.9rem; }

/* formulário */
.form { display: flex; flex-direction: column; gap: 0; }
.mat-row { display: grid; grid-template-columns: 1fr 5.5rem 5rem 7rem 2.5rem; gap: 0.5rem; align-items: end; padding: 0.5rem 0; border-bottom: 1px dashed var(--line); }
.mat-row .m-del { align-self: end; padding: 0; min-width: 2.5rem; }
@media (max-width: 640px) {
  .mat-row { grid-template-columns: 1fr 1fr 1fr; }
  .mat-row .m-nome { grid-column: 1 / 3; grid-row: 1; }
  .mat-row .m-del { grid-column: 3; grid-row: 1; justify-self: end; }
}
canvas.sig { display: block; width: 100%; max-width: 34rem; aspect-ratio: 560 / 180; background: #fff; border: 1px solid var(--line); border-radius: 6px; touch-action: none; cursor: crosshair; }
.err { color: var(--danger); font-weight: 500; }

/* financeiro */
.sum { display: grid; grid-template-columns: repeat(auto-fit, minmax(9.5rem, 1fr)); gap: 0.6rem; }
.sum div { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 0.6rem 0.8rem; }
.sum b { display: block; font-family: var(--font-mono); font-weight: 500; font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.sum span { font-size: 0.75rem; color: var(--muted); }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 0.9rem 1rem; }
.panel > h2 { font-size: 1.1rem; margin-bottom: 0.6rem; }

#toast { position: fixed; left: 0; right: 0; bottom: 0; display: flex; justify-content: center; padding: 0 max(16px, env(safe-area-inset-right, 0px)) calc(1rem + env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px)); pointer-events: none; z-index: 40; }
#toast span { background: var(--fg); color: var(--bg); padding: 0.55rem 0.9rem; border-radius: 6px; font-size: 0.9rem; max-width: 30rem; }
#toast:empty { display: none; }
@media (prefers-reduced-motion: no-preference) { .os { transition: border-color 0.12s; } }

.login { max-width: 24rem; margin: 2rem auto 0; }
#who { display: flex; align-items: center; gap: 0.6rem; padding-bottom: 0.4rem; }
.usr select { width: auto; min-width: 10rem; }
@media (max-width: 640px) {
  .usr thead { display: none; }
  .usr, .usr tbody, .usr tr, .usr td { display: block; }
  .usr tr { padding: 0.7rem 0; border-bottom: 1px solid var(--line); }
  .usr td { border: 0; padding: 0.2rem 0; }
}
#who:empty { display: none; }
.bar-in { padding-top: max(0.5rem, env(safe-area-inset-top, 0px)); }

/* fotos e vídeos */
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
label.btn:focus-within { outline: 2px solid var(--primary); outline-offset: 2px; }
.gal { display: grid; grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr)); gap: 0.6rem; margin-top: 0.6rem; }
.tile { border: 1px solid var(--line); border-radius: 6px; overflow: hidden; background: var(--surface-2); display: flex; flex-direction: column; min-width: 0; }
.tile.video { grid-column: span 2; }
.tile img, .tile video { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; display: block; background: #000; }
.tile.video video { object-fit: contain; }
.thumb { padding: 0; border: 0; background: none; cursor: zoom-in; display: block; width: 100%; }
.tile-info { padding: 0.4rem 0.55rem 0.55rem; font-size: 0.75rem; color: var(--muted); display: flex; flex-direction: column; gap: 0.25rem; min-width: 0; overflow-wrap: anywhere; }
.up-item { display: grid; grid-template-columns: 1fr auto; gap: 0.25rem 0.6rem; align-items: center; padding: 0.45rem 0; border-bottom: 1px dashed var(--line); font-size: 0.875rem; }
.up-item > span:first-child { min-width: 0; overflow-wrap: anywhere; }
.bar-prog { grid-column: 1 / -1; height: 0.4rem; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.bar-prog i { display: block; height: 100%; background: var(--primary); width: 0; }
#up-list { margin-top: 0.6rem; }
#lb { position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, 0.9); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.9rem;
  padding: max(16px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) max(16px, env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px)); }
#lb img { max-width: 100%; max-height: calc(100% - 4rem); object-fit: contain; }

/* ---------- obras ---------- */
:root { --st-par-bg: #fde4e1; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --st-par-bg: #4a1f1c; } }
:root[data-theme="dark"] { --st-par-bg: #4a1f1c; }
.st-paralisada { color: var(--danger); background: var(--st-par-bg); }
.tabs { overflow-x: auto; max-width: 100%; }
.tabs a { white-space: nowrap; }
.up-list { margin-top: 0.6rem; }
.os.ob .ob-prog { grid-column: 1 / -1; display: flex; align-items: center; gap: 0.7rem; margin-top: 0.35rem; }
.os.ob .ob-prog .prog { flex: 1; }
.prog { height: 0.55rem; background: var(--surface-2); border: 1px solid var(--line); border-radius: 99px; overflow: hidden; min-width: 4rem; }
.prog i { display: block; height: 100%; background: var(--primary); }
.prog.late i { background: var(--danger); }
.ob-big { display: flex; align-items: center; gap: 0.9rem; }
.ob-big b { font-size: 1.9rem; font-weight: 500; min-width: 4.5rem; }
.ob-big .prog { flex: 1; height: 0.8rem; }
.et-bar { display: inline-flex; align-items: center; gap: 0.5rem; justify-content: flex-end; }
.et-bar .prog { width: 6rem; }
.et-row { display: grid; grid-template-columns: 1fr 9rem 9rem 6rem 2.5rem; gap: 0.5rem; align-items: end; padding: 0.5rem 0; border-bottom: 1px dashed var(--line); }
.ef-row { display: grid; grid-template-columns: 1fr 6rem 2.5rem; gap: 0.5rem; align-items: end; padding: 0.4rem 0; border-bottom: 1px dashed var(--line); }
.et-row .m-del, .ef-row .m-del { padding: 0; min-width: 2.5rem; }
.et-prog { display: grid; grid-template-columns: 1fr 5.5rem auto; gap: 0.6rem; align-items: center; padding: 0.35rem 0; border-bottom: 1px dashed var(--line); }
@media (max-width: 640px) {
  .et-row { grid-template-columns: 1fr 1fr 1fr; }
  .et-row .et-nome { grid-column: 1 / 3; }
  .et-row .m-del { grid-column: 3; grid-row: 1; justify-self: end; }
}
.rdo-item { display: grid; gap: 0.2rem; text-decoration: none; color: inherit; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 0.6rem 0.8rem; }
.rdo-item:hover { border-color: var(--primary); }
.rdo-data { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.2rem 0.7rem; }
.rdo-sum { overflow-wrap: anywhere; font-size: 0.92rem; }

/* impressão: relatório limpo, em preto sobre branco, sem botões nem vídeos */
@media print {
  :root:root:root { --bg: #fff; --surface: #fff; --surface-2: #fff; --fg: #000; --muted: #333; --line: #999; --primary: #000; --danger: #900; color-scheme: light; }
  body { font-size: 11pt; }
  .bar, #toast, .actions, .no-print, .chips, video { display: none !important; }
  .main { padding: 0; max-width: none; }
  .sheet { border: 0; }
  .blk { break-inside: avoid; }
  .gal { grid-template-columns: repeat(3, 1fr); }
  .tile, .tile.video { grid-column: auto; break-inside: avoid; }
  a { color: inherit; text-decoration: none; }
  .prog { border-color: #666; } .prog i { background: #333; }
}
@media (max-width: 640px) {
  .tabs a { padding: 0.55rem 0.55rem; font-size: 0.92rem; }
  .et-bar .prog { width: 3rem; min-width: 3rem; }
}
