:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --input-bg: #ffffff;
  --text: #1c2430;
  --muted: #647084;
  --line: #d8dde6;
  --accent: #1f6feb;
  --danger: #b42318;
  --secondary-bg: #e9edf5;
  --alert-bg: #fff3f1;
  --alert-line: #f1a7a0;
  --notice-bg: #eaf7ef;
  --notice-line: #9fd3ad;
  --notice-text: #176138;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111418;
  --panel: #1b2027;
  --input-bg: #12161c;
  --text: #edf2f7;
  --muted: #a8b3c2;
  --line: #343c47;
  --accent: #78aefb;
  --danger: #ff8b82;
  --secondary-bg: #2a323d;
  --alert-bg: #351816;
  --alert-line: #7a2d29;
  --notice-bg: #12301f;
  --notice-line: #2e6d45;
  --notice-text: #a9e7bf;
}

@media (prefers-color-scheme: dark) {
  :root[data-theme="system"] {
    color-scheme: dark;
    --bg: #111418;
    --panel: #1b2027;
    --input-bg: #12161c;
    --text: #edf2f7;
    --muted: #a8b3c2;
    --line: #343c47;
    --accent: #78aefb;
    --danger: #ff8b82;
    --secondary-bg: #2a323d;
    --alert-bg: #351816;
    --alert-line: #7a2d29;
    --notice-bg: #12301f;
    --notice-line: #2e6d45;
    --notice-text: #a9e7bf;
  }
}

* {
  box-sizing: border-box;
}

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

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

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

.app-header,
.app-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.app-footer {
  border-top: 1px solid var(--line);
  border-bottom: 0;
  color: var(--muted);
  font-size: 14px;
}

.brand {
  color: var(--text);
  font-weight: 700;
}

.nav {
  display: flex;
  align-items: center;
  gap: 16px;
}

.icon-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--text);
  background: var(--secondary-bg);
  font-size: 18px;
  line-height: 1;
}

.nav form {
  margin: 0;
}

.nav button,
.form button,
.button,
.button-row button,
.inline-form button,
.danger-zone button {
  border: 0;
  border-radius: 6px;
  padding: 9px 13px;
  color: #fff;
  background: var(--accent);
  cursor: pointer;
}

.button {
  display: inline-block;
}

.button.secondary {
  color: var(--text);
  background: var(--secondary-bg);
}

button:disabled {
  cursor: not-allowed;
  opacity: .55;
}

.page {
  width: min(1040px, calc(100% - 32px));
  margin: 32px auto;
}

.auth-panel,
.card,
.hero {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.auth-panel {
  width: min(520px, 100%);
  margin: 56px auto;
  padding: 28px;
}

.auth-panel.invoice-form-panel {
  width: min(860px, 100%);
}

.auth-panel h1,
.hero h1,
.card h2 {
  margin: 0 0 12px;
}

.form {
  display: grid;
  gap: 16px;
}

.form label {
  display: grid;
  gap: 7px;
  font-weight: 600;
}

.form input,
.form select,
.form textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  color: var(--text);
  background: var(--input-bg);
}

.form textarea {
  resize: vertical;
}

.form fieldset {
  display: grid;
  gap: 10px;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

.form fieldset label {
  display: grid;
  gap: 7px;
  font-weight: 500;
}

.form fieldset input {
  width: 100%;
}

.form label:has(input[type="checkbox"]),
.form fieldset label:has(input[type="checkbox"]) {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 500;
}

.form input[type="checkbox"],
.form fieldset input[type="checkbox"] {
  width: auto;
}

.copy-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.copy-row code {
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--secondary-bg);
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  background: var(--secondary-bg);
  cursor: pointer;
}

.copy-status {
  color: var(--muted);
  font-size: 13px;
}

.line-item-row {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(120px, 180px);
  gap: 12px;
  align-items: end;
  margin-bottom: 10px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 16px;
}

.toolbar a,
.status {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 10px;
  color: var(--text);
  background: var(--panel);
  font-size: 13px;
  font-weight: 700;
  text-transform: capitalize;
}

.toolbar a.active {
  border-color: var(--accent);
  color: #fff;
  background: var(--accent);
}

.status.draft {
  color: #675300;
  background: #fff8c5;
}

.status.approved {
  color: #084b83;
  background: #dff0ff;
}

.status.paid {
  color: #0f5132;
  background: #d1e7dd;
}

.status.voided {
  color: #842029;
  background: #f8d7da;
}

.status.closed {
  color: #495057;
  background: #e9ecef;
}

.alert {
  border: 1px solid var(--alert-line);
  border-radius: 6px;
  padding: 10px 12px;
  color: var(--danger);
  background: var(--alert-bg);
}

.notice {
  border: 1px solid var(--notice-line);
  border-radius: 6px;
  padding: 10px 12px;
  color: var(--notice-text);
  background: var(--notice-bg);
}

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

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

.button-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.button-row form,
.danger-zone form {
  margin: 0;
}

.audit-dialog {
  width: min(860px, calc(100% - 32px));
  max-height: min(720px, calc(100vh - 48px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: var(--panel);
  box-shadow: 0 20px 60px rgb(0 0 0 / .25);
}

.audit-dialog::backdrop {
  background: rgb(0 0 0 / .55);
}

.audit-dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

.audit-dialog-header h2 {
  margin: 0;
}

.audit-dialog-body {
  max-height: calc(100vh - 160px);
  padding: 0 18px 18px;
  overflow: auto;
}

.audit-empty {
  margin: 18px 0 0;
}

.audit-table {
  min-width: 680px;
}

.audit-details {
  display: grid;
  gap: 4px;
  margin: 0;
  padding-left: 18px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}

.card {
  padding: 18px;
  overflow-x: auto;
}

.stack {
  margin-top: 16px;
}

.details {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 8px 16px;
  margin: 0;
}

.details dt {
  color: var(--muted);
  font-weight: 700;
}

.details dd {
  margin: 0;
}

.inline-form {
  display: grid;
  grid-template-columns: repeat(4, minmax(140px, 1fr));
  gap: 12px;
  align-items: end;
}

.filter-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
  align-items: end;
}

.filter-form label {
  display: grid;
  gap: 6px;
  font-weight: 600;
}

.filter-form select,
.filter-form input[type="date"] {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  color: var(--text);
  background: var(--input-bg);
}

.filter-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.filter-actions button {
  border: 0;
  border-radius: 6px;
  padding: 9px 13px;
  color: #fff;
  background: var(--accent);
  cursor: pointer;
}

.filter-note {
  margin-bottom: 0;
}

.inline-form label {
  display: grid;
  gap: 6px;
  font-weight: 600;
}

.inline-form input {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  color: var(--text);
  background: var(--input-bg);
}

.danger-zone {
  margin-top: 16px;
  border-color: var(--alert-line);
}

.danger-zone button {
  background: var(--danger);
}

.metric {
  margin: 0;
  font-size: 34px;
  font-weight: 700;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 11px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

@media (max-width: 720px) {
  .app-header,
  .app-footer,
  .nav,
  .hero,
  .inline-form,
  .filter-form,
  .line-item-row {
    align-items: flex-start;
    flex-direction: column;
  }

  .inline-form,
  .filter-form,
  .line-item-row {
    display: grid;
    grid-template-columns: 1fr;
  }
}
