:root {
  color-scheme: light;
  --bg: #f5f2ec;
  --surface: #fffdf8;
  --ink: #191814;
  --muted: #6f6a61;
  --line: #ded8cc;
  --brand: #1f4f3b;
  --brand-strong: #123629;
  --accent: #b98732;
  --danger: #9f372d;
  --paid: #1f7a53;
  --open: #9c6a1d;
  --shadow: 0 18px 45px rgba(30, 26, 20, .08);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

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

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

button {
  border: 0;
  cursor: pointer;
}

a {
  color: inherit;
}

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

.auth-box {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 28px;
}

.auth-box img {
  width: 56px;
  height: 56px;
  object-fit: contain;
  display: block;
  margin-bottom: 18px;
}

.auth-box h1 {
  margin: 0 0 22px;
  font-size: 1.6rem;
}

.auth-error {
  min-height: 22px;
  margin: 14px 0 0;
  color: var(--danger);
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  background: #151814;
  color: #f8f3e8;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  font-weight: 800;
  letter-spacing: .05em;
}

.brand img {
  width: 42px;
  height: 42px;
  object-fit: contain;
  background: #fff;
  border-radius: 6px;
}

.tabs {
  display: grid;
  gap: 6px;
}

.tab,
.ghost {
  min-height: 42px;
  border-radius: 6px;
  text-align: left;
  padding: 0 12px;
  color: inherit;
  background: transparent;
}

.tab:hover,
.tab.active,
.ghost:hover {
  background: rgba(255, 255, 255, .1);
}

.logout {
  margin-top: auto;
  color: #d4cabb;
}

.workspace {
  min-width: 0;
  padding: 28px clamp(18px, 4vw, 44px) 48px;
}

.topbar {
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: .78rem;
  font-weight: 800;
  text-transform: uppercase;
}

h1,
h2,
h3 {
  margin: 0;
}

.topbar h1 {
  font-size: clamp(1.55rem, 2.4vw, 2.25rem);
}

.primary,
.secondary,
.danger,
.small-action,
.auth-box button {
  min-height: 40px;
  border-radius: 6px;
  padding: 0 14px;
  font-weight: 750;
}

.primary,
.auth-box button {
  background: var(--brand);
  color: #fff;
}

.primary:hover,
.auth-box button:hover {
  background: var(--brand-strong);
}

.secondary {
  background: #eadfcf;
  color: var(--ink);
}

.danger {
  background: #f0d5d1;
  color: var(--danger);
}

.small-action {
  min-height: 34px;
  padding: 0 10px;
  background: #eee7dc;
}

.small-action + .small-action {
  margin-left: 6px;
}

.link-action {
  min-height: 0;
  padding: 0;
  background: transparent;
  color: var(--danger);
  font-size: .78rem;
  font-weight: 800;
  text-decoration: underline;
}

.notice {
  border: 1px solid #d5c092;
  background: #fff7df;
  color: #5e4315;
  padding: 12px 14px;
  border-radius: 6px;
  margin-bottom: 16px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

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

.metric span {
  color: var(--muted);
  font-size: .84rem;
}

.metric strong {
  font-size: 1.8rem;
}

.metric small {
  color: var(--muted);
  font-weight: 750;
}

.danger-metric {
  border-color: #e3b9b3;
  background: #fff8f6;
}

.danger-metric strong {
  color: var(--danger);
}

.dashboard-panel {
  margin-bottom: 18px;
}

.split-grid {
  display: grid;
  grid-template-columns: minmax(320px, 430px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

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

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

.panel-sub {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: .84rem;
}

.panel-body {
  padding: 18px;
}

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

.form-grid .wide {
  grid-column: 1 / -1;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: .82rem;
  font-weight: 750;
}

input,
select,
textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 9px 10px;
  outline: none;
}

textarea {
  min-height: 76px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(31, 79, 59, .12);
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

.table-wrap {
  width: 100%;
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}

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

th {
  color: var(--muted);
  font-size: .78rem;
  text-transform: uppercase;
}

td.money,
th.money {
  text-align: right;
}

.overdue-row {
  background: #fff8f6;
}

.due-warning {
  color: var(--danger);
  font-weight: 800;
}

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

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 26px;
  padding: 0 9px;
  border-radius: 999px;
  background: #eee7dc;
  color: var(--muted);
  font-size: .78rem;
  font-weight: 800;
}

.pill.paid {
  background: #dcefe4;
  color: var(--paid);
}

.pill.open {
  background: #f3e5ca;
  color: var(--open);
}

.pill.partial {
  background: #e7ead9;
  color: #6c6d23;
}

.pill.in_progress {
  background: #dce8ef;
  color: #28536b;
}

.pill.done,
.pill.invoiced {
  background: #dcefe4;
  color: var(--paid);
}

.pill.converted {
  background: #e0e7f0;
  color: #36506d;
}

.pill.cancelled {
  background: #f0d5d1;
  color: var(--danger);
}

.empty {
  padding: 26px 18px;
  color: var(--muted);
  text-align: center;
}

.line-items {
  display: grid;
  gap: 10px;
}

.line-item {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) 84px 130px 38px;
  gap: 8px;
  align-items: end;
}

.line-remove {
  width: 38px;
  height: 40px;
  border-radius: 6px;
  background: #f0d5d1;
  color: var(--danger);
  font-weight: 900;
}

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

.einvoice-grid {
  grid-template-columns: minmax(0, 1.25fr) minmax(360px, .75fr);
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
  }

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

  .tab {
    text-align: center;
    padding: 0 8px;
  }

  .logout {
    margin-top: 0;
  }

  .summary-grid,
  .split-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 680px) {
  .workspace {
    padding: 18px 12px 32px;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

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

  .form-grid {
    grid-template-columns: 1fr;
  }

  .line-item {
    grid-template-columns: 1fr;
  }
}
