:root {
  color-scheme: light;
  --dark: #101720;
  --ink: #10213a;
  --muted: #4f6075;
  --paper: #f5f6f8;
  --surface: #fff;
  --line: #d9e1eb;
  --blue: #1354d5;
  --blue-soft: #eaf1ff;
  --danger: #9b2432;
  --radius: 10px;
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
  color: var(--ink);
  background: var(--paper);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; font-size: 15px; line-height: 1.5; }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: wait; opacity: .65; }
:focus-visible { outline: 3px solid #6092ee; outline-offset: 2px; }
h1, h2, p { margin: 0; }
h1 { font-size: clamp(1.65rem, 3.3vw, 2.55rem); line-height: 1.12; letter-spacing: -.035em; font-weight: 650; }
h2 { font-size: clamp(1.125rem, 2.2vw, 1.38rem); line-height: 1.25; letter-spacing: -.02em; }
small, .muted, .hint { color: var(--muted); }
.hint { font-size: .86rem; }

.masthead { background: var(--dark); color: #f3f6fd; }
.header-inner, .workspace { width: min(100% - 48px, 1320px); margin-inline: auto; }
.header-inner, .brand, .session { display: flex; align-items: center; }
.header-inner { min-height: 76px; justify-content: space-between; gap: 14px; }
.brand { gap: 18px; }
.brand img { width: clamp(105px, 14vw, 155px); height: auto; display: block; }
.brand span { padding-left: 18px; border-left: 1px solid #495463; color: #c5cfdf; font-size: .85rem; }
.session { gap: 14px; }
.session strong, .session small { display: block; }
.session small { color: #c5cfdf; }

.workspace { padding-bottom: 48px; }
.navigation { display: flex; flex-wrap: wrap; gap: 6px 20px; border-bottom: 1px solid var(--line); margin-bottom: 30px; }
.nav-item { min-height: 48px; background: none; border: 0; border-bottom: 2px solid transparent; padding: 0 4px; font-weight: 600; text-align: left; color: var(--muted); }
.nav-item:hover, .nav-item[aria-current] { color: var(--blue); }
.nav-item[aria-current] { border-color: var(--blue); }
.section-head, .actions, .dialog-head, .preview-tools { display: flex; align-items: center; gap: 10px; }
.section-head { justify-content: space-between; flex-wrap: wrap; gap: 18px; margin-bottom: 22px; }
.actions { justify-content: flex-end; flex-wrap: wrap; }
.button { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 8px 14px; font-weight: 600; color: var(--ink); border: 1px solid var(--line); background: #fff; border-radius: 8px; }
.button:hover { border-color: #9bb6e2; background: var(--blue-soft); }
.primary { color: #fff; background: var(--blue); border-color: var(--blue); }
.primary:hover { background: #1046b1; border-color: #1046b1; }
.inverse { background: transparent; color: #f3f6fd; border-color: #526072; }
.inverse:hover { background: #233043; }
.close { min-width: 44px; font-size: 1.4rem; line-height: 1; }

.panel, .document { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.access { width: min(100% - 48px, 930px); margin: clamp(38px, 10vw, 124px) auto 36px; display: grid; grid-template-columns: 1fr minmax(0, 400px); gap: clamp(24px, 6vw, 76px); align-items: start; }
.access-intro p { margin-top: 14px; color: var(--muted); }
.access-card { padding: clamp(18px, 4vw, 30px); box-shadow: 0 12px 32px #16304e0b; }
.access-card form { display: grid; gap: 14px; }
.access-card h2 { margin-bottom: 6px; }

.filters { display: grid; grid-template-columns: minmax(0, 360px) minmax(175px, 225px); gap: 14px; padding: 16px 20px; }
label { display: grid; min-width: 0; gap: 6px; color: var(--ink); font-weight: 575; font-size: .9rem; }
input, textarea, select { width: 100%; min-width: 0; min-height: 44px; padding: 9px 10px; border-radius: 7px; border: 1px solid #b9c6d7; background: white; color: var(--ink); font-weight: 400; font-size: 1rem; }
textarea { resize: vertical; }
input::placeholder { color: #607084; }
.empty { min-height: 180px; display: grid; justify-items: center; align-content: center; gap: 12px; border-top: 1px solid var(--line); text-align: center; color: var(--muted); padding: 20px; }
.empty strong { font-size: 1.02rem; color: var(--ink); }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
thead { background: #f2f5fa; }
th, td { text-align: left; padding: 13px 14px; border-top: 1px solid var(--line); overflow-wrap: anywhere; }
th { font-size: .82rem; color: var(--muted); }
td small { display: block; }
.text-button { border: 0; background: none; color: var(--blue); padding: 4px 0; min-height: 44px; font-weight: 650; text-align: left; }
.text-button:hover { text-decoration: underline; }
.badge { display: inline-block; background: #edf0f4; border-radius: 5px; padding: 4px 8px; font-size: .8rem; color: #34435a; font-weight: 600; }
.badge.sent, .badge.pending { background: #edf3ff; color: #254f9b; }
.badge.active, .badge.done { background: #e7f4ee; color: #155a39; }
.badge.review, .badge.expired { background: #fbf1db; color: #735015; }
.badge.revoked { background: #f9e9eb; color: var(--danger); }
.notice, .error { border-radius: 7px; padding: 9px 12px; overflow-wrap: anywhere; }
.notice { background: #e7f4ee; color: #155a39; margin: 0 0 14px; }
.error { background: #f9e9eb; color: var(--danger); }
#workspace-error { margin-bottom: 14px; }

dialog { width: min(760px, 100% - 36px); max-height: calc(100dvh - 36px); border: 1px solid var(--line); border-radius: 14px; padding: clamp(14px, 3vw, 24px); color: var(--ink); box-shadow: 0 16px 65px #111b3155; }
dialog::backdrop { background: #0a142582; }
dialog.wide { width: min(970px, 100% - 36px); }
#invite-dialog { width: min(510px, 100% - 36px); }
.dialog-head { justify-content: space-between; margin-bottom: 18px; }
.split { display: grid; grid-template-columns: 190px minmax(0, 1fr); gap: 20px; }
.template-picker { border-right: 1px solid var(--line); padding-right: 16px; }
#template-list, dialog form, #invite-result { display: grid; gap: 13px; }
#template-list { gap: 6px; margin-top: 12px; }
.template-choice { width: 100%; text-align: left; min-height: 44px; padding: 8px; border: 1px solid transparent; border-radius: 7px; color: var(--ink); background: #f3f5f9; overflow-wrap: anywhere; }
.template-choice:hover, .template-choice[aria-pressed="true"] { background: var(--blue-soft); border-color: #a4bdf0; color: var(--blue); }
.field-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.template-summary { align-self: end; display: grid; overflow-wrap: anywhere; padding: 4px 0; }
fieldset { margin: 0; padding: 12px; min-width: 0; border: 1px solid var(--line); border-radius: 8px; }
legend { padding-inline: 4px; font-weight: 650; }
.quote-item { display: grid; grid-template-columns: minmax(0, 1fr) 85px 132px 132px auto; gap: 9px; align-items: end; padding-bottom: 12px; }
.quote-item + .quote-item { border-top: 1px solid var(--line); padding-top: 12px; }
.totals { display: flex; flex-wrap: wrap; gap: 8px 22px; justify-content: flex-end; color: var(--muted); }
.totals strong { color: var(--ink); margin-left: 5px; }
.preview-tools { justify-content: space-between; align-items: end; flex-wrap: wrap; margin: 0 0 14px; }
.document { padding: clamp(13px, 3vw, 30px); color: #152238; overflow-wrap: anywhere; }
.document header { border-bottom: 1px solid var(--line); padding-bottom: 12px; margin-bottom: 18px; }
.document.brand-layout header { border-top: 3px solid var(--blue); padding-top: 12px; color: var(--blue); }
.document h3 { margin: 0 0 12px; font-size: 1.2rem; }
.document .items-preview { margin: 14px 0; }
.document th, .document td { padding-inline: 6px; }
.document .amount { text-align: right; margin-bottom: 15px; }
.preserve-lines { white-space: pre-wrap; }
.signature { padding-top: 16px; }

@media (max-width: 780px) {
  .quote-item { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .quote-item label:first-child { grid-column: 1 / -1; }
  .quote-item .button { grid-column: 1 / -1; justify-self: end; }
  .records :is(table, tbody, tr, td) { display: block; }
  .records thead { clip-path: inset(50%); position: absolute; width: 1px; height: 1px; overflow: hidden; }
  .records tr { border-top: 1px solid var(--line); padding: 10px 14px; }
  .records td { border: 0; padding: 4px 0; display: grid; grid-template-columns: minmax(90px, 35%) minmax(0, 1fr); gap: 10px; align-items: start; }
  .records td::before { content: attr(data-label); color: var(--muted); font-size: .85rem; }
  .records td[data-label=""]::before { content: none; }
  .records td[data-label=""] { display: block; }
  .records td .badge { justify-self: start; }
  .records td .text-button { min-height: 40px; margin: 0; }
}

@media (max-width: 620px) {
  .header-inner, .workspace, .access { width: calc(100% - 30px); }
  .brand span, .session div { display: none; }
  .header-inner { min-height: 62px; }
  .access, .split, .field-grid { grid-template-columns: 1fr; }
  .template-picker { border: 0; border-bottom: 1px solid var(--line); padding: 0 0 12px; }
  .filters { grid-template-columns: 1fr; padding: 12px; }
  .navigation { gap: 0 13px; margin-bottom: 20px; }
  .nav-item { font-size: .84rem; }
  .section-head .actions { justify-content: flex-start; }
  .document :is(th, td) { font-size: .76rem; padding: 6px 2px; }
}

@media print {
  @page { margin: 16mm; }
  body { background: #fff; }
  body > :not(#preview-dialog), #preview-dialog > :not(#document) { display: none !important; }
  #preview-dialog { display: block; position: static; width: 100%; max-width: none; max-height: none; margin: 0; padding: 0; border: 0; box-shadow: none; overflow: visible; }
  #preview-dialog::backdrop { display: none; }
  .document { padding: 0; border: 0; }
  .document thead { display: table-header-group; }
  .document tr { break-inside: avoid; }
}
