:root {
  --ink: #142033;
  --muted: #5d6b7c;
  --line: #d5e0ea;
  --bg: #e7eef5;
  --panel: #fff;
  --brand: #0e4a6e;
  --accent: #1f6f9f;
  --radius: 14px;
  --shadow: 0 12px 32px rgba(16, 42, 67, 0.08);
  --font: "Inter", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(900px 420px at 0% -10%, #d5ebf8 0%, transparent 55%),
    var(--bg);
}
body.login-locked { overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.login-gate {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  overflow: hidden;
  padding: 1.5rem;
  background:
    radial-gradient(800px 420px at 15% 0%, #cfe6f6 0%, transparent 55%),
    linear-gradient(180deg, #e8f2fa, #d5e6f2);
}
.login-factory {
  position: absolute;
  inset: -28px;
  background:
    linear-gradient(180deg, rgba(232, 242, 250, 0.12), rgba(214, 230, 242, 0.08)),
    url("assets/login-factory.jpg?v=20260928f3") center / cover no-repeat;
  filter: blur(2px);
  transform: scale(1.06);
  pointer-events: none;
}
.login-gate::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(480px 380px at 50% 46%, rgba(255, 255, 255, 0.22), transparent 68%);
}
.login-card, .login-portal { position: relative; z-index: 2; }
.login-portal {
  position: absolute;
  top: max(0.85rem, env(safe-area-inset-top));
  left: max(0.85rem, env(safe-area-inset-left));
  z-index: 2;
  border: 1.5px solid rgba(14, 74, 110, 0.18);
  background: rgba(255, 255, 255, 0.92);
  color: var(--brand);
  font-weight: 800;
  font-size: 0.84rem;
  letter-spacing: 0.02em;
  border-radius: 8px;
  padding: 0.48rem 0.9rem;
  text-decoration: none;
  box-shadow: 0 8px 20px rgba(0, 26, 56, 0.12);
}
.login-portal:hover { background: var(--brand); color: #fff; }
.login-card {
  width: min(440px, 100%);
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: 22px;
  padding: 1.85rem 1.55rem 1.35rem;
  box-shadow: 0 28px 60px rgba(8, 28, 48, 0.28);
  display: grid;
  gap: 0.62rem;
  backdrop-filter: blur(8px);
  overflow: hidden;
}
.login-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(90deg, #0e4a6e, #3aa0c8);
}
.login-logo { width: min(100%, 250px); height: auto; display: block; margin: 0 auto 0.15rem; }
.login-product { margin: 0.15rem 0 0; font-size: 1.4rem; font-weight: 800; color: var(--brand); text-align: center; }
.login-sub, .login-error { margin: 0; color: var(--muted); font-size: 0.92rem; }
.login-sub { text-align: center; margin-bottom: 0.35rem; }
.login-card .btn-primary { margin-top: 0.25rem; border-radius: 12px; padding: 0.78rem 0.9rem; letter-spacing: 0.01em; }
.login-error { min-height: 1.2em; color: #9b1c1c; font-weight: 600; }
.login-card label, .editor label { display: grid; gap: 0.28rem; font-size: 0.82rem; font-weight: 600; color: var(--muted); }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.62rem 0.7rem;
  background: #fbfcfd;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(31, 111, 159, 0.25); border-color: var(--accent); }

.btn {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  padding: 0.62rem 0.9rem;
  font-weight: 700;
}
.btn-primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn-primary:hover { background: #0b3d5c; }
.btn-ghost { background: #f4f8fb; }
.icon-btn {
  border: 0;
  background: transparent;
  color: #8aa;
  font-size: 1.15rem;
  line-height: 1;
  padding: 0.2rem 0.35rem;
}

.app { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1rem;
  background: #fff;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 5;
}
.brand, .session { display: flex; align-items: center; gap: 0.7rem; }
.brand img { height: 36px; width: auto; border-radius: 6px; }
.brand strong, .brand span { display: block; }
.brand span, .session span { color: var(--muted); font-size: 0.82rem; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--brand); color: #fff; font-size: 0.75rem; font-weight: 800;
}

.workspace {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr) minmax(320px, 420px);
  gap: 0.8rem;
  padding: 0.8rem;
  align-items: start;
}
.side, .editor, .preview-col {
  min-width: 0;
}
.side, .preview-col {
  position: sticky;
  top: 72px;
  max-height: calc(100vh - 84px);
  overflow: auto;
}
.side { display: grid; gap: 0.5rem; align-content: start; }
.side-label { margin: 0.35rem 0 0; font-size: 0.72rem; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.side-note { margin: 0; color: var(--muted); font-size: 0.78rem; }
.doc-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.35rem; }
.doc-list li { display: flex; align-items: center; gap: 0.15rem; }
.doc-item {
  flex: 1;
  display: grid;
  grid-template-columns: 8px 1fr auto;
  gap: 0.45rem;
  align-items: center;
  text-align: left;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  padding: 0.55rem 0.6rem;
}
.doc-item.is-on { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.doc-item strong, .doc-item em { display: block; font-style: normal; }
.doc-item em, .doc-item small { color: var(--muted); font-size: 0.75rem; font-weight: 600; }
.doc-list .empty { color: var(--muted); font-size: 0.86rem; padding: 0.4rem; }
.dot { width: 8px; height: 8px; border-radius: 50%; }

.editor { display: grid; gap: 0.7rem; }
.editor-head, .section-row, .co-switch { display: flex; gap: 0.45rem; align-items: center; flex-wrap: wrap; }
.editor-head { justify-content: space-between; }
.eyebrow { margin: 0 0 0.35rem; font-size: 0.75rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.co-btn {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 0.4rem 0.75rem;
  font-weight: 700;
  font-size: 0.82rem;
}
.co-btn.is-on { background: var(--co, var(--brand)); color: #fff; border-color: transparent; }
.save-state { font-size: 0.8rem; font-weight: 700; color: #9a6200; }
.save-state.is-saved { color: #0f7a3f; }
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0.9rem 1rem 1rem;
  display: grid;
  gap: 0.65rem;
}
.card h2, .signs-edit h3 { margin: 0; font-size: 0.95rem; }
.grid-4, .grid-2, .grid-3, .split { display: grid; gap: 0.6rem; }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-2, .split { grid-template-columns: 1fr 1fr; }
.hint { margin: 0; color: var(--muted); font-size: 0.8rem; }
.table-wrap { overflow: auto; }
.edit-table { width: 100%; border-collapse: collapse; font-size: 0.84rem; }
.edit-table th { text-align: left; font-size: 0.72rem; color: var(--muted); padding: 0.3rem; }
.edit-table td { padding: 0.2rem; }
.edit-table input { padding: 0.45rem 0.4rem; }
.edit-table .seq { width: 4.2rem; text-align: center; font-weight: 700; color: var(--brand); }
.edit-table th.seq { text-align: center; }
.edit-table .num { white-space: nowrap; font-weight: 700; font-size: 0.78rem; }
.calc { display: grid; gap: 0.25rem; }
.calc div, .calc-net { display: flex; justify-content: space-between; gap: 1rem; font-size: 0.88rem; }
.calc-net { margin-top: 0.35rem; padding-top: 0.45rem; border-top: 1px solid var(--line); font-size: 1rem; }
.preview-col { background: #d5dee8; border-radius: 14px; padding: 0.7rem; }
.preview-scale { overflow: hidden; }
#preview-host { margin: 0 auto; overflow: hidden; }
#print-root { position: absolute; left: -12000px; top: 0; }
.modal {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(14, 32, 51, 0.45);
  display: grid; place-items: center; padding: 1rem;
}
.modal-card {
  width: min(980px, 100%);
  max-height: min(86vh, 820px);
  overflow: auto;
  background: #fff;
  border-radius: 16px;
  padding: 1rem 1.1rem 1.1rem;
  display: grid;
  gap: 0.7rem;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.2);
}
.modal-card header { display: flex; justify-content: space-between; gap: 1rem; align-items: start; }
.modal-card h2 { margin: 0; }
.modal-card header p { margin: 0.2rem 0 0; color: var(--muted); font-size: 0.85rem; }
.edit-table .warn { color: #9a6200; font-size: 0.75rem; white-space: nowrap; }
.pdf-snip { white-space: pre-wrap; font-size: 0.75rem; color: var(--ink); margin: 0.4rem 0 0; }
.toast {
  position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%);
  background: #142033; color: #fff; padding: 0.7rem 1rem; border-radius: 999px;
  font-weight: 700; z-index: 30;
}

.sheet-pack { display: flex; flex-direction: column; gap: 12px; width: 210mm; }
.sheet-page {
  width: 210mm; height: 297mm; position: relative; overflow: hidden;
  display: flex; flex-direction: column; color: #111; background: #fff;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}
.sheet-letterhead { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: fill; z-index: 0; }
.sheet-body, .sheet-foot { position: relative; z-index: 1; }
.sheet-body { flex: 1; min-height: 0; overflow: hidden; display: flex; flex-direction: column; }
.sheet-foot {
  display: flex; justify-content: space-between; font-size: 9px; color: #556; letter-spacing: 0.04em;
}
.sheet-paper-industrial .sheet-page { padding: 32mm 14mm 36mm; }
.sheet-paper-klimasist .sheet-page { padding: 32mm 14mm 34mm; }
.sheet-paper-kosiap .sheet-page { padding: 58mm 14mm 28mm; }
.sheet-paper-decrates .sheet-page { padding: 48mm 12mm 26mm 72mm; }
.hk-title { display: flex; justify-content: space-between; gap: 8px; align-items: flex-end; border-bottom: 1.5px solid var(--hk, #0e4a6e); padding-bottom: 4px; margin-bottom: 6px; }
.hk-kicker { margin: 0; font-size: 9px; line-height: 1.25; color: #445; max-width: 115mm; }
.hk-title h1 { margin: 2px 0 0; font-size: 26px; font-weight: 800; letter-spacing: 0.04em; }
.hk-meta { text-align: right; font-size: 11px; }
.hk-meta div { display: flex; justify-content: flex-end; gap: 6px; }
.hk-meta span { color: #667; }
.sheet-paper-industrial { --hk: #0e4a6e; }
.sheet-paper-klimasist { --hk: #0d5f96; }
.sheet-paper-kosiap { --hk: #0057c2; }
.sheet-paper-decrates { --hk: #6b5430; }
.hk-title h1, .hk-grid h2, .hk-summary .net td { color: var(--hk); }
.hk-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 6px; }
.hk-grid h2 { margin: 0 0 2px; font-size: 12px; letter-spacing: 0.04em; }
.hk-kv, .hk-table, .hk-summary table { width: 100%; border-collapse: collapse; }
.hk-kv th, .hk-kv td, .hk-summary th, .hk-summary td {
  border: 1px solid rgba(20, 32, 51, 0.16); padding: 3px 5px; vertical-align: top; font-size: 11px; line-height: 1.3;
}
.hk-table th, .hk-table td {
  border: 1px solid rgba(20, 32, 51, 0.2); padding: 4px 5px; vertical-align: middle; font-size: 11.5px; line-height: 1.3;
}
.hk-kv th, .hk-summary th { width: 38%; text-align: left; font-weight: 700; background: rgba(255, 255, 255, 0.55); }
.hk-table { margin-top: 2px; width: 100%; border-collapse: collapse; }
.hk-table th { background: color-mix(in srgb, var(--hk) 14%, white); text-align: left; font-size: 10px; letter-spacing: 0.03em; text-transform: uppercase; }
.hk-table td.seq, .hk-table th:first-child { width: 11%; text-align: center; font-weight: 700; }
.hk-table .work { width: 42%; }
.hk-table .work { white-space: pre-wrap; }
.num, .hk-table .num, .hk-summary td { text-align: right; white-space: nowrap; }
.hk-summary { margin-top: 4px; display: grid; gap: 4px; }
.hk-summary table { width: 62%; margin-left: auto; }
.hk-summary .net th, .hk-summary .net td { font-size: 12px; font-weight: 800; }
.hk-notes { grid-column: 1 / -1; font-size: 11px; }
.hk-notes p { margin: 2px 0 0; white-space: pre-wrap; }
.hk-signs { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; margin-top: 4px; }
.hk-signs div { border: 1px solid rgba(20, 32, 51, 0.18); min-height: 16mm; padding: 3px 4px; background: rgba(255, 255, 255, 0.45); }
.hk-signs span, .hk-signs em { display: block; font-size: 10px; color: #556; font-style: normal; }
.hk-signs b { display: block; margin-top: 5mm; font-size: 11px; }
.hk-cont { display: flex; justify-content: space-between; border-bottom: 1.5px solid var(--hk); margin-bottom: 6px; padding-bottom: 3px; font-size: 12px; }
.empty-row { text-align: center; color: #667; }

@media (max-width: 1180px) {
  .workspace { grid-template-columns: 220px minmax(0, 1fr); }
  .preview-col { grid-column: 1 / -1; position: static; max-height: none; }
  .grid-4 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 800px) {
  .workspace, .split, .grid-3, .grid-2 { grid-template-columns: 1fr; }
  .side { position: static; max-height: none; }
}

.app.shell {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  min-height: 100vh;
  background: #e7eef6;
}
.nav {
  background: linear-gradient(180deg, #0c2748 0%, #0a1d38 70%, #071428 100%);
  color: #fff;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 1.1rem 0.85rem 0.85rem;
  height: 100vh;
  position: sticky;
  top: 0;
  overflow: hidden;
}
.nav-brand { display: flex; align-items: center; margin: 0.15rem 0.2rem 1rem; }
.nav-brand img { width: 100%; height: auto; max-height: 58px; object-fit: contain; border-radius: 0; background: transparent; }
.nav-brand strong { display: block; font-size: 1.02rem; font-weight: 800; letter-spacing: -0.03em; text-transform: lowercase; }
.nav-brand span { display: block; font-size: 0.72rem; letter-spacing: 0.08em; text-transform: uppercase; opacity: 0.75; }
.nav-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.55rem;
  text-align: left;
  border: 0;
  background: transparent;
  color: #d7e4f0;
  border-radius: 10px;
  padding: 0.62rem 0.75rem;
  font-weight: 700;
}
.nav-item svg { width: 18px; height: 18px; flex: none; }
.nav-item.is-on { background: #14b8c9; color: #fff; }
.nav-kicker {
  margin: 0.9rem 0.2rem 0.2rem;
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #9fb4c9;
}
.nav .side-note, .nav .doc-item em, .nav .doc-item small { color: #b7c9da; }
.nav .doc-item {
  background: transparent;
  border-color: transparent;
  color: #fff;
  box-shadow: none;
}
.nav .doc-item.is-on, .nav .doc-item:hover { background: rgba(255, 255, 255, 0.08); }
.nav .doc-list { min-height: 0; }
.offer-scroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
  scrollbar-width: none;
}
.offer-scroll::-webkit-scrollbar { width: 0; height: 0; display: none; }
.offer-loading {
  display: grid;
  place-items: center;
  min-height: 8rem;
  margin: 0;
}
.offer-loading.is-error {
  min-height: 0;
  color: #f0c7c7;
  font-size: 0.8rem;
  text-align: center;
  padding: 0.6rem 0.2rem;
}
.spinner {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.18);
  border-top-color: #14b8c9;
  animation: offer-spin 0.75s linear infinite;
}
@keyframes offer-spin { to { transform: rotate(360deg); } }
.nav .nav-new {
  margin-top: 0.35rem;
  background: transparent;
  color: #fff;
  border-color: rgba(255, 255, 255, 0.22);
}
.nav-user {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.45rem;
  padding: 0.7rem 0.15rem 0.15rem;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  flex-shrink: 0;
}
.nav-user .session { min-width: 0; gap: 0.5rem; }
.nav-user .session-meta { display: grid; min-width: 0; line-height: 1.15; }
.nav-user .session span { color: #fff; font-size: 0.82rem; font-weight: 700; }
.nav-user #session-title { color: #9fb4c9; font-size: 0.66rem; font-weight: 600; white-space: normal; line-height: 1.2; }
.avatar.has-photo { background-color: transparent; background-size: cover; background-position: center 18%; }
.nav-user #session-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.nav-logout {
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: transparent;
  color: #fff;
  border-radius: 8px;
  padding: 0.38rem 0.6rem;
  font-weight: 700;
  font-size: 0.78rem;
  flex-shrink: 0;
}
.nav-logout:hover { background: rgba(255, 255, 255, 0.08); }
.shell-main { min-width: 0; display: flex; flex-direction: column; min-height: 100vh; }
.shell-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 0.8rem;
  padding: 1rem;
  align-items: start;
}
.app.shell .editor-head h1 { margin: 0; font-size: 1.28rem; }
.app.shell .editor-head p { margin: 0.12rem 0 0; color: var(--muted); font-size: 0.84rem; }
.app.shell .save-state {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.4rem 0.75rem;
  color: #8b97a6;
}
.app.shell .save-state.is-saved { color: #0f7a3f; }
.app.shell .card { border-radius: 16px; border-color: #e6eef5; }
.tabs { display: flex; gap: 0.35rem; flex-wrap: wrap; }
.tab {
  border: 0;
  background: transparent;
  color: #5d6b7c;
  font-weight: 700;
  border-radius: 999px;
  padding: 0.45rem 0.8rem;
}
.tab.is-on { background: #14b8c9; color: #fff; }
.preview-col { background: #fff; border-radius: 16px; padding: 0.75rem; box-shadow: var(--shadow); position: sticky; top: 12px; }
.preview-title { margin: 0 0 0.5rem; font-weight: 800; }
.app.shell .btn-primary { background: #14b8c9; border-color: #14b8c9; }
.app.shell .card h2 { font-size: 0.95rem; }
.app.shell .edit-table th { font-size: 0.72rem; color: #7b8b9c; }
.app.shell .edit-table .num { color: #0e7490; }
@media (max-width: 1180px) {
  .shell-body { grid-template-columns: 1fr; }
  .app.shell .preview-col { position: static; max-height: none; }
}
@media (max-width: 860px) {
  .app.shell { grid-template-columns: 1fr; }
  .nav { height: auto; position: static; overflow: visible; }
}

@page { size: A4; margin: 0; }
@media print {
  body { background: #fff; }
  .login-gate, .app, .toast { display: none !important; }
  #print-root { position: static !important; left: auto !important; display: block !important; }
  .sheet-pack { gap: 0; }
  .sheet-page { box-shadow: none; break-after: page; }
  .sheet-page:last-child { break-after: auto; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
