* {
  box-sizing: border-box;
}

:root {
  --bg: #f1f7fb;
  --bg-soft: #e7f1f8;
  --card: #ffffff;
  --text: #0f2233;
  --muted: #5b6d7c;
  --line: #d7e4ee;
  --accent: #0d7b8f;
  --accent-soft: #dff4f8;
  --danger: #b42318;
  --danger-soft: #fff3f1;
  --shadow: 0 12px 34px rgba(9, 28, 41, 0.09);
  --radius-xl: 22px;
  --radius-lg: 16px;
  --radius-sm: 10px;
}

body {
  margin: 0;
  color: var(--text);
  font-family: "Poppins", "Segoe UI", "Tahoma", sans-serif;
  background:
    radial-gradient(circle at 0% 0%, #dceff7 0, transparent 34%),
    radial-gradient(circle at 100% 0%, #dff7ee 0, transparent 30%),
    linear-gradient(180deg, #edf5fb 0, var(--bg) 42%, #f6fbff 100%);
}

h1,
h2,
h3,
h4,
p {
  margin: 0;
}

.page-shell {
  max-width: 1480px;
  margin: 0 auto;
  padding: 24px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow);
}

.topbar {
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: 18px;
  padding: 22px;
  margin-bottom: 18px;
}

.kicker {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 8px;
}

h1 {
  font-size: 34px;
  line-height: 1.1;
  margin-bottom: 8px;
}

.subtitle,
.muted {
  color: var(--muted);
}

.topbar-actions {
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
}

.auth-box {
  border: 1px solid #cce7f0;
  background: linear-gradient(180deg, #f7fbff, #e9f4fb);
  border-radius: var(--radius-lg);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.auth-box span {
  color: var(--muted);
  font-size: 12px;
}

.auth-logout {
  min-width: 220px;
}

.error-banner {
  margin-bottom: 18px;
  padding: 16px;
  border-color: #ffd2ce;
  background: var(--danger-soft);
}

.error-banner h2 {
  margin-bottom: 6px;
  color: var(--danger);
}

.error-banner p {
  color: #8e1e15;
  margin-bottom: 10px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(320px, 0.9fr);
  gap: 18px;
  align-items: start;
}

.workspace.invoices-layout {
  grid-template-columns: 1fr;
}

.form-panel {
  padding: 18px;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.head-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.switch-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
  background: #fff;
  font-size: 13px;
  font-weight: 600;
}

.switch-row input {
  width: 15px;
  height: 15px;
}

.muted-card {
  background: linear-gradient(180deg, #f6fbfe, #eef8fc);
  border-color: #cae4ef;
}

.compact-block {
  padding: 14px;
  margin-bottom: 14px;
}

.scenario-strip {
  display: grid;
  grid-template-columns: auto auto 1fr;
  gap: 12px;
  align-items: center;
}

.scenario-pill,
.calc-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border-radius: 999px;
  padding: 8px 12px;
  background: #ffffff;
  border: 1px solid #bfdeea;
  font-size: 13px;
}

.scenario-pill strong {
  color: var(--accent);
}

.progress-wrap {
  background: #ffffff;
  border: 1px solid #c8deea;
  border-radius: 14px;
  padding: 8px 10px;
}

.progress-meta {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 7px;
}

.progress-meta strong {
  color: var(--accent);
}

.progress-track {
  height: 10px;
  border-radius: 999px;
  background: #deecf4;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, #0d7b8f, #1ca2b9);
  transition: width 0.2s ease;
}

.field-grid {
  display: grid;
  gap: 12px;
  margin-bottom: 12px;
}

.field-grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.field-grid.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.field-grid.four {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.label-text {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: #365066;
}

.field.required .label-text::after {
  content: "Required";
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 999px;
  padding: 3px 8px;
}

.field.optional .label-text::after {
  content: "Optional";
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
  color: #6b7580;
  background: #edf2f5;
  border-radius: 999px;
  padding: 3px 8px;
}

input,
select,
textarea,
button {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-family: inherit;
  color: var(--text);
  background: #fff;
}

input,
select,
textarea {
  padding: 10px 11px;
  font-size: 14px;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: #1ca2b9;
  box-shadow: 0 0 0 3px rgba(28, 162, 185, 0.14);
}

.field.required input,
.field.required select,
.field.required textarea {
  border-color: #9bcdd9;
  background: #fbfeff;
}

.scenario-guide {
  padding: 14px;
  margin: 12px 0;
}

.block-head,
.section-title,
.item-head,
.form-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.block-head {
  margin-bottom: 10px;
}

.hint-list {
  margin: 0 0 8px 18px;
  color: #365066;
  padding: 0;
}

.hint-list li {
  margin-bottom: 4px;
}

.requirement-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 10px;
}

.mini-title {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 7px;
}

.chip-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.chip {
  border: 1px solid #c8e1eb;
  background: #ffffff;
  border-radius: 999px;
  padding: 5px 9px;
  font-size: 12px;
  color: #235066;
  font-weight: 600;
}

.section-block {
  border-top: 1px dashed #d3e2eb;
  padding-top: 14px;
  margin-top: 14px;
}

.section-title {
  margin-bottom: 10px;
}

.item-card {
  border: 1px solid #d4e6ee;
  border-radius: 16px;
  background: linear-gradient(180deg, #fcfeff, #f5fafc);
  padding: 14px;
  margin-bottom: 12px;
}

.item-head h4 {
  font-size: 17px;
  margin-bottom: 3px;
}

.item-summary {
  border: 1px solid #d2e7ef;
  border-radius: 12px;
  background: #ffffff;
  padding: 10px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  align-items: center;
}

.item-summary span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.item-summary strong {
  font-size: 15px;
}

.btn {
  border: none;
  cursor: pointer;
  border-radius: 10px;
  padding: 10px 13px;
  font-size: 13px;
  font-weight: 600;
}

.btn.primary {
  background: var(--accent);
  color: #fff;
}

.btn.secondary {
  background: #e6f4f8;
  color: #0f5f72;
  border: 1px solid #bfe0ea;
}

.btn.ghost {
  background: #f0f5f8;
  color: #496071;
  border: 1px solid #d5e2ea;
}

.btn:hover {
  opacity: 0.94;
}

.form-actions {
  margin-top: 14px;
}

.validation-box {
  border-radius: 14px;
  border: 1px solid #ffd2ce;
  background: #fff6f5;
  color: #9a251a;
  padding: 12px;
}

.validation-box h4 {
  margin-bottom: 6px;
}

.validation-box ul {
  margin: 0 0 0 18px;
  padding: 0;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.side-card {
  padding: 14px;
  position: static;
}

.scenario-list,
.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.scenario-list-item,
.history-item {
  border: 1px solid #dae8f0;
  border-radius: 12px;
  padding: 10px;
  background: #fff;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
}

.scenario-list-item.active {
  border-color: #9ecfdd;
  background: #eef9fc;
}

.inspector-card {
  padding: 0;
  overflow: hidden;
}

.inspector-head {
  padding: 14px 14px 12px;
  border-bottom: 1px solid #d8e8f0;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

.inspector-head h3 {
  margin-bottom: 4px;
}

.inspector-head .muted {
  font-size: 12px;
}

.mini-btn {
  padding: 7px 10px;
  font-size: 12px;
}

.json-shell {
  max-height: 340px;
  overflow: auto;
  background: linear-gradient(180deg, #132739, #0f2233);
}

.json-box {
  margin: 0;
  padding: 14px;
  color: #d7e8ff;
  font-size: 12px;
  line-height: 1.45;
  white-space: pre;
}

.history-card {
  padding: 0;
  overflow: hidden;
}

.history-card .history-list {
  padding: 12px 14px 14px;
}

.history-empty {
  border: 1px dashed #c8dbe6;
  border-radius: 12px;
  padding: 12px;
  text-align: center;
  color: var(--muted);
  background: #f9fcfe;
}

.history-item {
  border-color: #d2e4ec;
  padding: 12px;
  gap: 7px;
}

.history-top,
.history-meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
}

.history-action {
  display: inline-flex;
  align-items: center;
  padding: 4px 8px;
  border-radius: 999px;
  background: #edf7fc;
  color: #1b5268;
  font-weight: 600;
  font-size: 12px;
}

.history-status {
  display: inline-flex;
  align-items: center;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid #d2dee6;
  color: #506170;
  background: #f4f7fa;
}

.history-status[data-state="success"] {
  border-color: #bde7cf;
  color: #176240;
  background: #e8f9f0;
}

.history-status[data-state="error"] {
  border-color: #ffd4d0;
  color: #9d261c;
  background: #fff0ee;
}

.history-meta {
  color: var(--muted);
  font-size: 12px;
}

.history-meta strong {
  color: #2c4357;
}

.history-time {
  color: #5a7082;
}

.history-log code {
  display: block;
  border: 1px dashed #c6d9e3;
  border-radius: 8px;
  padding: 7px 8px;
  background: #f8fcff;
  color: #36566a;
  font-size: 11px;
}

.invoices-card {
  padding: 0;
  overflow: hidden;
}

.invoices-head {
  padding: 14px 16px 12px;
  border-bottom: 1px solid #d8e8f0;
}

.invoices-head h3 {
  margin-bottom: 4px;
}

.table-wrap {
  overflow: auto;
}

.invoices-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 860px;
  font-size: 13px;
}

.invoices-table th {
  text-align: left;
  padding: 12px 14px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #4f6678;
  background: #f3f9fc;
  border-bottom: 1px solid #d7e7ef;
}

.invoices-table td {
  padding: 12px 14px;
  border-bottom: 1px solid #e3edf3;
  vertical-align: top;
}

.invoices-table tbody tr:hover {
  background: #f8fcff;
}

.empty-cell {
  text-align: center;
  color: var(--muted);
  padding: 18px 14px !important;
}

.time-cell {
  white-space: nowrap;
  color: #556d80;
}

.log-cell code {
  display: inline-block;
  max-width: 420px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  border: 1px dashed #c6d9e3;
  border-radius: 8px;
  padding: 6px 8px;
  background: #f8fcff;
  color: #36566a;
  font-size: 11px;
}

.log-cell {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.log-link-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.log-link {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  text-decoration: none;
  border: 1px solid #c4dce7;
  background: #eef8fc;
  color: #1c556a;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
}

.log-link:hover {
  background: #e4f2f8;
}

.log-view-shell {
  min-height: 100vh;
  padding: 24px;
}

.log-view-card {
  max-width: 1320px;
  margin: 0 auto;
  padding: 18px;
}

.log-view-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: flex-start;
  margin-bottom: 12px;
}

.log-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.log-view-head h1 {
  margin-bottom: 6px;
}

.log-summary-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.log-summary-item {
  border: 1px solid #d5e5ee;
  border-radius: 12px;
  padding: 10px;
  background: #f8fcff;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.log-summary-item span {
  color: var(--muted);
  font-size: 12px;
}

.log-summary-item strong {
  color: #1f3f52;
  font-size: 13px;
  word-break: break-word;
}

.log-blocks {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.log-json-card {
  padding: 12px;
}

.log-json-card h3 {
  margin-bottom: 8px;
}

.json-box.light {
  background: #102332;
  color: #d6e8ff;
  border-radius: 12px;
  padding: 12px;
  max-height: 430px;
  overflow: auto;
  white-space: pre;
}

.invoice-page-shell {
  min-height: 100vh;
  padding: 24px;
}

.invoice-toolbar {
  max-width: 980px;
  margin: 0 auto 10px;
  display: flex;
  gap: 10px;
}

.invoice-paper {
  max-width: 980px;
  margin: 0 auto;
  background: #fff;
  border: 1px solid #d5e3ec;
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 10px 26px rgba(7, 22, 33, 0.08);
}

.invoice-branding {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  padding-bottom: 12px;
  margin-bottom: 8px;
  border-bottom: 1px solid #dbe8ef;
}

.invoice-logo {
  display: block;
  width: auto;
  object-fit: contain;
}

.invoice-logo-lt {
  height: 72px;
}

.invoice-logo-fbr {
  height: 84px;
}

.invoice-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.invoice-header h1 {
  margin-bottom: 4px;
}

.invoice-id-box {
  border: 1px solid #d7e6ee;
  border-radius: 12px;
  padding: 10px 12px;
  min-width: 300px;
  background: #f8fcff;
  display: grid;
  gap: 6px;
}

.invoice-id-box div {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 13px;
}

.invoice-id-box span {
  color: var(--muted);
}

.invoice-id-box strong {
  color: #1d4155;
}

.invoice-parties {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.party-card {
  border: 1px solid #d9e6ee;
  border-radius: 12px;
  padding: 12px;
  background: #fbfeff;
}

.party-card h3 {
  margin-bottom: 8px;
  font-size: 15px;
}

.party-card p {
  margin: 0 0 4px;
}

.tiny {
  font-size: 11px;
}

.invoice-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.invoice-table th,
.invoice-table td {
  border: 1px solid #dce8ef;
  padding: 8px;
  text-align: left;
  vertical-align: top;
}

.invoice-table th {
  background: #f1f8fc;
  color: #36556a;
}

.invoice-summary {
  display: flex;
  justify-content: flex-end;
  margin-top: 14px;
}

.summary-box {
  width: min(360px, 100%);
  border: 1px solid #d9e6ee;
  border-radius: 12px;
  overflow: hidden;
}

.summary-box > div {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 12px;
  border-bottom: 1px solid #e2ebf1;
  background: #fff;
}

.summary-box > div:last-child {
  border-bottom: none;
}

.summary-box .grand-total {
  background: #eaf6fb;
  font-size: 14px;
}

.summary-box span {
  color: #4d687a;
}

.summary-box strong {
  color: #10394d;
}

pre,
code {
  margin: 0;
  font-family: "Cascadia Mono", "Consolas", monospace;
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-word;
}

.hidden {
  display: none !important;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(440px, 100%);
  padding: 30px;
  border: 1px solid #cde0ea;
  box-shadow: 0 20px 42px rgba(9, 30, 42, 0.14);
  background: linear-gradient(180deg, #ffffff 0%, #f6fbfe 100%);
}

.login-card h1 {
  margin-bottom: 14px;
  font-size: 32px;
  line-height: 1.1;
  text-align: center;
}

.login-form {
  display: grid;
  gap: 14px;
  margin-top: 10px;
}

.login-error {
  border: 1px solid #ffd2ce;
  background: #fff6f5;
  color: #9a251a;
  border-radius: 12px;
  padding: 10px 11px;
  margin-bottom: 10px;
  text-align: center;
}

.login-trap {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

@media (max-width: 1280px) {
  .workspace,
  .topbar {
    grid-template-columns: 1fr;
  }

  .topbar-actions,
  .scenario-strip,
  .log-summary-grid,
  .invoice-parties,
  .requirement-grid,
  .field-grid.two,
  .field-grid.three,
  .field-grid.four,
  .item-summary {
    grid-template-columns: 1fr;
  }

  .panel-head,
  .head-actions,
  .block-head,
  .section-title,
  .item-head,
  .form-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .side-card {
    position: static;
  }

  .invoice-branding {
    flex-direction: column;
    align-items: flex-start;
  }
}

@media print {
  body {
    background: #fff !important;
  }

  .no-print {
    display: none !important;
  }

  .invoice-page-shell {
    padding: 0;
  }

  .invoice-paper {
    border: none;
    border-radius: 0;
    box-shadow: none;
    max-width: 100%;
    margin: 0;
    padding: 0;
  }

  .invoice-logo-lt {
    height: 54px;
  }

  .invoice-logo-fbr {
    height: 64px;
  }
}
