:root {
  --bg: #f3f6f5;
  --surface: #ffffff;
  --surface-strong: #ffffff;
  --ink: #1f2522;
  --muted: #69736d;
  --line: #d9e1de;
  --accent: #0f766e;
  --accent-dark: #0b5f59;
  --accent-soft: #d9f2ed;
  --warning: #b45309;
  --danger: #b42318;
  --shadow: 0 18px 45px rgba(31, 37, 34, 0.07);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--bg);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 32px;
  padding: 28px;
  background: #17211d;
  color: #f7f2e9;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border-radius: 8px;
  color: #17211d;
  background: #f3c969;
  font-weight: 800;
}

.brand h1,
.topbar h2,
.section-heading h3,
.panel h3,
.modal h3 {
  margin: 0;
  letter-spacing: 0;
}

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

.sidebar .eyebrow,
.sidebar-note span {
  color: #b9c8c0;
}

.nav-list {
  display: grid;
  gap: 8px;
}

.nav-link {
  min-height: 44px;
  padding: 12px 14px;
  border-radius: 8px;
  color: #dce5df;
  text-decoration: none;
}

.nav-link:hover,
.nav-link.active {
  color: #17211d;
  background: #f3c969;
}

.sidebar-note {
  display: grid;
  gap: 8px;
  margin-top: auto;
  padding: 16px;
  border: 1px solid rgba(247, 242, 233, 0.18);
  border-radius: 8px;
}

.sidebar-note span {
  font-size: 0.76rem;
  text-transform: uppercase;
}

.content {
  padding: 28px;
  overflow-x: hidden;
}

.topbar,
.section-heading,
.panel-header,
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.topbar {
  margin-bottom: 28px;
}

.topbar h2 {
  font-size: clamp(1.8rem, 3vw, 2.8rem);
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.primary-button,
.ghost-button,
.icon-button,
.danger-button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  font-weight: 750;
}

.primary-button {
  padding: 0 16px;
  color: #fff;
  background: var(--accent);
}

.primary-button:hover {
  background: var(--accent-dark);
}

.ghost-button {
  padding: 0 16px;
  color: var(--ink);
  background: var(--surface-strong);
  border: 1px solid var(--line);
}

.icon-button {
  width: 42px;
  color: var(--ink);
  background: var(--surface-strong);
  border: 1px solid var(--line);
}

.danger-button {
  min-height: 34px;
  padding: 0 10px;
  color: var(--danger);
  background: #fff1ef;
}

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

.table-actions .ghost-button {
  min-height: 34px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

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

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

.metric {
  display: grid;
  gap: 10px;
  padding: 18px;
}

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

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

.metric.warning {
  background: #fff8eb;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(320px, 0.8fr);
  gap: 18px;
}

.analytics-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(320px, 0.8fr);
  gap: 18px;
  margin-bottom: 18px;
}

.panel {
  padding: 18px;
}

.panel-header {
  margin-bottom: 14px;
}

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

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

th,
td {
  padding: 14px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

th {
  color: var(--ink);
  font-size: 0.78rem;
  text-transform: uppercase;
}

.status {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 750;
}

.status.paid {
  color: #075c4f;
  background: var(--accent-soft);
}

.status.pending {
  color: var(--warning);
  background: #fff1d6;
}

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

.breakdown-row {
  display: grid;
  gap: 8px;
}

.breakdown-label {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

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

.progress span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}

.bar-chart {
  display: grid;
  grid-template-columns: repeat(4, minmax(64px, 1fr));
  align-items: end;
  min-height: 210px;
  gap: 16px;
  padding-top: 12px;
}

.bar-group {
  display: grid;
  align-items: end;
  gap: 10px;
  min-width: 0;
  text-align: center;
}

.bars {
  display: flex;
  align-items: end;
  justify-content: center;
  height: 150px;
  gap: 8px;
  padding: 8px;
  border-radius: 8px;
  background: #f3f6f5;
}

.bar {
  display: block;
  width: 18px;
  min-height: 6px;
  border-radius: 6px 6px 0 0;
}

.bar.revenue,
.status-meter .paid,
.legend.paid {
  background: var(--accent);
}

.bar.expense,
.status-meter .pending,
.legend.pending {
  background: #f3c969;
}

.bar-group strong {
  color: var(--muted);
  font-size: 0.82rem;
  text-transform: capitalize;
}

.status-chart {
  display: grid;
  gap: 16px;
  padding-top: 12px;
}

.status-meter {
  display: flex;
  width: 100%;
  height: 18px;
  overflow: hidden;
  border-radius: 999px;
  background: #e5ebe8;
}

.status-meter span {
  min-width: 4px;
}

.status-chart-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.status-chart-row span {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
}

.legend {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 999px;
}

.section-heading {
  margin-bottom: 16px;
}

.filter-bar {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(160px, 0.35fr) minmax(200px, 0.45fr);
  gap: 12px;
  margin-bottom: 16px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
}

.filter-bar label {
  gap: 6px;
  color: var(--muted);
  font-size: 0.82rem;
}

.filter-bar input,
.filter-bar select {
  color: var(--ink);
}

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

.client-card {
  display: grid;
  gap: 10px;
  padding: 18px;
}

.client-card h4,
.client-card p {
  margin: 0;
}

.client-card p {
  color: var(--muted);
}

.settings-form {
  display: grid;
  gap: 16px;
  max-width: 820px;
}

.settings-form .primary-button {
  width: fit-content;
}

.form-feedback {
  min-height: 22px;
  margin: 0;
  color: var(--accent-dark);
  font-weight: 750;
}

.invoice-document {
  max-width: 900px;
  margin: 0 auto;
  padding: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  box-shadow: var(--shadow);
}

.invoice-doc-header,
.invoice-parties,
.invoice-totals div {
  display: flex;
  justify-content: space-between;
  gap: 24px;
}

.invoice-doc-header {
  align-items: flex-start;
  padding-bottom: 28px;
  border-bottom: 2px solid var(--ink);
}

.invoice-brand {
  display: inline-flex;
  margin-bottom: 14px;
  color: var(--accent);
  font-size: 1rem;
  font-weight: 850;
}

.invoice-doc-header h3 {
  margin: 0 0 8px;
  font-size: 2.1rem;
}

.invoice-doc-header p,
.invoice-parties p,
.invoice-footer p {
  margin: 0;
  color: var(--muted);
}

.invoice-status {
  min-width: 120px;
  padding: 10px 14px;
  border-radius: 8px;
  color: #075c4f;
  background: var(--accent-soft);
  font-weight: 800;
  text-align: center;
}

.invoice-parties {
  margin: 32px 0;
}

.invoice-parties section {
  display: grid;
  flex: 1;
  gap: 7px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.invoice-parties span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

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

.invoice-lines td:last-child,
.invoice-lines th:last-child {
  text-align: right;
}

.invoice-totals {
  display: grid;
  gap: 10px;
  width: min(360px, 100%);
  margin: 30px 0 0 auto;
}

.invoice-totals div {
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}

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

.invoice-totals .grand-total {
  color: var(--ink);
  border-bottom: 0;
  font-size: 1.2rem;
}

.invoice-footer {
  margin-top: 46px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.empty-state {
  display: grid;
  justify-items: center;
  gap: 8px;
  width: 100%;
  padding: 34px 24px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: #f8faf9;
  text-align: center;
}

.empty-state strong {
  color: var(--ink);
  font-size: 1rem;
}

.empty-state span,
.empty-state small {
  max-width: 360px;
}

.empty-state small {
  color: var(--accent-dark);
  font-weight: 750;
}

.modal {
  width: min(560px, calc(100vw - 28px));
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
}

.modal::backdrop {
  background: rgba(23, 33, 29, 0.45);
}

.modal-card {
  display: grid;
  gap: 16px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 10;
  max-width: min(360px, calc(100vw - 32px));
  padding: 14px 16px;
  border: 1px solid rgba(15, 118, 110, 0.22);
  border-radius: 8px;
  color: #f8fffd;
  background: #17211d;
  box-shadow: 0 18px 45px rgba(31, 37, 34, 0.2);
  font-weight: 750;
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px);
  transition:
    opacity 180ms ease,
    transform 180ms ease;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

label {
  display: grid;
  gap: 8px;
  color: var(--ink);
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
}

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

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

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 2;
    flex-direction: row;
    align-items: center;
    padding: 16px;
  }

  .nav-list {
    grid-auto-flow: column;
    overflow-x: auto;
  }

  .sidebar-note {
    display: none;
  }

  .metrics-grid,
  .dashboard-grid,
  .analytics-grid,
  .client-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

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

  .topbar,
  .section-heading,
  .panel-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-actions,
  .topbar-actions button,
  .section-heading button,
  .settings-form .primary-button {
    width: 100%;
  }

  .metrics-grid,
  .dashboard-grid,
  .analytics-grid,
  .client-grid,
  .filter-bar,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .invoice-document {
    padding: 24px;
  }

  .invoice-doc-header,
  .invoice-parties {
    flex-direction: column;
  }

  .sidebar {
    align-items: flex-start;
    flex-direction: column;
    gap: 14px;
  }

  .toast {
    right: 16px;
    bottom: 16px;
    left: 16px;
    max-width: none;
  }

  .nav-list {
    width: 100%;
  }
}

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

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

  .app-shell,
  .content {
    display: block;
    padding: 0;
  }

  .view {
    display: none !important;
  }

  #invoicePreview {
    display: block !important;
  }

  .invoice-document {
    max-width: none;
    padding: 0;
    border: 0;
    box-shadow: none;
  }
}
