:root {
  --navy: #1f3864;
  --navy-2: #2b4a80;
  --band: #d9e1f2;
  --band-2: #eef2fa;
  --line: #bfbfbf;
  --line-soft: #e3e6ec;
  --ink: #1d2430;
  --muted: #5d6675;
  --input-ink: #0b3fd1;
  --input-bg: #fffbea;
  --pos: #137a2a;
  --neg: #c0161f;
  --page: #f4f6fa;
  --radius: 8px;
  font-family: Arial, "Helvetica Neue", Helvetica, sans-serif;
  color: var(--ink);
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--page); }
body { font-size: 14px; line-height: 1.35; }
button, input, select, textarea { font: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px 18px; background: var(--navy); color: #fff;
}
.brand { display: flex; align-items: center; gap: 10px; margin-right: auto; }
.brand-mark {
  display: grid; place-items: center; width: 34px; height: 34px; border-radius: 7px;
  background: #fff; color: var(--navy); font-weight: 700; font-size: 18px;
}
.brand-co { font-size: 12px; opacity: .8; letter-spacing: .02em; }
.brand-app { font-size: 17px; font-weight: 700; }
.bidbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
#bidPicker {
  min-width: 220px; max-width: 340px; padding: 7px 10px; border-radius: 6px;
  border: 1px solid rgba(255,255,255,.35); background: var(--navy-2); color: #fff;
}
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 6px; cursor: pointer;
  border: 1px solid rgba(255,255,255,.35); background: transparent; color: inherit; white-space: nowrap;
}
.btn:hover { background: rgba(255,255,255,.12); }
.btn.primary { background: var(--navy); color: #fff; border-color: var(--navy); }
.btn.primary:hover { background: var(--navy-2); }
.view .btn, .modal-body .btn { border-color: var(--line); color: var(--ink); }
.view .btn:hover, .modal-body .btn:hover { background: var(--band-2); }
.view .btn.primary, .modal-body .btn.primary { color: #fff; border-color: var(--navy); }
.view .btn.primary:hover, .modal-body .btn.primary:hover { background: var(--navy-2); }
.btn.danger, .menu-list .danger { color: var(--neg); }
.btn.small { padding: 4px 9px; font-size: 13px; }

.menu { position: relative; }
.menu > summary { list-style: none; }
.menu > summary::-webkit-details-marker { display: none; }
.menu-list {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 210px; padding: 6px;
  background: #fff; color: var(--ink); border-radius: var(--radius); box-shadow: 0 8px 24px rgba(15,30,60,.18);
  display: flex; flex-direction: column;
}
.menu-list button { text-align: left; padding: 8px 10px; border: 0; background: none; border-radius: 5px; cursor: pointer; }
.menu-list button:hover { background: var(--band-2); }

.status { font-size: 12px; padding: 5px 10px; border-radius: 999px; background: rgba(255,255,255,.14); white-space: nowrap; }
.status.ok::before { content: "● "; color: #7be39a; }
.status.local::before { content: "● "; color: #ffd166; }
.status.err { background: #ffdddd; color: var(--neg); }

/* ---------- Tabs ---------- */
.tabs {
  position: sticky; top: 58px; z-index: 15;
  display: flex; gap: 2px; overflow-x: auto; padding: 8px 14px 0; background: #fff; border-bottom: 1px solid var(--line-soft);
}
.tab {
  flex: 0 0 auto; padding: 9px 14px; border: 1px solid transparent; border-bottom: 0; border-radius: 7px 7px 0 0;
  background: none; cursor: pointer; color: var(--muted); max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tab:hover { background: var(--band-2); color: var(--ink); }
.tab.active { background: var(--page); border-color: var(--line-soft); color: var(--navy); font-weight: 700; }
.tab.fixed { font-weight: 600; }
.tab-sep { flex: 0 0 1px; background: var(--line-soft); margin: 6px 6px 0; }
.tab .badge { margin-left: 6px; }
.tab.add { color: var(--navy); font-weight: 600; }

/* ---------- Page ---------- */
.view { max-width: 1240px; margin: 0 auto; padding: 18px 18px 60px; }
.loading { color: var(--muted); }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin: 4px 0 14px; }
.page-head h1 { margin: 0; font-size: 22px; color: var(--navy); }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.card { background: #fff; border: 1px solid var(--line-soft); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.card h2 { margin: 0 0 10px; font-size: 15px; color: var(--navy); }
.hint { color: var(--muted); font-size: 12.5px; margin: 6px 0 0; }
.legend { display: inline-flex; gap: 14px; font-size: 12.5px; color: var(--muted); }
.legend .in { color: var(--input-ink); }

.grid-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.field input, .field textarea {
  width: 100%; padding: 7px 9px; border: 1px solid var(--line); border-radius: 6px; background: var(--input-bg); color: var(--input-ink);
}
.field textarea { min-height: 60px; resize: vertical; }

.task-head { display: flex; gap: 14px; align-items: flex-end; flex-wrap: wrap; }
.task-name { font-size: 20px; font-weight: 700; padding: 6px 10px; min-width: 260px; border: 1px solid var(--line); border-radius: 6px; color: var(--navy); background: var(--input-bg); }
.inline-field { display: flex; flex-direction: column; font-size: 12px; color: var(--muted); gap: 4px; }
.inline-field input[type=text]:not(.task-name) {
  width: 110px; padding: 7px 9px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--input-bg); color: var(--input-ink); text-align: right;
}
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink); padding-bottom: 6px; }
.spacer { flex: 1; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.sheet { width: 100%; border-collapse: collapse; background: #fff; }
.sheet th, .sheet td { border: 1px solid var(--line); padding: 0; height: 30px; vertical-align: middle; }
.sheet thead th { background: var(--navy); color: #fff; font-weight: 700; padding: 6px 8px; text-align: center; white-space: nowrap; }
.sheet thead th.left { text-align: left; }
.sheet td.lbl { padding: 4px 8px; font-weight: 700; white-space: nowrap; }
.sheet td.num, .sheet td.out { padding: 4px 8px; text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.sheet td.txt { padding: 4px 8px; }
.sheet td.ctr { text-align: center; }
.sheet tr.total td { background: var(--band); font-weight: 700; }
.sheet tr.subtle td { background: var(--band-2); }
.sheet tr.alt td { color: var(--muted); }
.sheet tr.alt td.lbl { font-style: italic; }
.sheet td.act { width: 34px; text-align: center; }
.sheet input {
  width: 100%; height: 100%; min-height: 29px; padding: 4px 8px; border: 0; background: var(--input-bg); color: var(--input-ink);
  outline: none;
}
.sheet input.num { text-align: right; font-variant-numeric: tabular-nums; }
.sheet input:focus { box-shadow: inset 0 0 0 2px #4d7cff; background: #fff; }
.sheet td.w-desc { min-width: 200px; }
.sheet td.w-item { min-width: 130px; }
.sheet td.w-num { width: 105px; }
.sheet td.w-unit { width: 70px; }
.sheet .neg { color: var(--neg); }
.sheet .pos { color: var(--pos); }
.net-cell { font-size: 15px; }
.icon-btn { border: 0; background: none; cursor: pointer; color: var(--muted); font-size: 16px; line-height: 1; padding: 4px 6px; border-radius: 4px; }
.icon-btn:hover { color: var(--neg); background: #fdecec; }
.link { border: 0; background: none; padding: 0; color: var(--navy); font-weight: 700; cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.badge { display: inline-block; font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 999px; background: #fff1c2; color: #7a5a00; vertical-align: middle; }
.section { margin-bottom: 18px; }
.section-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 6px; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.kpi { background: #fff; border: 1px solid var(--line-soft); border-radius: var(--radius); padding: 10px 12px; }
.kpi .k { font-size: 12px; color: var(--muted); }
.kpi .v { font-size: 19px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi .p { font-size: 12px; color: var(--muted); }
.kpi.net .v.pos { color: var(--pos); }
.kpi.net .v.neg { color: var(--neg); }

.calc-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 460px), 1fr)); gap: 16px; }
.calc-grid .card { margin: 0; }
.calc-grid .wide { grid-column: 1 / -1; }

/* ---------- Modal ---------- */
dialog { border: 0; border-radius: 12px; padding: 0; box-shadow: 0 20px 50px rgba(10,20,40,.3); max-width: 420px; width: calc(100% - 32px); }
dialog::backdrop { background: rgba(10,20,40,.45); }
.modal-body { padding: 20px; }
.modal-body h2 { margin: 0 0 8px; font-size: 17px; color: var(--navy); }
.modal-body p { margin: 0 0 12px; color: var(--muted); }
.modal-body input { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

/* ---------- Print ---------- */
@media print {
  body { background: #fff; font-size: 11px; }
  .topbar, .tabs, .no-print, .icon-btn, .section-foot button, .act { display: none !important; }
  .view { max-width: none; padding: 0; }
  .card { border: 0; padding: 0; }
  .sheet input { background: none; color: #000; }
  .sheet thead th { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .sheet tr.total td { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

@media (max-width: 720px) {
  .tabs { top: 0; position: static; }
  .topbar { position: static; }
  #bidPicker { min-width: 0; width: 100%; }
  .bidbar { width: 100%; }
}
