:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --ink: #17202a;
  --muted: #667085;
  --line: #d9dee7;
  --primary: #0f766e;
  --primary-dark: #0b5f59;
  --accent: #b45309;
  --danger: #b42318;
  --info-bg: #e8f3ff;
  --error-bg: #fff1f0;
  --success-bg: #ecfdf3;
  --shadow: 0 18px 45px rgba(20, 32, 44, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

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

a:hover {
  text-decoration: underline;
}

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

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #ffffff;
  padding: 0.7rem 0.8rem;
}

textarea {
  resize: vertical;
}

label {
  display: grid;
  gap: 0.35rem;
  color: #344054;
  font-weight: 700;
}

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

th,
td {
  padding: 0.9rem;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  color: #475467;
  font-size: 0.82rem;
  text-transform: uppercase;
}

td form {
  display: inline-flex;
  gap: 0.5rem;
  align-items: center;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  min-height: 72px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 1.25rem;
  align-items: center;
  padding: 0 2rem;
  background: rgba(255, 255, 255, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.7rem;
  color: var(--ink);
  font-weight: 800;
  letter-spacing: 0;
}

.brand:hover {
  text-decoration: none;
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: var(--primary);
  color: white;
  font-size: 0.85rem;
}

.nav-links {
  display: flex;
  gap: 0.4rem;
  justify-content: center;
  flex-wrap: wrap;
}

.nav-links a,
.ghost-button,
.ghost-link,
.secondary-button,
.primary-button,
.small-button {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  padding: 0.65rem 0.9rem;
  font-weight: 800;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}

.nav-links a {
  color: #344054;
}

.nav-links a:hover,
.ghost-button:hover,
.ghost-link:hover {
  background: #eef6f5;
  text-decoration: none;
}

.user-menu,
.action-row,
.form-actions,
.table-actions {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
}

.user-menu {
  justify-content: flex-end;
}

.user-menu form {
  margin: 0;
}

.primary-button {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.primary-button:hover {
  background: var(--primary-dark);
  text-decoration: none;
}

.secondary-button,
.small-button {
  background: #ffffff;
  color: var(--ink);
  border-color: var(--line);
}

.secondary-button:hover,
.small-button:hover {
  border-color: var(--primary);
  color: var(--primary);
  text-decoration: none;
}

.danger-button {
  color: var(--danger);
  border-color: #fecdca;
  background: #fff8f7;
}

.ghost-button,
.ghost-link {
  background: transparent;
  color: #344054;
}

.small-button {
  min-height: 34px;
  padding: 0.45rem 0.65rem;
  font-size: 0.9rem;
}

.page-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 2rem 0 4rem;
}

.page-heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.page-heading h1,
.auth-card h1,
.report-header h1 {
  margin: 0;
  font-size: 2rem;
  line-height: 1.15;
  letter-spacing: 0;
}

.eyebrow {
  margin: 0 0 0.4rem;
  color: var(--accent);
  font-size: 0.78rem;
  text-transform: uppercase;
  font-weight: 900;
}

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

.metric-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

.metric-card,
.panel,
.auth-card,
.report-sheet {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metric-card {
  display: grid;
  gap: 0.25rem;
  padding: 1rem;
}

.metric-card span {
  color: var(--muted);
  font-weight: 800;
}

.metric-card strong {
  font-size: 1.8rem;
  line-height: 1.1;
}

.metric-card small {
  color: var(--muted);
}

.split-grid,
.report-grid {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
  gap: 1rem;
}

.panel {
  padding: 1rem;
}

.panel-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 0.75rem;
}

.panel-heading h2,
.report-sheet h2 {
  margin: 0;
  font-size: 1.1rem;
}

.bar-row {
  display: grid;
  grid-template-columns: minmax(140px, 1fr) minmax(100px, 160px) auto;
  gap: 0.8rem;
  align-items: center;
  padding: 0.8rem 0;
  border-top: 1px solid var(--line);
}

.bar-row:first-of-type {
  border-top: 0;
}

.bar-row div:first-child {
  display: grid;
}

.bar-row span {
  color: var(--muted);
  font-size: 0.9rem;
}

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

.bar-track span {
  display: block;
  height: 100%;
  background: var(--primary);
}

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

.numeric {
  text-align: right;
}

.table-note {
  display: block;
  color: var(--muted);
  font-size: 0.9rem;
}

.filter-bar,
.year-filter,
.invoice-form,
.stacked-form {
  display: grid;
  gap: 1rem;
}

.filter-bar {
  grid-template-columns: repeat(5, minmax(0, 1fr)) auto;
  align-items: end;
  margin-bottom: 1rem;
  padding: 1rem;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.year-filter {
  grid-template-columns: minmax(160px, 220px) auto 1fr;
  align-items: end;
  margin-bottom: 1rem;
  padding: 1rem;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.form-panel {
  padding: 1.25rem;
}

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

.field-note {
  align-self: end;
  color: var(--muted);
  font-size: 0.92rem;
  padding: 0.75rem 0;
}

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

.receipt-preview {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin: 1rem 0;
  padding: 0.8rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}

.receipt-preview img {
  width: 96px;
  height: 96px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--line);
}

.auth-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem 1rem;
  background:
    linear-gradient(135deg, rgba(15, 118, 110, 0.08), rgba(180, 83, 9, 0.08)),
    var(--bg);
}

.auth-shell {
  width: min(460px, 100%);
}

.installer-shell {
  width: min(900px, 100%);
}

.auth-card {
  padding: 1.5rem;
}

.installer-card h2 {
  margin: 1rem 0 0;
  font-size: 1.1rem;
}

.auth-switch {
  margin: 1rem 0 0;
  color: var(--muted);
}

.alert {
  margin-bottom: 1rem;
  padding: 0.85rem 1rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--info-bg);
  color: #184264;
}

.alert ul {
  margin: 0.45rem 0 0;
  padding-left: 1.2rem;
}

.alert-error {
  background: var(--error-bg);
  color: #912018;
  border-color: #fecdca;
}

.alert-success {
  background: var(--success-bg);
  color: #05603a;
  border-color: #abefc6;
}

.empty-state {
  max-width: 640px;
  margin: 4rem auto;
  text-align: center;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 2rem;
  box-shadow: var(--shadow);
}

.report-sheet {
  padding: 1.5rem;
}

.report-header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding-bottom: 1rem;
  border-bottom: 2px solid var(--ink);
  margin-bottom: 1rem;
}

.report-header div:last-child {
  display: grid;
  align-content: start;
  justify-items: end;
  color: var(--muted);
}

.report-metrics .metric-card {
  box-shadow: none;
}

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

.report-grid {
  align-items: start;
  margin: 1rem 0;
}

.settings-grid {
  margin-top: 1rem;
}

.inline-edit-form,
.inline-add-form {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto auto;
  gap: 0.75rem;
  align-items: center;
}

.inline-add-form {
  margin-bottom: 1rem;
}

.setup-row-actions {
  display: grid;
  grid-template-columns: auto minmax(260px, 1fr) auto;
  gap: 0.75rem;
  align-items: center;
}

.setup-row-actions > form:last-child {
  justify-self: end;
}

.drag-handle {
  display: inline-grid;
  place-items: center;
  width: 34px;
  min-width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: #ffffff;
  cursor: grab;
  font-weight: 900;
}

tr.is-dragging {
  opacity: 0.55;
}

.sort-save-form {
  margin-top: 1rem;
}

.check-label {
  display: inline-flex;
  grid-template-columns: none;
  align-items: center;
  gap: 0.4rem;
  font-weight: 700;
  white-space: nowrap;
}

.check-label input {
  width: auto;
}

.report-note {
  margin-top: 1.25rem;
  color: var(--muted);
  font-size: 0.92rem;
}

@media (max-width: 900px) {
  .topbar {
    grid-template-columns: 1fr;
    padding: 1rem;
  }

  .nav-links {
    justify-content: flex-start;
  }

  .user-menu {
    justify-content: flex-start;
  }

  .metric-grid,
  .split-grid,
  .report-grid,
  .form-grid,
  .inline-edit-form,
  .inline-add-form {
    grid-template-columns: 1fr;
  }

  .filter-bar {
    grid-template-columns: 1fr 1fr;
  }

  .year-filter,
  .setup-row-actions {
    grid-template-columns: 1fr;
  }

  .setup-row-actions > form:last-child {
    justify-self: start;
  }
}

@media (max-width: 620px) {
  .page-heading,
  .report-header,
  .panel-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .filter-bar {
    grid-template-columns: 1fr;
  }

  .year-filter {
    grid-template-columns: 1fr;
  }

  .bar-row {
    grid-template-columns: 1fr;
  }

  .numeric {
    text-align: left;
  }
}

@media print {
  body {
    background: #ffffff;
    color: #000000;
  }

  .topbar,
  .no-print,
  .alert,
  .nav-links,
  .user-menu {
    display: none !important;
  }

  .page-shell {
    width: 100%;
    padding: 0;
  }

  .report-sheet,
  .metric-card {
    box-shadow: none;
    border-color: #999999;
  }

  a {
    color: #000000;
  }
}
