:root {
  --navy: #0c1929;
  --navy-mid: #132a45;
  --accent: #1a6dff;
  --accent-hover: #1558d6;
  --blue: #154e86;
  --blue-dark: #0e345c;
  --ink: #1c2836;
  --muted: #5d6b7c;
  --line: #e1e8f0;
  --line-strong: #c9d4e2;
  --bg: #f3f6fa;
  --paper: #fff;
  --input: #fff;
  --green: #1f7a4d;
  --yellow: #9a6700;
  --red: #991b1b;
  --ok: #ecfdf5;
  --err: #fef2f2;
  --font: "Segoe UI", system-ui, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: var(--font); font-size: 14px; color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased; }
a { color: var(--blue); }
button, .btn { background: var(--blue); color: #fff; border: 1px solid var(--blue); border-radius: 8px; padding: 8px 14px; cursor: pointer; font: inherit; font-size: 14px; font-weight: 600; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }
button:hover, .btn:hover { background: var(--blue-dark); border-color: var(--blue-dark); color: #fff}
button.secondary, .btn.secondary { background: var(--paper); color: var(--blue-dark); border: 1px solid var(--line-strong); }
button.secondary:hover, .btn.secondary:hover { background: #f4f8fc; border-color: var(--blue); color: var(--blue); }
button.danger { background: var(--red); border-color: var(--red); }
button:disabled { opacity: .45; cursor: default; }
input, select, textarea { width: 100%; font: inherit; padding: 9px 12px; border: 1px solid var(--line-strong); border-radius: 8px; background: #fff; color: var(--ink); }
input:focus, select:focus, textarea:focus { outline: 0; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(21, 78, 134, .15); }
label.field { display: block; margin-bottom: 12px; font-size: 13px; font-weight: 600; }
label.field span { display: block; margin-bottom: 4px; color: var(--muted); font-weight: 600; }
#login { min-height: 100vh; background: #eee; font-family: "proxima-nova", "Segoe UI", system-ui, sans-serif; }
#login .image { position: absolute; top: 0; left: 0; width: 46%; height: 100%; overflow: hidden; background: var(--navy); z-index: 2; }
#login .image .bg { position: absolute; inset: 0; background: url("../images/login.jpg") center/cover no-repeat; opacity: .35; }
#login .image .brand { position: absolute; left: 48px; right: 48px; bottom: 48px; color: #fff; }
#login .image .brand img { width: 180px; max-width: 50%; margin-bottom: 20px; display: block; }
#login .image .brand h2 { margin: 0 0 8px; color: #fff; font-size: 28px; line-height: 34px; font-weight: 600; letter-spacing: -.03em; }
#login .image .brand p { margin: 0; color: rgba(255,255,255,.72); font-size: 15px; line-height: 22px; font-weight: 400; }
#login .form { margin-left: 46%; width: 54%; min-height: 100vh; background: var(--paper); position: relative; }
#login .form form { width: min(380px, calc(100% - 48px)); position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); }
#login .form h3 { margin: 0 0 8px; font-size: 20px; line-height: 28px; font-weight: 700; letter-spacing: -.03em; }
#login .form form > p { margin: 0 0 28px; color: var(--muted); font-size: 15px; line-height: 22px; }
#login .form label.field { font-weight: 600; }
#login .form input { padding: 12px 14px; font-size: 15px; font-weight: 400; margin-bottom: 0; border-color: #aeb4bc; border-radius: 6px; background: #f0f1f3; }
#login .form input:focus { border-color: #1a6dff; box-shadow: 0 0 0 3px rgba(26, 109, 255, .15); }
#login .form button[type="submit"] { margin-top: 8px; padding: 11px 22px; font-size: 14px; border: 0; border-radius: 6px; background: #0c1929; }
#login .form button[type="submit"]:hover { background: #132a45; }
#login .banner { border: 1px solid #fecaca; }
#login .banner.ok { border-color: #a7f3d0; }
#login .login-links { margin: 18px 0 0; clear: both; }
#login .login-links a { color: #1a6dff; font-size: 14px; font-weight: 600; text-decoration: none; }
#login .login-links a:hover { text-decoration: underline; }
.app-shell { min-height: 100vh; }
.sidenav { position: fixed; inset: 0 auto 0 0; width: 248px; background: #fff; color: var(--ink); display: flex; flex-direction: column; z-index: 20; border-right: 1px solid var(--line); }
.sidenav .brand { display: flex; align-items: center; gap: 12px; padding: 22px 18px 18px; }
.sidenav .mark { width: 36px; height: 36px; border-radius: 10px; background: var(--blue); color: #fff; display: grid; place-items: center; font-size: 13px; font-weight: 700; letter-spacing: .02em; flex: none; }
.sidenav .brand strong { display: block; font-size: 15px; line-height: 1.2; }
.sidenav .brand small { display: block; margin-top: 2px; color: var(--muted); font-size: 12px; }
.sidenav nav { display: flex; flex-direction: column; gap: 4px; padding: 4px 12px; }
.sidenav a { color: #3d4d60; text-decoration: none; padding: 10px 12px; border-radius: 8px; font-size: 14px; font-weight: 600; }
.sidenav a:hover { background: #f4f7fb; color: var(--blue-dark); }
.sidenav a.active { background: #e7f0fa; color: var(--blue); }
.sidefoot { margin-top: auto; padding: 14px 16px 18px; border-top: 1px solid var(--line); }
.sidefoot span { display: block; font-size: 13px; font-weight: 600; margin-bottom: 8px; }
.sidefoot button { width: 100%; background: #fff; color: var(--ink); border: 1px solid var(--line); }
.sidefoot button:hover { background: #f4f7fb; border-color: var(--line-strong); color: var(--ink); }
.workspace { margin-left: 248px; min-height: 100vh; }
main { padding: 32px 36px 56px; }
h1 { margin: 0 0 18px; font-size: 28px; line-height: 1.2; font-weight: 600; letter-spacing: -.02em; color: var(--ink); }
.card { background: var(--paper); border: 1px solid var(--line); border-radius: 14px; padding: 22px; box-shadow: 0 8px 24px rgba(21, 50, 84, .04); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.stat { background: var(--paper); border-radius: 14px; padding: 16px 18px; border: 1px solid var(--line); box-shadow: 0 8px 24px rgba(21, 50, 84, .04); }
.stat b { display: block; font-size: 28px; color: var(--blue); letter-spacing: -.02em; }
.toolbar { display: flex; justify-content: space-between; gap: 12px; align-items: center; margin-bottom: 16px; }
table.data { width: 100%; border-collapse: collapse; background: var(--paper); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; box-shadow: 0 8px 24px rgba(21, 50, 84, .04); }
table.data th, table.data td { text-align: left; padding: 13px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.data th { background: #f7fafc; color: var(--muted); font-size: 12px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
table.data tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover td { background: #f8fbfe; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.banner { padding: 10px 12px; border-radius: 8px; margin-bottom: 12px; white-space: pre-line; }
.is-required > .doc-label::after,
label.checkline.is-required::after { content: " *"; color: var(--red); }
.field-invalid { outline: 2px solid var(--red); outline-offset: 4px; background: #fff6f5; border-radius: 6px; }
.field-error { color: var(--red); font-size: 13px; font-weight: 600; margin: 4px 0 8px; }
.banner.err { background: var(--err); color: var(--red); }
.banner.ok { background: var(--ok); color: var(--green); }
.tag { display: inline-block; padding: 2px 8px; border-radius: 99px; background: #e8eef6; color: var(--blue); font-size: 12px; }
.tag.draft { background: #fff6e5; color: var(--yellow); }
.tag.submitted { background: var(--ok); color: var(--green); }
.builder-tabs { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.builder-tabs button { background: #fff; color: var(--ink); border: 1px solid var(--line); }
.builder-tabs button.active { background: var(--blue); color: #fff; border-color: var(--blue); }
.builder-build { display: grid; grid-template-columns: 210px minmax(0, 1fr) 320px; gap: 16px; align-items: start; }
.builder-simple { max-width: 760px; }
.panel { background: var(--paper); border: 1px solid var(--line); border-radius: 14px; padding: 16px; box-shadow: 0 8px 24px rgba(21, 50, 84, .04); }
.panel h2 { margin: 0 0 8px; font-size: 16px; color: var(--ink); }
.panel .lead { margin: 0 0 12px; color: var(--muted); font-size: 14px; }
.page-tab { display: block; width: 100%; text-align: left; margin-bottom: 6px; background: #f6f9fc; color: var(--ink); border: 1px solid var(--line); }
.page-tab.active { border-color: var(--blue); background: #e7f0fa; color: var(--blue-dark); }
.palette { display: flex; flex-direction: column; gap: 8px; margin: 8px 0 14px; }
.palette-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.palette-row strong { width: 92px; font-size: 12px; color: var(--muted); font-weight: 600; }
button.chip { background: #f6f9fc; color: var(--ink); border: 1px solid var(--line); padding: 5px 8px; font-size: 13px; }
button.chip:hover { border-color: var(--blue); color: var(--blue); }
.field-line { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px; align-items: center; margin-bottom: 6px; }
.field-line.nested { margin-left: 22px; }
button.field-card { display: flex; gap: 8px; align-items: center; width: 100%; text-align: left; background: #fff; color: var(--ink); border: 1px solid var(--line); }
button.field-card.active { border-color: var(--blue); background: #e7f0fa; }
button.field-card .badge { flex: none; font-size: 11px; color: var(--blue); background: #e8f1fb; border-radius: 99px; padding: 2px 8px; }
button.icon-btn { background: #fff; color: var(--ink); border: 1px solid var(--line); padding: 6px 8px; }
.sheet { background: #fff; width: min(920px, 100%); margin: 0 auto; padding: 28px 32px 20px; box-shadow: 0 8px 24px rgba(16, 42, 67, .08); }
.sheet input, .sheet select, .sheet textarea { background: #fff; box-shadow: none; }
.sheet input:focus, .sheet select:focus, .sheet textarea:focus { background: #fff; box-shadow: none; }
.doc-kicker { display: flex; justify-content: space-between; gap: 16px; border-bottom: 1px solid var(--line); padding-bottom: 8px; font-size: 13px; color: #334155; }
.doc-kicker img { height: 48px; }
.doc-title { color: var(--blue); font-size: 26px; margin: 16px 0; }
.section { color: var(--blue); margin: 22px 0 8px; }
.section.h3 { font-size: 16px; }
.doc-label { font-weight: 700; margin: 12px 0 4px; }
.doc-help { color: var(--red); font-size: 13px; margin: 4px 0 8px; }
.checkline { display: flex; gap: 8px; align-items: flex-start; margin: 4px 0; }
.checkline input { width: auto; margin-top: 3px; }
.matrix { width: 100%; border-collapse: collapse; margin: 8px 0 12px; }
.matrix th, .matrix td { border: 1px solid #b7c3d0; padding: 6px; vertical-align: top; font-size: 14px; }
.matrix td { text-align: center; }
.matrix .matrix-name { text-align: left; font-weight: 600; }
.matrix-choice { display: inline-flex; align-items: center; justify-content: center; }
.matrix-choice input { width: 18px; height: 18px; }
.matrix-choice span { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); border: 0; }
.entries { display: flex; flex-direction: column; gap: 12px; }
.entry { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 16px; box-shadow: 0 8px 24px rgba(21, 50, 84, .04); }
.entry h2 { margin: 0 0 6px; font-size: 18px; line-height: 1.3; }
.entry p { margin: 0 0 4px; }
.entry .tag { margin-bottom: 8px; }
.entry-actions { display: flex; gap: 8px; margin-top: 12px; }
.entry-actions .btn, .entry-actions button { flex: 1; min-height: 44px; }
.fill-actions {display: flex; gap: 10px;}
@media (min-width: 861px) {
  .entry-actions .btn, .entry-actions button { flex: none; min-width: 140px; }
}
.matrix th { background: #f4f7fb; color: var(--blue); }
.sheet textarea { min-height: 90px; }
.sheet .line-input { border: 0; border-bottom: 1px solid #94a3b8; border-radius: 0; padding-left: 0; }
.signature { width: 100%; height: 140px; border: 1px solid var(--line); background: #fff; touch-action: none; }
.doc-footer { display: flex; justify-content: space-between; gap: 16px; margin-top: 28px; padding-top: 8px; border-top: 1px solid var(--line); font-size: 12px; color: #334155; }
.page-break { border-top: 2px dashed #d5dde6; margin: 28px 0; }
.preview { margin-top: 16px; }
.muted { color: var(--muted); }
.checks { display: flex; flex-direction: column; gap: 6px; max-height: 240px; overflow: auto; }
.builder-simple .checks { max-height: none; }
.checks label { display: flex; gap: 8px; align-items: center; }
.checks input { width: auto; }
@media (max-width: 1100px) {
  .builder-build, .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  #login .image { position: relative; width: 100%; height: 220px; }
  #login .image .brand { left: 24px; right: 24px; bottom: 24px; }
  #login .image .brand h2 { font-size: 22px; line-height: 28px; }
  #login .form { margin-left: 0; width: 100%; min-height: calc(100vh - 220px); }
  #login .form form { position: relative; top: auto; left: auto; transform: none; margin: 0 auto; padding: 36px 0; }
  .sidenav { position: relative; width: 100%; min-height: 0; }
  .sidenav nav { flex-direction: row; flex-wrap: wrap; }
  .sidefoot { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
  .sidefoot span { margin: 0; }
  .sidefoot button { width: auto; }
  .workspace { margin-left: 0; }
  main { padding: 20px 16px 40px; }
  body.is-app { overflow-x: hidden; }
  body.is-app .sidenav {
    position: sticky;
    top: 0;
    z-index: 40;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "brand foot" "nav nav";
    width: 100%;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    box-shadow: 0 6px 16px rgba(21, 50, 84, .05);
  }
  body.is-app .sidenav .brand { grid-area: brand; padding: 10px 12px; min-width: 0; }
  body.is-app .sidenav .brand small { display: none; }
  body.is-app .sidenav .brand strong { white-space: nowrap; }
  body.is-app .sidenav nav { grid-area: nav; flex-direction: row; width: auto; padding: 0 8px 8px; }
  body.is-app .sidenav nav a { flex: 1; text-align: center; min-height: 44px; display: flex; align-items: center; justify-content: center; }
  body.is-app .sidefoot { grid-area: foot; border: 0; margin: 0; padding: 10px 12px; display: flex; align-items: center; gap: 8px; }
  body.is-app .sidefoot span { max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin: 0; }
  body.is-app .sidefoot button { width: auto; min-height: 40px; padding: 8px 10px; }
  body.is-app main { padding: 16px 12px 28px; }
  body.is-app h1 { font-size: 24px; }
  body.is-app .toolbar { align-items: stretch; flex-direction: column; }
  body.is-app .sheet { width: 100%; padding: 16px 14px 12px; border-radius: 12px; }
  body.is-app .doc-kicker, body.is-app .doc-footer { flex-direction: column; }
  body.is-app .doc-title { font-size: 22px; }
  body.is-app input, body.is-app select, body.is-app textarea { font-size: 16px; }
  body.is-app .checkline { min-height: 44px; align-items: center; font-size: 16px; }
  body.is-app .checkline input { width: 22px; height: 22px; flex: none; }
  body.is-app .matrix, body.is-app .matrix thead, body.is-app .matrix tbody, body.is-app .matrix tr, body.is-app .matrix td { display: block; width: 100%; }
  body.is-app .matrix thead { display: none; }
  body.is-app .matrix { border: 0; }
  body.is-app .matrix tr { border: 1px solid #b7c3d0; border-radius: 12px; margin: 0 0 12px; padding: 10px 12px; background: #fff; }
  body.is-app .matrix td { border: 0; text-align: left; padding: 6px 0; }
  body.is-app .matrix .matrix-name { font-weight: 700; color: var(--blue); padding-top: 0; }
  body.is-app .matrix td[data-label]::before { content: attr(data-label); display: block; margin-bottom: 4px; color: var(--muted); font-size: 12px; font-weight: 700; }
  body.is-app .matrix-choice { display: flex; justify-content: flex-start; gap: 10px; min-height: 44px; }
  body.is-app .matrix-choice input { width: 22px; height: 22px; flex: none; }
  body.is-app .matrix-choice span { position: static; width: auto; height: auto; margin: 0; overflow: visible; clip: auto; clip-path: none; }
  body.is-app .matrix td .secondary { width: 100%; min-height: 44px; }
  body.is-app .signature { height: 180px; }
  body.is-app main:has(.fill-actions) { padding-bottom: calc(92px + env(safe-area-inset-bottom)); }
  body.is-app .fill-actions {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    display: flex;
    gap: 8px;
    margin: 0;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
    background: #fff;
    border-top: 1px solid var(--line);
    box-shadow: 0 -8px 24px rgba(21, 50, 84, .06);
  }
  body.is-app .fill-actions button { flex: 1; min-height: 48px; }
}
@media print {
  body { background: #fff; }
  .sidenav, .toolbar, .no-print { display: none !important; }
  .workspace { margin-left: 0; }
  main { padding: 0; }
  .sheet { box-shadow: none; width: auto; }
}
