:root {
  --bg: #f4f5f2;
  --paper: #ffffff;
  --ink: #191917;
  --muted: #6f716b;
  --line: #d9dbd4;
  --soft: #eceee8;
  --soft-2: #e5ece8;
  --red: #a82424;
  --red-dark: #7e1c1c;
  --teal: #167c78;
  --amber: #b16b15;
  --shadow: 0 18px 45px rgba(25, 25, 23, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.topbar {
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 14px 22px;
  background: rgba(255, 255, 255, 0.88);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(14px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-logo {
  width: clamp(96px, 9vw, 132px);
  max-height: 46px;
  height: auto;
  display: block;
  flex: 0 0 auto;
  object-fit: contain;
}

.brand-title {
  font-weight: 780;
  letter-spacing: 0;
  white-space: nowrap;
}

.brand-subtitle,
.eyebrow,
.field-label,
.pill,
.status,
.mini-link,
.client-meta,
.archive-meta,
.template-meta {
  color: var(--muted);
  font-size: 12px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.pill {
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--soft);
  white-space: nowrap;
}

.workspace {
  display: grid;
  grid-template-columns: 288px minmax(430px, 1fr) 390px;
  gap: 16px;
  padding: 16px;
  min-height: calc(100vh - 72px);
}

.rail,
.side,
.command {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

.panel {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.compact {
  padding: 14px;
}

.hero-panel,
.result-panel,
.preview-panel,
.statement-panel,
.archive-panel,
.finance-panel,
.audit-panel {
  padding: 16px;
}

.operator-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 16px;
}

.operator-strip div {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  column-gap: 9px;
  row-gap: 1px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfbf8;
  padding: 9px;
}

.operator-strip span {
  grid-row: 1 / 3;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: var(--red);
  color: #fff;
  font-weight: 800;
  font-size: 12px;
}

.operator-strip strong {
  font-size: 13px;
  letter-spacing: 0;
}

.operator-strip small,
.command-subtitle {
  color: var(--muted);
}

.operator-strip small {
  font-size: 11px;
  overflow-wrap: anywhere;
}

.panel-head,
.command-head,
.command-actions,
.dialog-head,
.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  flex-wrap: wrap;
}

.mini-count {
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

.panel-head h2,
.dialog-head h2 {
  margin: 0;
  font-size: 14px;
  letter-spacing: 0;
}

.command-head {
  align-items: flex-start;
  margin-bottom: 16px;
}

.command-head h1 {
  margin: 4px 0 0;
  max-width: 620px;
  font-size: clamp(26px, 3vw, 38px);
  line-height: 1.02;
  letter-spacing: 0;
}

.command-subtitle {
  margin: 8px 0 0;
  max-width: 620px;
  font-size: 14px;
  line-height: 1.35;
}

.active-client {
  padding: 9px 11px;
  border-radius: 8px;
  background: var(--soft-2);
  color: #1d4f4c;
  font-weight: 700;
  white-space: nowrap;
  max-width: 230px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.client-list,
.template-list,
.archive-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
  max-height: 39vh;
  overflow: auto;
}

.client-item,
.template-item,
.archive-item {
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  background: #fbfbf8;
  border-radius: 8px;
  padding: 10px;
}

.client-item:hover,
.template-item:hover,
.archive-item:hover {
  border-color: #b8bcae;
}

.client-item.active,
.template-item.active,
.archive-item.selected {
  border-color: rgba(168, 36, 36, 0.55);
  background: #fff7f5;
}

.archive-select-row {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  gap: 8px;
  align-items: start;
}

.archive-select-row input {
  width: auto;
  min-height: auto;
  margin-top: 2px;
}

.client-name,
.archive-title,
.template-title {
  font-weight: 760;
  letter-spacing: 0;
  overflow-wrap: anywhere;
}

.client-meta,
.archive-meta,
.template-meta {
  margin-top: 4px;
  line-height: 1.35;
}

.doc-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  margin: 12px 0 16px;
}

.doc-type {
  border: 1px solid var(--line);
  background: #fbfbf8;
  border-radius: 8px;
  min-height: 62px;
  padding: 10px;
  text-align: left;
  font-weight: 720;
}

.doc-type span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  margin-top: 3px;
  font-weight: 500;
}

.doc-type.active {
  border-color: var(--red);
  background: #fff2ef;
  color: var(--red-dark);
}

.field-label {
  display: block;
  margin: 12px 0 6px;
  font-weight: 700;
}

textarea,
input,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  outline: none;
}

textarea {
  resize: vertical;
  min-height: 160px;
  padding: 13px 14px;
  line-height: 1.45;
}

input,
select {
  min-height: 42px;
  padding: 9px 10px;
}

textarea:focus,
input:focus,
select:focus {
  border-color: rgba(22, 124, 120, 0.75);
  box-shadow: 0 0 0 3px rgba(22, 124, 120, 0.12);
}

.input-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 260px;
  gap: 12px;
  margin-top: 12px;
}

.file-zone {
  min-height: 156px;
  border: 1px dashed #b9bdaa;
  border-radius: 8px;
  background: #fbfbf8;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 18px;
  text-align: center;
}

.file-zone input {
  display: none;
}

.file-zone span {
  font-weight: 760;
}

.file-zone strong {
  color: var(--teal);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.ai-box {
  display: grid;
  gap: 8px;
  align-content: start;
}

.advanced-box {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfbf8;
  padding: 11px;
}

.advanced-box summary {
  cursor: pointer;
  font-weight: 760;
}

.advanced-box .field-label {
  margin-top: 10px;
}

.command-actions {
  margin-top: 14px;
  justify-content: flex-start;
}

.status {
  margin-left: auto;
  min-width: 160px;
  text-align: right;
}

.status.busy {
  color: var(--amber);
}

.status.ok {
  color: var(--teal);
}

.status.error {
  color: var(--red);
}

.primary-btn,
.secondary-btn,
.ghost-btn,
.tiny-btn,
.icon-btn {
  border-radius: 8px;
  min-height: 38px;
  border: 1px solid transparent;
  font-weight: 760;
}

.primary-btn {
  background: var(--red);
  color: white;
  padding: 0 16px;
}

.primary-btn:hover {
  background: var(--red-dark);
}

.secondary-btn {
  width: 100%;
  margin-top: 10px;
  background: var(--teal);
  color: white;
  padding: 0 14px;
}

.ghost-btn {
  background: #fff;
  border-color: var(--line);
  color: var(--ink);
  padding: 0 12px;
}

.full-btn {
  width: 100%;
  margin-top: 8px;
}

.tiny-btn {
  min-height: 28px;
  padding: 0 8px;
  background: var(--soft);
  border-color: var(--line);
  color: var(--muted);
  font-size: 12px;
}

.tiny-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.danger-btn {
  color: var(--red);
  border-color: rgba(168, 36, 36, 0.35);
  background: #fff7f5;
}

.icon-btn {
  width: 34px;
  height: 34px;
  background: #fff;
  border-color: var(--line);
  font-size: 22px;
  line-height: 1;
}

.result-panel {
  min-height: 210px;
}

.result-empty {
  color: var(--muted);
  padding: 22px 0 4px;
}

.file-links {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.file-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px;
  background: #fbfbf8;
}

.file-card strong {
  display: block;
  margin-bottom: 8px;
}

.file-card a,
.mini-link,
.primary-link {
  color: var(--red-dark);
  font-weight: 760;
  text-decoration: none;
}

.primary-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  margin-top: 14px;
  padding: 0 14px;
  border-radius: 8px;
  background: var(--red);
  color: #fff;
}

.nas-steps {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.nas-steps div {
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fbfbf8;
}

.nas-steps strong {
  width: 32px;
  height: 32px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: var(--soft-2);
  color: #1d4f4c;
}

code {
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 0.95em;
}

.email-box {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fcfcfa;
  padding: 12px;
  white-space: pre-wrap;
  font-size: 13px;
  line-height: 1.45;
}

.preview-panel {
  min-height: 370px;
}

#pdf-preview {
  width: 100%;
  height: 315px;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-top: 12px;
  background: var(--soft);
}

.date-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
}

.archive-list {
  max-height: 35vh;
}

.audit-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
  max-height: 28vh;
  overflow: auto;
}

.audit-item {
  border-left: 3px solid var(--teal);
  background: #fbfbf8;
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 12px;
}

.audit-item strong {
  display: block;
  font-size: 13px;
}

.profile-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}

.profile-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fbfbf8;
}

.finance-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
}

.metric {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfbf8;
  padding: 10px;
  min-height: 64px;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 11px;
}

.metric strong {
  display: block;
  margin-top: 4px;
  font-size: 16px;
  letter-spacing: 0;
}

.status-select {
  width: auto;
  min-height: 30px;
  margin-top: 8px;
  padding: 4px 8px;
  font-size: 12px;
}

.archive-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.pay-link {
  border: 0;
  background: transparent;
  color: var(--teal);
  font-weight: 760;
  padding: 0;
}

.pill.due {
  background: #fff4e5;
  color: #8b4b08;
  border-color: #e7c486;
}

.pill.good {
  background: #eaf5ef;
  color: #126047;
  border-color: #a8d7c2;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 13px;
}

.check-row input {
  width: auto;
  min-height: auto;
}

.login-form {
  max-width: 420px;
}

.login-note {
  color: var(--muted);
  margin: 8px 0 14px;
}

dialog {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  max-width: 720px;
  width: calc(100vw - 28px);
  box-shadow: 0 30px 80px rgba(20, 20, 18, 0.24);
}

dialog::backdrop {
  background: rgba(20, 20, 18, 0.4);
}

.client-form {
  padding: 18px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 14px 0 10px;
}

.dialog-actions {
  margin-top: 12px;
  justify-content: flex-end;
}

@media (max-width: 1180px) {
  .workspace {
    grid-template-columns: 260px minmax(0, 1fr);
  }

  .side {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 820px) {
  .topbar {
    height: auto;
    align-items: flex-start;
    flex-direction: column;
  }

  .workspace,
  .side {
    grid-template-columns: 1fr;
  }

  .doc-grid,
  .input-row,
  .form-grid,
  .operator-strip {
    grid-template-columns: 1fr;
  }

  .command-head,
  .command-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .status {
    margin-left: 0;
    text-align: left;
  }
}
