:root {
  /* Inspired by the old React/MUI dark theme (green accents) */
  --max-width: 1120px;
  --radius: 10px;
  --radius-sm: 8px;

  --bg: #121212;
  --paper: #1e1e1e;
  --text: #ffffff;
  --text-secondary: #b0b0b0;

  --primary: #4caf50;
  --secondary: #81c784;

  --border: rgba(255, 255, 255, 0.12);
  --border-strong: rgba(255, 255, 255, 0.18);
  --shadow: 0 6px 18px rgba(0, 0, 0, 0.35);

  --focus: 0 0 0 3px rgba(76, 175, 80, 0.35);
}

/* --------------------------------------------------------------------- */

body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, sans-serif;
  line-height: 1.45;
  background: var(--bg);
  color: var(--text);
}

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

a:hover {
  text-decoration: underline;
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.95em;
  background: rgba(255, 255, 255, 0.06);
  padding: 0.1rem 0.3rem;
  border-radius: 8px;
}

.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0.9rem 1rem;
}

/* --------------------------------------------------------------------- */
/* Top bar / navigation (MUI-ish) */

.topbar {
  background: var(--paper);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar .container {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1rem;
}

.nav-wrap {
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1rem;
  flex-wrap: wrap;
}

.nav-toggle {
  display: none;
}

.nav-toggle-btn {
  display: none;
  user-select: none;
  cursor: pointer;
  font-size: 1.1rem;
  padding: 0.35rem 0.55rem;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  line-height: 1;
}

.brand {
  font-weight: 800;
  letter-spacing: 0.2px;
  font-size: 1.1rem;
  color: var(--text);
}

.brand a {
  color: inherit;
  text-decoration: none;
}

.nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.15rem 0.35rem;
  align-items: center;
}

.nav a {
  color: var(--text-secondary);
  padding: 0.55rem 0.55rem;
  border-bottom: 2px solid transparent;
  border-radius: 8px;
  text-decoration: none;
}

.nav a:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
  text-decoration: none;
}

.nav a.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.user-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

@media (max-width: 760px) {
  .nav-toggle-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .nav-wrap {
    display: none;
    width: 100%;
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
    padding-top: 0.25rem;
  }

  /* checkbox hack: show menu */
  .nav-toggle:checked ~ .nav-wrap {
    display: flex;
  }

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

  .nav a {
    border-bottom: none;
    border-left: 4px solid transparent;
    border-radius: 10px;
  }

  .nav a.active {
    border-left-color: var(--primary);
    background: rgba(76, 175, 80, 0.08);
  }

  .user-actions {
    justify-content: space-between;
  }
}

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

/* --------------------------------------------------------------------- */
/* Typography */

h1, h2, h3 {
  margin: 0 0 0.75rem;
}

h1 {
  font-size: 2rem;
  font-weight: 800;
  color: var(--primary);
}

h2 {
  font-size: 1.25rem;
  font-weight: 750;
}

h3 {
  font-size: 1.05rem;
  font-weight: 700;
}

p {
  margin: 0.5rem 0;
}

/* --------------------------------------------------------------------- */
/* Cards */

.card {
  padding: 0.9rem 1rem;
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.02);
  margin-bottom: 1rem;
}

/* --------------------------------------------------------------------- */
/* Buttons */

.btn {
  display: inline-block;
  padding: 0.45rem 0.75rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--text);
  background: rgba(255, 255, 255, 0.02);
}

.btn:hover {
  background: rgba(255, 255, 255, 0.06);
  text-decoration: none;
}

.btn.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: rgba(0, 0, 0, 0.87);
  font-weight: 700;
}

.btn.primary:hover {
  filter: brightness(1.05);
}

.btn:focus,
input:focus,
select:focus,
textarea:focus {
  outline: none;
  box-shadow: var(--focus);
}

.btn.small {
  padding: 0.28rem 0.55rem;
  border-radius: var(--radius-sm);
  font-size: 0.92rem;
}

.btn[disabled],
button[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}

/* --------------------------------------------------------------------- */
/* Forms */

.form {
  max-width: 560px;
}

.form-row {
  margin-bottom: 0.85rem;
}

label {
  display: block;
  font-weight: 650;
  margin-bottom: 0.35rem;
  color: var(--text-secondary);
}

input,
select,
textarea {
  width: 100%;
  padding: 0.55rem 0.65rem;
  box-sizing: border-box;
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
}

input[type="checkbox"],
input[type="radio"] {
  width: auto;
  padding: 0;
  background: transparent;
  border: none;
}

input::placeholder {
  color: rgba(255, 255, 255, 0.45);
}

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

.form-actions {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  align-items: center;
}

.checkbox-inline {
  display: inline-flex;
  gap: 0.55rem;
  align-items: center;
  font-weight: 650;
}

.checkbox-inline input {
  width: auto;
  accent-color: var(--primary);
}

/* Filters row (invoice list) */
.filters-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.9rem;
  align-items: flex-end;
}

.filters-row .field {
  flex: 1 1 200px;
  min-width: 180px;
}

.filters-row .field.checkbox {
  flex: 0 0 auto;
  min-width: 180px;
}

.filters-row .field.actions {
  flex: 0 0 auto;
}

/* --------------------------------------------------------------------- */
/* Tables */

.table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

.table th,
.table td {
  padding: 0.6rem 0.65rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  text-align: left;
  vertical-align: top;
}

.table th {
  font-weight: 700;
  color: var(--text-secondary);
  background: rgba(255, 255, 255, 0.02);
}

.table tr:last-child td {
  border-bottom: none;
}

.table tr:hover td {
  background: rgba(255, 255, 255, 0.03);
}

/* --------------------------------------------------------------------- */
/* Badges / notices */

.badge {
  display: inline-block;
  padding: 0.12rem 0.55rem;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  font-size: 0.85em;
  margin-left: 0.35rem;
  color: var(--text-secondary);
}

.badge.overdue {
  border-color: rgba(244, 67, 54, 0.6);
  color: #ef9a9a;
}

.row-overdue td {
  background: rgba(244, 67, 54, 0.08);
}

.notice {
  padding: 0.75rem 0.9rem;
  border: 1px solid var(--border);
  border-left: 4px solid var(--border);
  border-radius: var(--radius);
  background: var(--paper);
}

.notice.success {
  border-left-color: var(--primary);
}

.notice.error {
  border-left-color: rgba(244, 67, 54, 0.8);
}

/* --------------------------------------------------------------------- */
/* Print/PDF safety: keep invoices readable */

@media print {
  body {
    background: #fff !important;
    color: #111 !important;
  }

  a { color: #111 !important; text-decoration: none !important; }

  .card {
    background: #fff !important;
    border-color: rgba(0, 0, 0, 0.15) !important;
    box-shadow: none !important;
  }

  .table {
    background: #fff !important;
    border-color: rgba(0, 0, 0, 0.15) !important;
  }

  .table th,
  .table td {
    border-bottom-color: rgba(0, 0, 0, 0.12) !important;
    color: #111 !important;
  }

  .table th {
    background: #f6f6f6 !important;
  }
}

/* --------------------------------------------------------------------- */
/* Invoice editor (phase-32) */

.invoice-editor-page {
  color: var(--text);
}

.invoice-editor-page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1rem;
}

.invoice-editor-backlink {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--text-secondary);
  margin-bottom: 0.45rem;
}

.invoice-editor-backlink:hover {
  color: var(--text);
}

.invoice-editor-title {
  color: var(--text);
  margin-bottom: 0.35rem;
}

.invoice-editor-subtitle {
  color: var(--text-secondary);
  max-width: 62rem;
}

.invoice-editor-page-actions {
  display: flex;
  gap: 0.65rem;
  flex-wrap: wrap;
}

.invoice-editor-page-actions .btn,
.invoice-editor-secondary-actions .btn {
  color: var(--text);
}

.invoice-editor-notice {
  margin-bottom: 1rem;
}

.invoice-editor-empty-state {
  padding: 1.25rem 1.35rem;
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.invoice-editor-empty-state h2,
.invoice-items-toolbar h2 {
  color: var(--text);
}

.invoice-editor-form {
  max-width: none;
}

.invoice-editor-surface {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.025), rgba(255, 255, 255, 0.01)), var(--paper);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.invoice-editor-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 310px;
  gap: 1.5rem;
  padding: 1.5rem;
}

.invoice-editor-main {
  min-width: 0;
}

.invoice-editor-fields {
  display: grid;
  gap: 1rem;
}

.invoice-editor-field-row {
  display: grid;
  grid-template-columns: 180px minmax(0, 1fr);
  gap: 1rem;
  align-items: flex-start;
}

.invoice-editor-field-row > label {
  display: flex;
  align-items: center;
  min-height: 44px;
  margin: 0;
  color: var(--text-secondary);
  font-weight: 700;
}

.invoice-editor-field-control {
  min-width: 0;
}

.invoice-editor-surface input,
.invoice-editor-surface select,
.invoice-editor-surface textarea {
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
  border-color: var(--border-strong);
}

.invoice-editor-surface input::placeholder,
.invoice-editor-surface textarea::placeholder {
  color: rgba(255, 255, 255, 0.45);
}

.invoice-editor-inline-row {
  display: flex;
  gap: 0.65rem;
  align-items: center;
}

.invoice-editor-inline-row > *:first-child {
  flex: 1 1 auto;
}

.invoice-contact-preview,
.invoice-editor-hint,
.invoice-editor-summary-note,
.invoice-editor-static-hint {
  color: var(--text-secondary);
  font-size: 0.95rem;
}

.invoice-contact-preview {
  margin-top: 0.55rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.invoice-contact-preview strong,
.invoice-editor-static-hint strong {
  color: var(--text);
}

.invoice-contact-sep {
  color: rgba(255, 255, 255, 0.35);
}

.invoice-editor-static-field {
  padding: 0.85rem 0.95rem;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  border-radius: 14px;
}

.invoice-editor-static-main {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--text);
}

.invoice-editor-static-hint {
  margin-top: 0.35rem;
}

.invoice-editor-due-grid {
  display: grid;
  grid-template-columns: minmax(180px, 220px) minmax(180px, 220px);
  gap: 0.75rem;
}

.invoice-editor-due-grid .invoice-editor-hint {
  grid-column: 1 / -1;
}

.invoice-editor-more-options {
  margin-top: 1.25rem;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.025);
}

.invoice-editor-more-options summary {
  cursor: pointer;
  list-style: none;
  padding: 0.9rem 1rem;
  font-weight: 700;
  color: var(--text);
}

.invoice-editor-more-options summary::-webkit-details-marker {
  display: none;
}

.invoice-editor-more-options summary::after {
  content: "+";
  float: right;
  color: var(--text-secondary);
}

.invoice-editor-more-options[open] summary::after {
  content: "−";
}

.invoice-editor-more-options-body {
  padding: 0 1rem 1rem;
}

.invoice-editor-sidebar {
  min-width: 0;
}

.invoice-editor-summary-card {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.03), rgba(255, 255, 255, 0.015));
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1.1rem 1rem;
  position: sticky;
  top: 84px;
}

.invoice-editor-summary-kicker {
  color: var(--secondary);
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  font-size: 0.8rem;
  margin-bottom: 0.45rem;
}

.invoice-editor-summary-total,
.invoice-editor-actions-total strong {
  font-size: 2rem;
  font-weight: 800;
  line-height: 1.1;
  color: var(--text);
}

.invoice-editor-summary-meta {
  display: grid;
  gap: 0.6rem;
  margin-top: 1rem;
}

.invoice-editor-summary-meta > div,
.invoice-editor-summary-breakdown > div {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: baseline;
}

.invoice-editor-summary-meta span,
.invoice-editor-summary-breakdown span,
.invoice-editor-actions-total span {
  color: var(--text-secondary);
}

.invoice-editor-summary-meta strong,
.invoice-editor-summary-breakdown strong {
  color: var(--text);
}

.invoice-editor-summary-breakdown {
  margin: 1rem 0;
  padding-top: 0.9rem;
  border-top: 1px solid var(--border);
  display: grid;
  gap: 0.6rem;
}

.invoice-items-section {
  padding: 0 1.5rem 1.5rem;
}

.invoice-items-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1rem;
}

.invoice-items-scroll {
  overflow-x: auto;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1rem;
}

.invoice-items-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0 0.75rem;
}

.invoice-items-th {
  text-transform: uppercase;
  font-size: 0.8rem;
  letter-spacing: 0.03em;
  color: var(--text-secondary);
  padding: 0 0.3rem 0.2rem;
  text-align: left;
}

.invoice-items-th-total,
.invoice-item-cell-total {
  text-align: right;
}

.invoice-items-th-drag,
.invoice-item-cell-drag {
  width: 3.25rem;
}

.invoice-items-th-remove,
.invoice-item-cell-remove {
  width: 6rem;
}

.invoice-item-row td {
  vertical-align: middle;
  padding: 0;
}

.invoice-item-cell {
  padding: 0 0.3rem;
}

.invoice-item-cell-drag {
  padding-right: 0.15rem;
}

.invoice-item-cell-qty {
  width: 6.5rem;
}

.invoice-item-cell-price,
.invoice-item-cell-vat {
  width: 10rem;
}

.invoice-item-cell-desc {
  min-width: 0;
}

.invoice-item-cell-total {
  width: 10.5rem;
}

.invoice-item-total {
  min-height: 44px;
  display: inline-flex;
  width: 100%;
  align-items: center;
  justify-content: flex-end;
  padding: 0.55rem 0.2rem;
  color: var(--text);
  font-weight: 700;
}

.invoice-row-drag {
  width: 42px;
  height: 42px;
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
  color: var(--text-secondary);
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.2rem;
  cursor: grab;
}

.invoice-row-drag span {
  display: block;
  width: 14px;
  height: 2px;
  border-radius: 999px;
  background: currentColor;
}

.invoice-row-drag:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
}

.invoice-row-drag:active {
  cursor: grabbing;
}

.invoice-item-row.is-dragging {
  opacity: 0.52;
}

.invoice-item-desc-field {
  display: grid;
  gap: 0.45rem;
}

.invoice-item-suggestions {
  border: 1px solid rgba(76, 175, 80, 0.35);
  background: rgba(255, 255, 255, 0.035);
  border-radius: 14px;
  padding: 0.55rem;
}

.invoice-item-suggestions[hidden] {
  display: none;
}

.invoice-item-suggestions-head {
  color: var(--secondary);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  margin-bottom: 0.45rem;
}

.invoice-item-suggestions-list {
  display: grid;
  gap: 0.35rem;
}

.invoice-suggestion-option {
  width: 100%;
  text-align: left;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
  border-radius: 12px;
  color: var(--text);
  padding: 0.55rem 0.7rem;
  display: grid;
  gap: 0.2rem;
  cursor: pointer;
}

.invoice-suggestion-option:hover,
.invoice-suggestion-option.is-active {
  border-color: rgba(76, 175, 80, 0.45);
  background: rgba(76, 175, 80, 0.08);
}

.invoice-row-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.35rem;
  padding: 0.1rem 0;
}

.invoice-suggestion-title {
  font-weight: 700;
}

.invoice-suggestion-meta {
  color: var(--text-secondary);
  font-size: 0.88rem;
}

.invoice-row-duplicate,
.invoice-row-remove {
  width: 42px;
  height: 42px;
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-secondary);
  line-height: 1;
  cursor: pointer;
}

.invoice-row-duplicate {
  font-size: 1.05rem;
  font-weight: 700;
}

.invoice-row-remove {
  font-size: 1.45rem;
}

.invoice-row-duplicate:hover,
.invoice-row-remove:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
}

.invoice-editor-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.1rem 1.5rem;
  border-top: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.02);
}

.invoice-editor-actions-total {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.invoice-editor-actions-total span {
  text-transform: uppercase;
  letter-spacing: 0.03em;
  font-size: 0.82rem;
  font-weight: 700;
}

.invoice-editor-submit {
  min-width: 180px;
}

.invoice-editor-secondary-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-top: 1rem;
}

.invoice-editor-secondary-actions form {
  display: inline-flex;
}

@media (max-width: 980px) {
  .invoice-editor-layout {
    grid-template-columns: 1fr;
  }

  .invoice-editor-summary-card {
    position: static;
  }
}

@media (max-width: 760px) {
  .invoice-editor-page-head,
  .invoice-editor-actions,
  .invoice-items-toolbar,
  .invoice-editor-inline-row {
    flex-direction: column;
    align-items: stretch;
  }

  .invoice-editor-layout,
  .invoice-items-section,
  .invoice-editor-actions {
    padding-left: 1rem;
    padding-right: 1rem;
  }

  .invoice-editor-field-row {
    grid-template-columns: 1fr;
    gap: 0.45rem;
  }

  .invoice-editor-field-row > label {
    min-height: 0;
  }

  .invoice-editor-due-grid {
    grid-template-columns: 1fr;
  }

  .invoice-item-cell-drag,
  .invoice-item-cell-qty,
  .invoice-item-cell-price,
  .invoice-item-cell-vat,
  .invoice-item-cell-total {
    width: auto;
  }

  .invoice-items-table {
    min-width: 760px;
  }
}
