/* BimDocx — «інженерний реєстр»: точний, спокійний, професійний інтерфейс. */
:root {
  --paper: #eceff3;
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --ink: #14181f;
  --muted: #5c6675;
  --faint: #8b93a1;
  --line: #dde2ea;
  --line-strong: #c8cfdb;

  --rail: #172230;
  --rail-2: #10192444;
  --rail-line: #26333f;
  --rail-text: #9aa6b6;
  --rail-strong: #f2f5f9;

  --brand: #1e4e7b;
  --brand-hover: #1a4368;
  --brand-soft: #e8f0f8;
  --brand-line: #b9d0e4;

  --ok: #1c8f52;
  --warn: #a9760f;
  --danger: #c23b3b;
  --danger-soft: #fbecec;

  --mono: ui-monospace, "Cascadia Code", "JetBrains Mono", "SF Mono", Consolas, monospace;
  --sans: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", sans-serif;
  --r: 10px;
  --shadow: 0 1px 2px rgba(20,24,31,.04), 0 8px 24px rgba(20,24,31,.06);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
}

/* ---------------------------------- Shell --------------------------------- */
.app { display: flex; height: 100vh; overflow: hidden; }

.sidebar {
  width: 236px;
  flex-shrink: 0;
  background: var(--rail);
  color: var(--rail-text);
  border-right: 1px solid var(--rail-line);
  display: flex;
  flex-direction: column;
  padding: 18px 12px 14px;
  gap: 2px;
}
.brand { display: flex; align-items: center; gap: 11px; padding: 4px 8px 20px; }
.brand .mark {
  width: 34px; height: 34px; flex-shrink: 0; border-radius: 8px;
  background: linear-gradient(150deg, #2f6ea3, #1e4e7b);
  display: grid; place-items: center;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.12);
}
.brand .mark svg { width: 19px; height: 19px; }
.brand h1 { font-size: 15.5px; font-weight: 650; color: var(--rail-strong); margin: 0; letter-spacing: .2px; }
.brand p { font-size: 10.5px; color: var(--rail-text); margin: 2px 0 0; letter-spacing: .3px; text-transform: uppercase; }

.nav-group { font-size: 10px; letter-spacing: .12em; text-transform: uppercase; color: #66748a; padding: 14px 10px 6px; }
.nav-btn {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 11px; border-radius: 8px;
  border: none; background: transparent; color: var(--rail-text);
  font-size: 13.5px; font-family: inherit; cursor: pointer; text-align: left; width: 100%;
  transition: background .14s, color .14s;
}
.nav-btn svg { width: 18px; height: 18px; flex-shrink: 0; stroke: currentColor; }
.nav-btn:hover { background: #1f2d3d; color: var(--rail-strong); }
.nav-btn.active { background: #21344c; color: #fff; }
.nav-btn.active svg { color: #7fb0dc; }
.nav-spacer { flex: 1; }
.nav-foot { font-size: 10.5px; color: #5f6d80; padding: 10px 10px 2px; line-height: 1.55; border-top: 1px solid var(--rail-line); margin-top: 8px; }

.main { flex: 1; overflow-y: auto; }
.page { display: none; max-width: 1520px; margin: 0 auto; padding: 30px 34px 70px; }
.page.active { display: block; animation: rise .22s ease; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.page-title { font-size: 22px; font-weight: 650; letter-spacing: -.01em; margin: 0 0 5px; }
.page-sub { color: var(--muted); margin: 0 0 24px; font-size: 13.5px; max-width: 70ch; }

/* ---------------------------------- Cards --------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 20px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
}
.card h3 { margin: 0 0 4px; font-size: 15px; font-weight: 620; }
.card .hint { color: var(--muted); font-size: 12.5px; margin: 0 0 14px; }
.card h3 + .hint { margin-top: 2px; }

/* --------------------------------- Buttons -------------------------------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 15px; border-radius: 9px;
  border: 1px solid var(--line-strong); background: var(--surface);
  color: var(--ink); font-size: 13.5px; font-family: inherit; font-weight: 550; cursor: pointer;
  transition: all .13s; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); border-color: var(--faint); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { color: var(--danger); border-color: #e6bcbc; }
.btn.danger:hover { background: var(--danger-soft); }
.btn.sm { padding: 5px 10px; font-size: 12px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.row-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* -------------------------------- Dropzone -------------------------------- */
.drop {
  border: 1.5px dashed var(--line-strong); border-radius: 12px;
  padding: 26px 20px; text-align: center; cursor: pointer;
  transition: all .15s; background: var(--surface-2); color: var(--muted);
}
.drop:hover, .drop.over { border-color: var(--brand); background: var(--brand-soft); color: var(--brand); }
.drop .big { display: none; }
.drop .fname { color: var(--ok); font-weight: 600; margin-top: 8px; font-family: var(--mono); font-size: 12.5px; }
.file-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 900px){ .file-grid { grid-template-columns: 1fr; } }

/* --------------------------------- Forms ---------------------------------- */
label.field { display: block; margin-bottom: 14px; }
label.field span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; font-weight: 550; }
input[type=text], input[type=password], input[type=number], input[type=email], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line-strong);
  border-radius: 8px; font-size: 13.5px; font-family: inherit; background: #fff; color: var(--ink);
  transition: border-color .12s, box-shadow .12s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px,1fr)); gap: 0 18px; }

/* --------------------------------- Tables --------------------------------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; background: #fff; box-shadow: var(--shadow); }
table.grid { border-collapse: collapse; width: 100%; font-size: 12.5px; }
table.grid th, table.grid td { border-bottom: 1px solid var(--line); border-right: 1px solid var(--line); padding: 6px 8px; text-align: left; vertical-align: top; }
table.grid th {
  background: var(--surface-2); position: sticky; top: 0; z-index: 2;
  font-size: 10.5px; font-weight: 620; letter-spacing: .03em; text-transform: uppercase;
  color: var(--muted); white-space: nowrap; border-bottom: 1px solid var(--line-strong);
}
table.grid td[contenteditable] { min-width: 62px; cursor: text; }
table.grid td[contenteditable]:focus { outline: 2px solid var(--brand); outline-offset: -2px; background: var(--brand-soft); }
table.grid tbody tr:hover td { background: #f9fafc; }
table.grid tr.pricing td:first-child { box-shadow: inset 3px 0 0 var(--brand); }
/* Дані-колонки — моноширинний «реєстр» */
table.grid td.num, table.grid td.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
table.grid td.num { text-align: right; }

.badge { display: inline-block; padding: 1px 8px; border-radius: 5px; font-size: 10.5px; font-weight: 600; font-family: var(--mono); }
.badge.p { background: var(--brand-soft); color: var(--brand); }
.badge.n { background: #eef0f3; color: var(--muted); }

/* --------------------------------- Stats ---------------------------------- */
.stats { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 18px; min-width: 130px; box-shadow: var(--shadow); }
.stat .v { font-size: 22px; font-weight: 680; font-family: var(--mono); font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.stat .k { font-size: 11px; color: var(--muted); margin-top: 2px; }

/* --------------------------------- Toasts --------------------------------- */
#toasts { position: fixed; bottom: 22px; right: 22px; display: flex; flex-direction: column; gap: 9px; z-index: 999; }
.toast { padding: 11px 16px; border-radius: 10px; background: var(--ink); color: #fff; box-shadow: var(--shadow); font-size: 13px; max-width: 380px; animation: rise .2s; border-left: 3px solid #3a4657; }
.toast.ok { border-left-color: #35c07e; }
.toast.err { border-left-color: #e06666; }

/* --------------------------------- Lists ---------------------------------- */
.list-row { display: flex; align-items: center; gap: 14px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 11px; margin-bottom: 9px; background: #fff; box-shadow: var(--shadow); }
.list-row .grow { flex: 1; }
.list-row .t { font-weight: 600; }
.list-row .s { font-size: 12px; color: var(--muted); margin-top: 3px; }
.tag { display: inline-block; background: var(--surface-2); border: 1px solid var(--line); border-radius: 6px; padding: 1px 8px; font-size: 11px; margin-right: 5px; font-family: var(--mono); color: var(--muted); }

.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip { background: var(--surface-2); border: 1px solid var(--line-strong); border-radius: 8px; padding: 5px 8px 5px 11px; font-size: 12px; display: inline-flex; gap: 7px; align-items: center; }
.chip button { border: none; background: none; cursor: pointer; color: var(--faint); font-size: 15px; line-height: 1; padding: 0; }
.chip button:hover { color: var(--danger); }

.info-banner { background: #fbf7ec; border: 1px solid #ecdcae; color: #6b5410; border-radius: 12px; padding: 15px 17px; font-size: 13px; line-height: 1.6; margin-bottom: 18px; }
.info-banner b { color: #4a3a08; }
.empty { text-align: center; color: var(--muted); padding: 44px 20px; font-size: 13.5px; }

.toolbar { display: flex; gap: 11px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar .grow { flex: 1; }
.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 9px; overflow: hidden; }
.seg button { border: none; background: #fff; padding: 7px 14px; cursor: pointer; font-size: 13px; color: var(--ink); font-family: inherit; }
.seg button.active { background: var(--brand); color: #fff; }
code { font-family: var(--mono); font-size: .92em; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }

/* ------------------------------ Review modal ------------------------------ */
.overlay { position: fixed; inset: 0; background: rgba(16,23,33,.5); backdrop-filter: blur(2px); display: flex; align-items: center; justify-content: center; z-index: 500; padding: 22px; }
.modal { background: var(--surface); border-radius: 16px; box-shadow: 0 24px 60px rgba(16,23,33,.28); width: 100%; max-width: 780px; max-height: 88vh; display: flex; flex-direction: column; overflow: hidden; }
.modal-head { display: flex; align-items: flex-start; gap: 12px; padding: 18px 22px; border-bottom: 1px solid var(--line); }
.modal-title { font-size: 17px; font-weight: 640; }
.modal-sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; font-family: var(--mono); }
.modal-body { padding: 18px 22px; overflow-y: auto; }
.modal-foot { display: flex; align-items: center; gap: 10px; padding: 13px 22px; border-top: 1px solid var(--line); }
.mat-name { font-size: 14.5px; font-weight: 620; margin-bottom: 4px; }
.mat-meta { font-size: 12px; color: var(--muted); margin-bottom: 16px; font-family: var(--mono); }
.cand { border: 1px solid var(--line); border-radius: 12px; padding: 13px 15px; margin-bottom: 11px; transition: border-color .12s, box-shadow .12s; }
.cand:hover { border-color: var(--brand-line); box-shadow: var(--shadow); }
.cand-top { display: flex; align-items: center; gap: 9px; margin-bottom: 7px; flex-wrap: wrap; }
.cand-name { font-weight: 600; flex: 1; min-width: 180px; }
.cand-price { font-weight: 680; font-size: 15px; font-family: var(--mono); }
.conf { padding: 2px 9px; border-radius: 6px; font-size: 10.5px; font-weight: 700; letter-spacing: .03em; font-family: var(--mono); }
.conf.HIGH { background: #dff3e7; color: #10743f; }
.conf.MEDIUM { background: #fbeecc; color: #86620c; }
.conf.LOW { background: #f7e7e7; color: #a13636; }
.conf.REJECTED { background: #eceef1; color: #7a828f; }
.cand-row { font-size: 12.5px; color: var(--muted); margin: 4px 0; }
.cand-row a { color: var(--brand); word-break: break-all; }
.cand-row.mono { font-family: var(--mono); }
.cand-actions { display: flex; gap: 9px; margin-top: 11px; align-items: center; flex-wrap: wrap; }
.edrpou-in { width: 140px; padding: 6px 9px; font-family: var(--mono); }
.empty-cand { text-align: center; color: var(--muted); padding: 22px; }
.spin { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--line-strong); border-top-color: var(--brand); border-radius: 50%; animation: sp .7s linear infinite; vertical-align: -2px; margin-right: 6px; }
@keyframes sp { to { transform: rotate(360deg); } }

/* ------------------------------ Accessibility ----------------------------- */
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
