:root {
  --ink: #0e1a2b;
  --ink-2: #1d2b40;
  --text: #1c2430;
  --muted: #667085;
  --line: #e4e1da;
  --bg: #f5f3ee;
  --card: #ffffff;
  --gold: #b0843a;
  --gold-soft: #f3ead9;
  --green: #1f7a4d;
  --green-soft: #e3f2ea;
  --red: #b4372f;
  --red-soft: #fbe9e7;
  --blue: #2c5e9e;
  --blue-soft: #e6eef8;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(14, 26, 43, .06), 0 2px 8px rgba(14, 26, 43, .04);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.55 Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-feature-settings: "tnum" 1;
}
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { color: var(--ink); line-height: 1.25; margin: 0 0 .5rem; }
h1 { font-size: 1.6rem; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 1.15rem; font-weight: 650; }
h3 { font-size: 1rem; font-weight: 600; }
p { margin: 0 0 .75rem; }
small, .muted { color: var(--muted); }
.num { text-align: right; white-space: nowrap; }

/* ---------- top bar ---------- */
.topbar { background: var(--ink); color: #fff; }
.topbar .inner { max-width: 1180px; margin: 0 auto; padding: 0 20px; height: 60px; display: flex; align-items: center; gap: 24px; }
.brand { display: flex; align-items: baseline; gap: 8px; color: #fff; font-weight: 700; letter-spacing: .18em; font-size: 15px; }
.brand:hover { text-decoration: none; }
.brand span { color: var(--gold); font-weight: 500; letter-spacing: .06em; font-size: 13px; }
.nav { display: flex; gap: 4px; margin-left: auto; align-items: center; flex-wrap: wrap; }
.nav a, .nav button { color: #c9d1dc; padding: 6px 10px; border-radius: 6px; font-size: 14px; background: none; border: 0; cursor: pointer; font: inherit; font-size: 14px; }
.nav a:hover, .nav button:hover { color: #fff; background: var(--ink-2); text-decoration: none; }
.nav a.active { color: #fff; background: var(--ink-2); }
.nav form { margin: 0; }

@media (max-width: 640px) {
  .topbar .inner { height: auto; flex-wrap: wrap; padding: 10px 16px 6px; gap: 6px; }
  .nav { margin-left: 0; width: 100%; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -10px; }
  .nav::-webkit-scrollbar { display: none; }
  .nav a, .nav button { white-space: nowrap; }
}

main { max-width: 1180px; margin: 0 auto; padding: 28px 20px 64px; }

/* ---------- flash ---------- */
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 18px; font-size: 14px; border: 1px solid transparent; }
.flash.success { background: var(--green-soft); color: var(--green); border-color: #c4e3d2; }
.flash.error { background: var(--red-soft); color: var(--red); border-color: #f1c9c4; }
.flash.info { background: var(--blue-soft); color: var(--blue); border-color: #c9daef; }

/* ---------- layout bits ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head p { margin: 0; }
.crumb { font-size: 13px; color: var(--muted); margin-bottom: 4px; display: block; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 20px; }
.card > h2:first-child, .card > h3:first-child { margin-bottom: 14px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.card-head h2, .card-head h3 { margin: 0; }
.grid { display: grid; gap: 20px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.split { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 20px; align-items: start; }
@media (max-width: 860px) { .grid-2, .grid-3, .split { grid-template-columns: 1fr; } }

/* ---------- stats ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat .label { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.stat .value { font-size: 1.45rem; font-weight: 650; color: var(--ink); margin-top: 2px; }
.stat .sub { font-size: 12.5px; color: var(--muted); }
.stat.accent { background: var(--ink); border-color: var(--ink); }
.stat.accent .label, .stat.accent .sub { color: #aab4c3; }
.stat.accent .value { color: #fff; }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 22px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a { padding: 10px 14px; color: var(--muted); font-weight: 500; font-size: 14px; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a:hover { color: var(--ink); text-decoration: none; }
.tabs a.active { color: var(--ink); border-bottom-color: var(--gold); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 10px; border-bottom: 1px solid #efede8; vertical-align: top; }
tr:last-child td { border-bottom: 0; }
tfoot td { font-weight: 650; border-top: 1px solid var(--line); color: var(--ink); }
table.kv td { padding: 7px 0; }
table.kv td:last-child { text-align: right; font-weight: 550; color: var(--ink); }
table.kv tr.total td { border-top: 1px solid var(--line); font-weight: 700; }
table.edit td { padding: 6px 4px; vertical-align: middle; }
table.edit input, table.edit select { padding: 6px 8px; font-size: 13.5px; }

/* ---------- forms ---------- */
label { display: block; font-size: 13px; font-weight: 550; color: var(--ink); margin-bottom: 4px; }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=number], input[type=tel], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid #d5d1c8; border-radius: 7px; background: #fff; font: inherit; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(176, 132, 58, .35); border-color: var(--gold); }
textarea { resize: vertical; min-height: 80px; }
.field { margin-bottom: 14px; }
.field .hint { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.inline-form { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
.inline-form .field { margin: 0; }
fieldset { border: 0; padding: 0; margin: 0 0 8px; }
legend { font-size: 12px; font-weight: 650; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 10px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 16px; border-radius: 7px; border: 1px solid var(--ink); background: var(--ink); color: #fff; font: inherit; font-size: 14px; font-weight: 550; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--ink-2); text-decoration: none; }
.btn.secondary { background: #fff; color: var(--ink); border-color: #d5d1c8; }
.btn.secondary:hover { background: #faf9f6; }
.btn.danger { background: #fff; color: var(--red); border-color: #e7c2bd; }
.btn.danger:hover { background: var(--red-soft); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.gold { background: var(--gold); border-color: var(--gold); }
.link-btn { background: none; border: 0; padding: 0; color: var(--blue); cursor: pointer; font: inherit; font-size: 13px; }
.link-btn.danger { color: var(--red); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
form.inline { display: inline; margin: 0; }

/* ---------- badges ---------- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: #eeece6; color: var(--ink-2); white-space: nowrap; }
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.red { background: var(--red-soft); color: var(--red); }
.badge.blue { background: var(--blue-soft); color: var(--blue); }
.badge.gold { background: var(--gold-soft); color: #8a6526; }

/* ---------- login ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: var(--ink); background-image: radial-gradient(ellipse at top, #1f324d 0%, var(--ink) 60%); }
.auth-card { width: 100%; max-width: 400px; background: #fff; border-radius: 14px; padding: 32px; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.auth-brand { text-align: center; margin-bottom: 24px; }
.auth-brand .word { font-weight: 750; letter-spacing: .3em; font-size: 22px; color: var(--ink); padding-left: .3em; }
.auth-brand .sub { color: var(--gold); letter-spacing: .14em; text-transform: uppercase; font-size: 12px; font-weight: 600; margin-top: 2px; }
.auth-card .btn { width: 100%; padding: 11px; }

/* ---------- project cards (portfolio) ---------- */
.project-card { display: grid; grid-template-columns: 240px minmax(0, 1fr); overflow: hidden; padding: 0; color: inherit; }
.project-card:hover { text-decoration: none; border-color: #cfc9bc; }
.project-card .cover { background: #dcd7cc center/cover no-repeat; min-height: 180px; }
.project-card .body { padding: 18px 20px; }
.project-card .mini-stats { display: flex; gap: 28px; flex-wrap: wrap; margin-top: 12px; }
.mini-stats .label { font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.mini-stats .value { font-weight: 650; color: var(--ink); }
@media (max-width: 640px) { .project-card { grid-template-columns: 1fr; } .project-card .cover { min-height: 160px; } }

.hero { position: relative; border-radius: var(--radius); overflow: hidden; background: #d9d3c6 center/cover no-repeat; min-height: 260px; margin-bottom: 20px; }
.hero .hero-text { position: absolute; inset: auto 0 0 0; padding: 24px; background: linear-gradient(transparent, rgba(8, 16, 28, .82)); color: #fff; }
.hero h1 { color: #fff; margin: 0; }
.hero p { margin: 4px 0 0; color: #e3e7ee; }
.title-block { margin-bottom: 18px; }

/* ---------- updates ---------- */
.updates { list-style: none; margin: 0; padding: 0; }
.updates li { display: grid; grid-template-columns: 110px minmax(0, 1fr); gap: 14px; padding: 12px 0; border-bottom: 1px solid #efede8; }
.updates li:last-child { border-bottom: 0; }
.updates .date { font-size: 13px; font-weight: 600; color: var(--gold); white-space: nowrap; padding-top: 1px; }
.updates .text { white-space: pre-line; }
@media (max-width: 520px) { .updates li { grid-template-columns: 1fr; gap: 2px; } }

/* ---------- documents ---------- */
.doc-group { margin-bottom: 18px; }
.doc-group h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 6px; }
.doc { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 6px; background: #fff; }
.doc .icon { width: 36px; height: 36px; border-radius: 6px; background: var(--gold-soft); color: #8a6526; display: grid; place-items: center; font-size: 10.5px; font-weight: 750; flex: none; }
.doc .meta { flex: 1; min-width: 0; }
.doc .meta a { font-weight: 550; color: var(--ink); }
.doc .meta small { display: block; }

/* ---------- photos ---------- */
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.gallery figure { margin: 0; background: #fff; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.gallery img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; display: block; cursor: zoom-in; background: #e8e4dc; }
.gallery figcaption { padding: 8px 10px; font-size: 13px; }
.gallery figcaption small { display: block; }
.lightbox { position: fixed; inset: 0; background: rgba(5, 10, 18, .92); display: none; align-items: center; justify-content: center; z-index: 50; padding: 20px; }
.lightbox.open { display: flex; }
.lightbox img { max-width: 100%; max-height: 86vh; border-radius: 4px; }
.lightbox .cap { color: #dde3ea; text-align: center; margin-top: 10px; font-size: 14px; }
.lightbox .lb-btn { position: absolute; top: 50%; transform: translateY(-50%); background: rgba(255,255,255,.12); color: #fff; border: 0; width: 44px; height: 44px; border-radius: 50%; font-size: 22px; cursor: pointer; }
.lightbox .prev { left: 14px; } .lightbox .next { right: 14px; }
.lightbox .close { position: absolute; top: 14px; right: 14px; background: rgba(255,255,255,.12); color: #fff; border: 0; width: 40px; height: 40px; border-radius: 50%; font-size: 20px; cursor: pointer; }

.dropzone { border: 2px dashed #d5d1c8; border-radius: 10px; padding: 22px; text-align: center; background: #fbfaf7; }
.dropzone.drag { border-color: var(--gold); background: var(--gold-soft); }
.progress { height: 6px; background: #ece8df; border-radius: 99px; overflow: hidden; margin-top: 10px; display: none; }
.progress div { height: 100%; width: 0; background: var(--gold); transition: width .2s; }

/* ---------- timeline / gantt ---------- */
.gantt { position: relative; padding-bottom: 16px; }
.gantt-row { display: grid; grid-template-columns: 200px minmax(0, 1fr); align-items: center; min-height: 44px; border-bottom: 1px solid #efede8; }
.gantt-row:last-child { border-bottom: 0; }
.gantt-label { font-size: 13.5px; font-weight: 550; padding-right: 12px; color: var(--ink); }
.gantt-label small { display: block; font-weight: 400; }
.gantt-track { position: relative; height: 30px; }
.gantt-bar { position: absolute; height: 10px; border-radius: 3px; }
.gantt-bar.proj { top: 4px; background: #d8d2c4; }
.gantt-bar.act { top: 16px; background: var(--ink); }
.gantt-bar.act.late { background: var(--red); }
.gantt-bar.act.open { background: repeating-linear-gradient(45deg, var(--gold), var(--gold) 6px, #c79d55 6px, #c79d55 12px); }
.gantt-axis { position: relative; height: 22px; margin-left: 200px; font-size: 11px; color: var(--muted); }
.gantt-axis span { position: absolute; transform: translateX(-50%); white-space: nowrap; }
.gantt-grid { position: absolute; top: 22px; bottom: 0; left: 200px; right: 0; pointer-events: none; }
.gantt-grid i { position: absolute; top: 0; bottom: 0; border-left: 1px dashed #ebe7df; }
.gantt-grid .today { border-left: 2px solid var(--gold); }
.gantt-grid .today::before { content: "Today"; position: absolute; bottom: -16px; left: -15px; font-size: 10.5px; font-weight: 700; color: var(--gold); font-style: normal; }
.legend { display: flex; gap: 18px; font-size: 12.5px; color: var(--muted); margin-bottom: 12px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 18px; height: 8px; border-radius: 2px; margin-right: 6px; vertical-align: middle; }
@media (max-width: 640px) {
  .gantt-row { grid-template-columns: 110px minmax(0, 1fr); }
  .gantt-grid { left: 110px; }
  .gantt-axis { margin-left: 110px; }
}

/* ---------- misc ---------- */
.empty { text-align: center; color: var(--muted); padding: 28px 12px; }
.prose { white-space: pre-line; }
.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px 20px; }
.facts .label { font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.facts .value { font-weight: 600; color: var(--ink); }
.bar { height: 8px; background: #ece8df; border-radius: 99px; overflow: hidden; }
.bar div { height: 100%; background: var(--ink); }
.bar div.over { background: var(--red); }
.note { font-size: 12.5px; color: var(--muted); background: #faf8f3; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.secret { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; background: #fff; border: 1px dashed var(--gold); padding: 3px 8px; border-radius: 5px; font-size: 14px; user-select: all; }
details > summary { cursor: pointer; color: var(--blue); font-size: 14px; }
details[open] > summary { margin-bottom: 12px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 18px 0; }
.danger-zone { border-color: #efcdc8; }
.pos { color: var(--green); } .neg { color: var(--red); }

@media (max-width: 640px) {
  main { padding: 20px 16px 48px; }
  .card { padding: 16px; }
  h1 { font-size: 1.4rem; }
}

/* AI import review */
tr.low-conf td { background: #fff6f4; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .92em; background: #f1eee7; padding: 1px 5px; border-radius: 4px; }
.snapshot-bar { display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex-wrap: wrap; margin: -8px 0 16px; font-size: 13.5px; }

/* Read-only team view: hide controls that change data (server enforces this too) */
body.ro .edit-only, body.ro form[method="post"] button, body.ro form[method="post"] .btn,
body.ro button[form], body.ro input[type="file"] { display: none !important; }
body.ro details > summary { pointer-events: none; color: var(--muted); }
