:root {
  --ink: #15201d;
  --muted: #68736d;
  --line: #dce3df;
  --page: #f7f8f5;
  --panel: #ffffff;
  --accent: #2f7d69;
  --blue: #356e9f;
  --gold: #c7922b;
  --bad: #a9473f;
  --shadow: 0 16px 40px rgba(21, 32, 29, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--page);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

a {
  color: var(--accent);
  text-decoration: none;
}

button,
.button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  padding: 0 16px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
}

button.secondary,
.button.secondary {
  background: #e8ede8;
  color: var(--ink);
}

button.ghost {
  width: 100%;
  background: transparent;
  border: 1px solid rgba(255,255,255,0.2);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 11px 12px;
  font: inherit;
}

input.readonly-field,
textarea.readonly-field {
  background: #f5f7f5;
  color: var(--muted);
}

textarea {
  resize: vertical;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

label input,
label select,
label textarea {
  color: var(--ink);
  font-size: 15px;
  font-weight: 500;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(28px, 3vw, 42px);
}

h2 {
  margin-bottom: 0;
  font-size: 19px;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 244px;
  background: var(--ink);
  color: #fff;
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: inherit;
  font-weight: 800;
  font-size: 18px;
}

.brand.large {
  color: var(--ink);
  font-size: 20px;
}

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: #f7f8f5;
  color: var(--ink);
  display: grid;
  place-items: center;
  font-weight: 900;
}

.nav {
  display: grid;
  gap: 4px;
}

.nav a {
  border-radius: 8px;
  color: rgba(255,255,255,0.78);
  padding: 11px 12px;
  font-weight: 700;
}

.nav a.active,
.nav a:hover {
  background: rgba(255,255,255,0.12);
  color: #fff;
}

.logout-form {
  margin-top: auto;
}

.main {
  margin-left: 244px;
  min-height: 100vh;
  padding: 30px;
}

.main.public {
  margin-left: 0;
  padding: 0;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  margin-bottom: 24px;
}

.eyebrow {
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
}

.account {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 10px;
  color: var(--muted);
  font-weight: 700;
}

.install-button {
  min-height: 34px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  padding: 0 12px;
  font-size: 13px;
}

.install-button:hover {
  border-color: #b8c4bd;
  background: #fdfdfb;
}

.status {
  border-radius: 999px;
  background: #edf1ee;
  color: var(--ink);
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 800;
  text-transform: capitalize;
}

.status.good {
  background: #dff1e9;
  color: #17614f;
}

.status.warn {
  background: #fff2cc;
  color: #76510c;
}

.alert {
  border-radius: 8px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  background: #fff;
}

.alert.good {
  border-color: #bde2d3;
  background: #eef9f3;
}

.alert.warn {
  border-color: #efd68c;
  background: #fff8df;
}

.alert.bad {
  border-color: #e2b6b1;
  background: #fff1ef;
  color: var(--bad);
}

.action-row,
.panel-head,
.split-block {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 18px;
}

.install-dialog {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(21, 32, 29, 0.48);
}

.install-dialog[hidden],
.install-button[hidden],
#install-action[hidden],
#download-action[hidden] {
  display: none;
}

.install-card {
  width: min(100%, 520px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 22px 60px rgba(21, 32, 29, 0.18);
  padding: 22px;
}

.install-head {
  align-items: flex-start;
  margin-bottom: 18px;
}

.compact-button {
  min-height: 34px;
  padding: 0 12px;
  font-size: 13px;
}

.install-copy {
  color: var(--ink);
  font-weight: 600;
}

.install-note {
  margin-bottom: 12px;
  color: var(--muted);
}

.install-steps {
  margin: 0;
  padding-left: 22px;
  color: var(--ink);
}

.install-steps li + li {
  margin-top: 8px;
}

.install-actions {
  margin-top: 18px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 18px;
}

.span-5 {
  grid-column: span 5;
}

.span-6 {
  grid-column: span 6;
}

.span-7 {
  grid-column: span 7;
}

.span-12 {
  grid-column: span 12;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.metric {
  border-radius: 8px;
  background: #fff;
  border: 1px solid var(--line);
  padding: 16px;
  min-height: 102px;
  display: grid;
  align-content: space-between;
}

.metric span,
.snapshot span,
.muted,
small {
  color: var(--muted);
}

.metric strong {
  font-size: 28px;
}

.snapshot {
  display: grid;
  gap: 12px;
  margin-top: 16px;
}

.snapshot-link {
  font-weight: 800;
}

.snapshot div,
.list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-top: 1px solid var(--line);
  padding: 13px 0;
}

.list-row:first-child {
  border-top: 0;
}

.list-row span:first-child {
  min-width: 0;
}

.list-row strong,
.list-row small {
  display: block;
  overflow-wrap: anywhere;
}

.empty {
  margin: 14px 0 0;
  color: var(--muted);
}

.stack {
  display: grid;
  gap: 14px;
}

.two-col {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(47, 125, 105, 0.18), transparent 42%),
    linear-gradient(315deg, rgba(199, 146, 43, 0.18), transparent 38%),
    var(--page);
}

.login-panel {
  width: min(440px, 100%);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 28px;
}

.login-panel h1 {
  margin: 18px 0 22px;
}

.step-list {
  display: grid;
  gap: 12px;
  margin: 18px 0;
}

.step {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  display: flex;
  gap: 12px;
  align-items: center;
}

.step > span {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: #edf1ee;
  display: grid;
  place-items: center;
  font-weight: 900;
}

.step.done > span {
  background: #dff1e9;
  color: #17614f;
}

.inline-form {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

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

.folder {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  font-weight: 800;
  background: #fbfcfa;
  display: grid;
  gap: 5px;
}

.folder small {
  font-weight: 600;
}

.folder-link {
  color: var(--ink);
}

.folder-link:hover {
  border-color: #b9d4ca;
  background: #f2f8f5;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 12px;
}

th,
td {
  border-top: 1px solid var(--line);
  padding: 12px 8px;
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

td small {
  display: block;
}

.number-cell {
  text-align: right;
  white-space: nowrap;
}

.finance-summary {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin: 18px 0;
}

.success-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.ticket-layout {
  display: grid;
  gap: 18px;
}

.ticket {
  margin-bottom: 0;
}

.thread {
  display: grid;
  gap: 10px;
  margin: 16px 0;
}

.message {
  border-radius: 8px;
  background: #f5f7f5;
  padding: 12px;
}

.message p {
  margin: 5px 0 8px;
}

.reply-form {
  display: grid;
  gap: 10px;
}

.admin-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.admin-tabs a {
  min-height: 40px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  padding: 0 14px;
  font-weight: 800;
}

.admin-tabs a.active,
.admin-tabs a:hover {
  border-color: #b9d4ca;
  background: #eaf4ef;
  color: #17614f;
}

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

.top-gap {
  margin-top: 16px;
}

.check-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink);
}

.check input {
  width: auto;
}

.folder-row {
  display: grid;
  grid-template-columns: 1.1fr 1.2fr 0.8fr 1fr 0.8fr auto;
  gap: 8px;
  align-items: center;
  border-top: 1px solid var(--line);
  padding: 10px 0;
}

.folder-row:first-child {
  border-top: 0;
}

.row-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.table-actions {
  min-width: 232px;
}

.row-actions form {
  margin: 0;
}

.small-button {
  min-height: 32px;
  padding: 0 10px;
  font-size: 12px;
}

.invoice-shell {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  margin-bottom: 18px;
  overflow: hidden;
}

.invoice-shell form {
  display: grid;
}

.invoice-form-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  padding: 26px 28px 20px;
  background: #fbfcfa;
  border-bottom: 1px solid var(--line);
}

.invoice-kind {
  margin-bottom: 8px;
  color: var(--ink);
  font-size: 15px;
  font-weight: 800;
}

.invoice-state {
  display: block;
  color: var(--ink);
  font-size: clamp(38px, 5vw, 62px);
  line-height: 0.95;
  letter-spacing: 0;
}

.invoice-header-grid {
  display: grid;
  grid-template-columns: minmax(340px, 1.1fr) minmax(420px, 1fr);
  gap: 30px;
  padding: 24px 28px 28px;
}

.invoice-customer {
  display: grid;
  align-content: start;
  gap: 14px;
}

.three-col {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.customer-detail-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

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

.invoice-tabs {
  display: flex;
  align-items: flex-end;
  gap: 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 0 28px;
  background: #f5f7f5;
}

.invoice-tabs span {
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  border-right: 1px solid var(--line);
  padding: 0 18px;
  color: var(--muted);
  font-weight: 800;
}

.invoice-tabs span:first-child {
  border-left: 1px solid var(--line);
}

.invoice-tabs .active {
  background: #fff;
  color: var(--accent);
  box-shadow: inset 0 3px 0 var(--accent);
}

.invoice-lines-wrap {
  overflow-x: auto;
}

.invoice-lines-table {
  min-width: 1060px;
  margin-top: 0;
}

.invoice-lines-table th,
.invoice-lines-table td {
  padding: 10px 8px;
}

.invoice-lines-table th:first-child,
.invoice-lines-table td:first-child {
  padding-left: 28px;
}

.invoice-lines-table th:last-child,
.invoice-lines-table td:last-child {
  padding-right: 28px;
}

.invoice-lines-table select,
.invoice-lines-table input,
.invoice-lines-table textarea {
  min-width: 110px;
  padding: 9px 10px;
}

.invoice-lines-table textarea {
  min-width: 230px;
  resize: vertical;
}

.line-label-stack {
  display: grid;
  gap: 8px;
  min-width: 260px;
}

.invoice-lines-table .line-type {
  min-width: 108px;
}

.invoice-lines-table .line-product {
  min-width: 260px;
}

.invoice-lines-table .line-tax {
  min-width: 180px;
}

.invoice-lines-table .line-quantity,
.invoice-lines-table .line-unit-price,
.invoice-lines-table .line-discount {
  min-width: 94px;
  text-align: right;
}

.invoice-line-row.is-note-line .product-cell,
.invoice-line-row.is-note-line .analytic-cell,
.invoice-line-row.is-note-line .tax-cell,
.invoice-line-row.is-note-line .line-number-cell,
.invoice-line-row.is-note-line .line-amount {
  opacity: 0.34;
}

.readonly-note {
  min-height: 40px;
  display: flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f5f7f5;
  color: var(--muted);
  padding: 9px 10px;
  font-size: 13px;
  font-weight: 700;
}

.invoice-line-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  padding: 14px 28px 22px;
  border-top: 1px solid var(--line);
}

.invoice-bottom-grid {
  display: grid;
  grid-template-columns: minmax(360px, 1fr) minmax(300px, 380px);
  gap: 26px;
  align-items: start;
  padding: 0 28px 28px;
}

.invoice-totals {
  display: grid;
  gap: 12px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.invoice-totals div {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 20px;
  align-items: baseline;
}

.invoice-totals span {
  color: var(--muted);
  font-weight: 800;
  text-align: right;
}

.invoice-totals strong {
  min-width: 124px;
  text-align: right;
  font-size: 22px;
}

.invoice-totals .amount-due {
  border-top: 1px solid var(--line);
  margin-top: 8px;
  padding-top: 12px;
}

@media (max-width: 900px) {
  .sidebar {
    position: sticky;
    top: 0;
    width: 100%;
    min-height: 0;
    padding: 12px;
    z-index: 5;
  }

  body {
    display: block;
  }

  .nav {
    grid-auto-flow: column;
    grid-auto-columns: max-content;
    overflow-x: auto;
    padding-bottom: 3px;
  }

  .logout-form {
    display: none;
  }

  .main {
    margin-left: 0;
    padding: 18px;
  }

  .topbar,
  .action-row,
  .success-card,
  .split-block {
    align-items: stretch;
    flex-direction: column;
  }

  .metric-grid,
  .grid,
  .two-col,
  .three-col,
  .customer-detail-grid,
  .invoice-header-grid,
  .invoice-meta-grid,
  .invoice-bottom-grid,
  .folder-grid,
  .check-grid,
  .folder-row {
    grid-template-columns: 1fr;
  }

  .invoice-form-head {
    align-items: stretch;
    flex-direction: column;
    padding: 20px;
  }

  .invoice-header-grid,
  .invoice-bottom-grid {
    padding: 20px;
  }

  .invoice-tabs {
    padding: 0 20px;
    overflow-x: auto;
  }

  .invoice-lines-table th:first-child,
  .invoice-lines-table td:first-child {
    padding-left: 20px;
  }

  .invoice-lines-table th:last-child,
  .invoice-lines-table td:last-child {
    padding-right: 20px;
  }

  .invoice-line-actions {
    padding: 14px 20px 20px;
  }

  .invoice-totals span {
    text-align: left;
  }

  .span-5,
  .span-6,
  .span-7,
  .span-12 {
    grid-column: span 1;
  }

  .account {
    justify-content: flex-start;
  }
}
