[hidden] { display: none !important; }
:root {
  --bg: #f3f4f6; --surface: #fff; --ink: #1f2933; --muted: #62707d; --line: #d9dee3;
  --brand: #1f2933; --accent: #c65d3b; --accent-ink: #fff;
  --ok: #1c7c3c; --warn: #b7791f; --bad: #c62828; --info: #1d5fa8;
  --radius: 14px; --tap: 48px;
  --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px); --safe-r: env(safe-area-inset-right, 0px);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 17px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
body.modal-open { overflow: hidden; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .4em; }
h1 { font-size: 1.8rem; } h2 { font-size: 1.35rem; } h3 { font-size: 1.1rem; }
a { color: var(--info); }
p { margin: .3em 0 .6em; }
pre { white-space: pre-wrap; word-break: break-word; }
.muted { color: var(--muted); } .hint { color: var(--muted); font-size: .9rem; margin-top: .3rem; }
.notes { white-space: pre-wrap; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); opacity: 0; }
.push-left { margin-right: auto; }

/* top bar */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  background: var(--brand); color: #fff; padding: calc(.5rem + var(--safe-t)) calc(1rem + var(--safe-r)) .5rem calc(1rem + var(--safe-l));
}
.brand { color: #fff; font-weight: 700; font-size: 1.15rem; text-decoration: none; }
.topbar nav { display: flex; gap: .25rem; margin-left: auto; }
.topbar nav a { color: #d5dbe1; text-decoration: none; padding: .7rem 1rem; border-radius: 10px; min-height: var(--tap); display: flex; align-items: center; }
.topbar nav a.active { background: rgba(255,255,255,.16); color: #fff; font-weight: 600; }
.pill { font-size: .8rem; padding: .2rem .6rem; border-radius: 99px; background: var(--warn); color: #fff; }

main { max-width: 1180px; margin: 0 auto; padding: 1rem calc(1rem + var(--safe-r)) calc(3rem + var(--safe-b)) calc(1rem + var(--safe-l)); outline: none; }
.page.narrow { max-width: 760px; margin: 0 auto; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin: .5rem 0 1rem; }
.page-head h1, .page-head h2 { margin: 0; }
.loading { text-align: center; color: var(--muted); padding: 3rem; }

/* buttons & inputs */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem; min-height: var(--tap); padding: .6rem 1.1rem;
  border: 1.5px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--ink);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; touch-action: manipulation;
}
.btn:hover { border-color: #aab3bc; } .btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { background: #fff; color: var(--bad); border-color: #e3b4b4; }
.btn.small { min-height: 42px; padding: .35rem .9rem; font-size: .95rem; }
.btn.icon { min-width: var(--tap); padding: 0; font-size: 1.1rem; }
.btn[disabled] { opacity: .5; }
.btn-row { display: flex; gap: .6rem; align-items: center; }
.btn-row.wrap { flex-wrap: wrap; } .btn-row.end { justify-content: flex-end; margin-top: .6rem; flex-wrap: wrap; }
.btn-col { display: grid; gap: .6rem; margin: 1rem 0; }
input, select, textarea {
  width: 100%; min-height: var(--tap); padding: .6rem .8rem; font: inherit; font-size: 1rem; color: var(--ink);
  background: #fff; border: 1.5px solid var(--line); border-radius: 12px;
}
input[type=date] { min-width: 10.5rem; }
input[type=range] { padding: 0; accent-color: var(--accent); }
input[type=radio], input[type=checkbox] { width: auto; min-height: 0; margin-right: .4rem; transform: scale(1.3); }
input:focus, select:focus, textarea:focus, .btn:focus-visible, a:focus-visible { outline: 3px solid rgba(198,93,59,.45); outline-offset: 1px; }
.toolbar input[type=search] { max-width: 360px; }
.toolbar { display: flex; gap: 1rem; flex-wrap: wrap; align-items: center; margin-bottom: 1rem; }
.chips, .segmented { display: flex; gap: .4rem; flex-wrap: wrap; }
.chip, .seg { min-height: 44px; padding: .4rem 1rem; border: 1.5px solid var(--line); border-radius: 99px; background: #fff; font: inherit; cursor: pointer; }
.segmented { gap: 0; } .seg { border-radius: 0; margin-left: -1.5px; } .seg:first-child { border-radius: 12px 0 0 12px; margin: 0; } .seg:last-child { border-radius: 0 12px 12px 0; }
.chip.active, .seg.active { background: var(--brand); color: #fff; border-color: var(--brand); }

/* cards & layout */
.grid.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 1rem; }
.stack { display: grid; gap: 1rem; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; box-shadow: 0 1px 2px rgba(0,0,0,.04); }
a.card { color: inherit; text-decoration: none; display: block; } a.card:hover { border-color: #aab3bc; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: .8rem; flex-wrap: wrap; }
.card-head h3, .card-head h1 { margin: 0; }
.card-foot { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; margin-top: .6rem; color: var(--muted); font-size: .95rem; }
.badges { display: flex; gap: .4rem; flex-wrap: wrap; }
.empty { text-align: center; padding: 2.5rem 1rem; color: var(--muted); background: var(--surface); border: 2px dashed var(--line); border-radius: var(--radius); }
dl.meta { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; margin: .5rem 0; }
dl.meta.inline { display: flex; gap: 2rem; flex-wrap: wrap; }
dl.meta dt { font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); } dl.meta dd { margin: 0; font-weight: 600; }
.inline-link { text-decoration: none; display: inline-flex; align-items: center; justify-content: center; min-width: var(--tap); min-height: var(--tap); margin: -.6rem -.2rem; vertical-align: middle; }
.project-head { margin-bottom: .5rem; } .back { display: inline-block; padding: .4rem 0; text-decoration: none; }

.tabs { display: flex; gap: .4rem; overflow-x: auto; border-bottom: 2px solid var(--line); margin-bottom: 1rem; -webkit-overflow-scrolling: touch; }
.tab { white-space: nowrap; padding: .8rem 1.1rem; min-height: var(--tap); text-decoration: none; color: var(--muted); font-weight: 600; border-bottom: 4px solid transparent; margin-bottom: -2px; }
.tab.active { color: var(--ink); border-bottom-color: var(--accent); }

/* badges */
.badge { display: inline-block; padding: .15rem .6rem; border-radius: 99px; font-size: .8rem; font-weight: 700; background: #e7ebef; color: #3b4753; white-space: nowrap; }
.badge.st-in-progress, .badge.st-sent { background: #dbeafe; color: #1d4e89; }
.badge.st-done, .badge.st-approved, .badge.st-complete, .badge.st-active { background: #d8f0df; color: var(--ok); }
.badge.st-blocked, .badge.st-rejected, .badge.sev-high, .badge.overdue { background: #fde0e0; color: var(--bad); }
.badge.sev-critical { background: var(--bad); color: #fff; }
.badge.sev-medium, .badge.warn, .badge.st-on-hold { background: #fdecc8; color: #8a5a00; }
.badge.sev-low { background: #e7ebef; }
.badge.overdue { background: var(--bad); color: #fff; margin-left: .4rem; }
.sev-border-critical { border-left: 6px solid var(--bad); } .sev-border-high { border-left: 6px solid #e57373; }
.sev-border-medium { border-left: 6px solid #f0b429; } .sev-border-low { border-left: 6px solid #b6c0c9; }
.is-overdue { border-left: 6px solid var(--bad); background: #fff8f8; }

.progress { height: 10px; background: #e5e9ed; border-radius: 99px; overflow: hidden; margin: .6rem 0 0; }
.progress > div { height: 100%; background: var(--accent); }
.progress.big { height: 22px; position: relative; min-width: 260px; }
.progress.big span { position: absolute; inset: 0; display: grid; place-items: center; font-size: .8rem; font-weight: 700; color: #111; }

/* photos */
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .6rem; margin: .6rem 0; }
.photo { margin: 0; } .photo-btn { display: block; width: 100%; padding: 0; border: 0; background: none; cursor: zoom-in; }
.photo img { width: 100%; aspect-ratio: 4/3; object-fit: cover; border-radius: 10px; background: #e5e9ed; display: block; }
.photo figcaption { font-size: .85rem; color: var(--muted); margin-top: .2rem; }
.photo-edit-list { display: grid; gap: .6rem; margin-top: .6rem; }
.photo-edit { display: grid; grid-template-columns: 84px 1fr auto; gap: .6rem; align-items: center; }
.photo-edit img { width: 84px; height: 64px; object-fit: cover; border-radius: 8px; background: #e5e9ed; }
.lightbox-img { max-width: 100%; max-height: 75vh; display: block; margin: 0 auto; border-radius: 8px; }
.modal.lightbox { max-width: 1000px; }

/* modal & forms */
.modal-backdrop { position: fixed; inset: 0; z-index: 50; background: rgba(15,23,32,.55); display: grid; place-items: center; padding: 1rem; overflow-y: auto; }
.modal { background: #fff; border-radius: 18px; width: min(680px, 100%); max-height: calc(100vh - 2rem); display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.modal.small { width: min(480px, 100%); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: .8rem 1rem .8rem 1.3rem; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; }
.modal-body { padding: 1rem 1.3rem 1.2rem; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.form { display: flex; flex-wrap: wrap; gap: 1rem; }
.field { flex: 1 1 100%; } .field.half { flex: 1 1 calc(50% - .5rem); min-width: 180px; }
.field label { display: block; font-weight: 600; margin-bottom: .3rem; } .req { color: var(--bad); }
.form-error { flex: 1 1 100%; color: var(--bad); font-weight: 600; } .form-error:empty { display: none; }
.sticky-actions { flex: 1 1 100%; position: sticky; bottom: -1.2rem; background: #fff; padding: .8rem 0 .2rem; margin: 0; border-top: 1px solid var(--line); }
.percent-row { display: grid; grid-template-columns: 1fr 90px auto; gap: .6rem; align-items: center; }
.photo-field .btn-row { flex-wrap: wrap; }
.preview { background: var(--bg); border-radius: 10px; padding: .8rem; font-size: .92rem; max-height: 220px; overflow: auto; }
.radio-row { display: grid; gap: .6rem; margin-bottom: .8rem; } .radio-row label { display: flex; align-items: center; min-height: 40px; }
.danger-zone { border-color: #e3b4b4; }

/* toasts */
#toasts { position: fixed; bottom: calc(1rem + var(--safe-b)); left: 50%; transform: translateX(-50%); z-index: 100; display: grid; gap: .5rem; }
.toast { background: var(--brand); color: #fff; padding: .8rem 1.2rem; border-radius: 12px; box-shadow: 0 6px 20px rgba(0,0,0,.3); }
.toast.warn { background: var(--warn); }

/* summary stats */
.summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .8rem; margin: 0 0 1rem; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: .8rem 1rem; }
.stat b { display: block; font-size: 1.4rem; } .stat span { color: var(--muted); font-size: .9rem; }
.stat.bad b { color: var(--bad); } .stat.warn b { color: var(--warn); }
.co-figures { display: flex; gap: 1.5rem; flex-wrap: wrap; align-items: baseline; }

/* overview */
a.stat.link { color: inherit; text-decoration: none; display: block; }
a.stat.link:hover { border-color: #aab3bc; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-bottom: 1rem; align-items: start; }
.rows { display: grid; }
.row-link { display: flex; justify-content: space-between; align-items: center; gap: .8rem; min-height: var(--tap); padding: .55rem 0; color: inherit; text-decoration: none; border-top: 1px solid var(--line); }
.rows .row-link:first-child { border-top: 0; }
.row-main { display: grid; min-width: 0; } .row-main small { color: var(--muted); }
.btn-row.center { justify-content: center; flex-wrap: wrap; }

.section-label { margin: .6rem 0 -.4rem; color: var(--muted); font-size: .85rem; text-transform: uppercase; letter-spacing: .05em; }
.task.compact { display: flex; align-items: center; gap: .8rem; padding: .5rem .5rem .5rem 1.1rem; }
.compact-main { flex: 1; min-width: 0; display: grid; } .compact-main small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* gantt */
.gantt { overflow-x: auto; padding: 0; -webkit-overflow-scrolling: touch; position: relative; }
.g-row { display: flex; border-bottom: 1px solid var(--line); min-width: max-content; }
.g-label { position: sticky; left: 0; z-index: 2; width: 240px; flex: none; background: #fff; border: 0; border-right: 1px solid var(--line); padding: .5rem .8rem; text-align: left; font: inherit; color: inherit; display: flex; flex-direction: column; justify-content: center; min-height: 56px; cursor: pointer; }
.g-label small { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.g-label strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.g-head .g-label { cursor: default; font-weight: 700; min-height: 36px; }
.g-track { position: relative; flex: none; background-image: repeating-linear-gradient(90deg, transparent 0 167px, #eef1f4 167px 168px); }
.g-head .g-track { height: 36px; }
.tick { position: absolute; top: 8px; font-size: .75rem; color: var(--muted); padding-left: 4px; border-left: 1px solid var(--line); height: 20px; }
.today-line { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--accent); z-index: 1; opacity: .7; }
.bar { position: absolute; top: 12px; height: 32px; border-radius: 8px; background: #b6c0c9; color: #111; font-size: .78rem; font-weight: 600; padding: 0 .5rem; display: flex; align-items: center; overflow: hidden; white-space: nowrap; }
.bar.st-in-progress { background: #7db3ee; } .bar.st-done { background: #8fd3a4; } .bar.st-blocked { background: #f2b46d; }
.bar.overdue { background: var(--bad); color: #fff; }
.legend { padding: .8rem 1rem; display: flex; gap: .4rem; flex-wrap: wrap; position: sticky; left: 0; }

/* documents (print views) */
.doc { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 2rem; max-width: 900px; margin: 1rem auto; }
.doc-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; border-bottom: 3px solid var(--accent); padding-bottom: .6rem; margin-bottom: 1rem; }
.doc-head h1 { margin: 0; } .right { text-align: right; }
.doc h2 { margin-top: 1.6rem; border-bottom: 1px solid var(--line); padding-bottom: .2rem; }
table { border-collapse: collapse; width: 100%; }
table.kv th { text-align: left; width: 130px; color: var(--muted); padding: .2rem .6rem .2rem 0; }
table.data { margin: .4rem 0 1rem; } table.data th, table.data td { text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
table.data th { background: var(--bg); font-size: .85rem; } .num { text-align: right !important; white-space: nowrap; }
tfoot td { font-weight: 700; } .row-overdue td { background: #fff1f1; }
.sigs { display: grid; grid-template-columns: 1fr 1fr; gap: 3rem; margin-top: 4rem; }
.sig-line { border-bottom: 1.5px solid #000; height: 2.5rem; margin-bottom: .3rem; }
.small-print { font-size: .8rem; margin-top: 3rem; }
.report-log, .report-issue { break-inside: avoid; margin-bottom: 1rem; }

@media (max-width: 760px) { .two-col { grid-template-columns: 1fr; } }
@media (max-width: 640px) {
  h1 { font-size: 1.5rem; } .topbar nav { margin-left: 0; width: 100%; } .topbar nav a { flex: 1; justify-content: center; }
  dl.meta { grid-template-columns: 1fr; } .doc { padding: 1rem; } .photo-edit { grid-template-columns: 64px 1fr; } .photo-edit .btn { grid-column: 1 / -1; }
}
@media print {
  @page { margin: 14mm; }
  body { background: #fff; font-size: 11pt; }
  .no-print, .topbar, #toasts { display: none !important; }
  main { padding: 0; max-width: none; }
  .doc { border: 0; padding: 0; margin: 0; max-width: none; border-radius: 0; }
  .photo-grid { grid-template-columns: repeat(4, 1fr); } .photo img { aspect-ratio: 4/3; }
  .badge { border: 1px solid #999; background: #fff !important; color: #000 !important; }
  .summary .stat { break-inside: avoid; } h2, h3 { break-after: avoid; } tr { break-inside: avoid; }
  a { color: inherit; text-decoration: none; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* Sync now: the refresh icon spins while a sync is running */
@keyframes cloud-spin { to { transform: rotate(360deg); } }
#sync-now[aria-busy="true"] svg { animation: cloud-spin 1s linear infinite; }
#sync-now:disabled { opacity: .7; }
