:root {
  --bg: #f6f5f1;
  --bg-card: #ffffff;
  --bg-hover: #fafaf8;
  --bg-input: #f6f5f1;
  --text-primary: #1a1a1a;
  --text-secondary: #6b6b6b;
  --text-tertiary: #9a9a9a;
  --border: #e5e3de;
  --border-focus: #1a1a1a;
  --accent: #1a1a2e;
  --accent-light: #2d2d4a;
  --green: #2d8a4e;
  --green-bg: #e8f5ed;
  --red: #c44040;
  --red-bg: #fce8e8;
  --orange: #c47a20;
  --orange-bg: #fef3e2;
  --blue: #2a6cb6;
  --blue-bg: #e8f0fa;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.06);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.08);
  --radius: 10px;
  --radius-sm: 6px;
  --font-body: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  --font-display: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  --font-mono: 'SF Mono', SFMono-Regular, ui-monospace, Menlo, monospace;
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 15px; -webkit-font-smoothing: antialiased; }

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.6;
}

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

/* ─── TOPBAR ─── */
.topbar {
  background: var(--accent);
  color: #fff;
  padding: 0 2rem;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-family: var(--font-display);
  font-size: 1.25rem;
  letter-spacing: -0.02em;
}

.topbar-brand svg { opacity: 0.9; }

.topbar-nav {
  display: flex;
  gap: 0.25rem;
  align-items: center;
}

.topbar-nav a {
  padding: 0.4rem 0.85rem;
  border-radius: var(--radius-sm);
  font-size: 0.87rem;
  font-weight: 500;
  color: rgba(255,255,255,0.7);
  transition: var(--transition);
  letter-spacing: 0.01em;
}

.topbar-nav a:hover { color: #fff; background: rgba(255,255,255,0.1); }
.topbar-nav a.active { color: #fff; background: rgba(255,255,255,0.15); }

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

.topbar-actions a {
  padding: 0.4rem 0.85rem;
  border-radius: var(--radius-sm);
  font-size: 0.87rem;
  font-weight: 500;
  color: rgba(255,255,255,0.7);
  transition: var(--transition);
}

.topbar-actions a:hover { color: #fff; }

/* ─── LAYOUT ─── */
.page-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.75rem;
}

.page-title {
  font-family: var(--font-display);
  font-size: 2rem;
  letter-spacing: -0.03em;
  line-height: 1.2;
}

/* ─── CARDS ─── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: visible;
}

.card-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-title {
  font-size: 0.82rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-secondary);
}

.card-body { padding: 1.5rem; }

/* ─── BUTTONS ─── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 1.2rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 0.87rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
  letter-spacing: 0.01em;
}

.btn:active { transform: scale(0.98); }

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.btn-primary:hover {
  background: var(--accent-light);
  box-shadow: var(--shadow-md);
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-primary);
  border-color: var(--border);
}

.btn-secondary:hover {
  background: var(--bg-hover);
  border-color: var(--text-tertiary);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}

.btn-ghost:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.btn-danger {
  background: transparent;
  color: var(--red);
  border-color: var(--red);
}

.btn-danger:hover {
  background: var(--red);
  color: #fff;
}

.btn-sm {
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
}

.btn-lg {
  padding: 0.75rem 1.5rem;
  font-size: 0.93rem;
}

.btn-icon {
  padding: 0.5rem;
  border-radius: var(--radius-sm);
}

/* ─── INPUTS ─── */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.form-label {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 0.6rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 0.93rem;
  color: var(--text-primary);
  background: var(--bg-card);
  transition: var(--transition);
  outline: none;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(26,26,46,0.08);
}

.form-input::placeholder,
.form-textarea::placeholder {
  color: var(--text-tertiary);
}

.form-textarea {
  resize: vertical;
  min-height: 80px;
}

.form-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='12' height='8' viewBox='0 0 12 8' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1.5L6 6.5L11 1.5' stroke='%236b6b6b' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2.25rem;
}

.form-row {
  display: grid;
  gap: 1rem;
}

.form-row-2 { grid-template-columns: 1fr 1fr; }
.form-row-3 { grid-template-columns: 1fr 1fr 1fr; }
.form-row-4 { grid-template-columns: 1fr 1fr 1fr 1fr; }

.form-check {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.form-check input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* ─── TABLE ─── */
.table-wrapper {
  overflow: visible;
}

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

table th {
  padding: 0.85rem 1rem;
  text-align: left;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-tertiary);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}

table td {
  padding: 1rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.93rem;
}

table tr {
  transition: var(--transition);
}

table tbody tr:hover {
  background: var(--bg-hover);
}

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

/* ─── BADGES ─── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.65rem;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.badge-paid { background: var(--green-bg); color: var(--green); }
.badge-outstanding { background: var(--orange-bg); color: var(--orange); }
.badge-draft { background: var(--bg-input); color: var(--text-secondary); }
.badge-overdue { background: var(--red-bg); color: var(--red); }

.badge-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

/* ─── INVOICE LIST ─── */
.list-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.list-filters {
  display: flex;
  gap: 0.25rem;
  background: var(--bg-input);
  padding: 0.25rem;
  border-radius: var(--radius-sm);
}

.filter-btn {
  padding: 0.45rem 1rem;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
  background: transparent;
  cursor: pointer;
  transition: var(--transition);
}

.filter-btn:hover { color: var(--text-primary); }

.filter-btn.active {
  background: var(--bg-card);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}

.search-box {
  position: relative;
  width: 260px;
}

.search-box input {
  width: 100%;
  padding: 0.55rem 0.85rem 0.55rem 2.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 0.87rem;
  background: var(--bg-card);
  outline: none;
  transition: var(--transition);
}

.search-box input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(26,26,46,0.08);
}

.search-box svg {
  position: absolute;
  left: 0.8rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-tertiary);
}

.year-separator {
  padding: 0.75rem 1rem;
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-tertiary);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.invoice-number {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--accent);
}

.invoice-amount {
  font-family: var(--font-mono);
  font-size: 0.9rem;
  font-weight: 500;
  text-align: right;
}

.row-actions {
  opacity: 0;
  transition: var(--transition);
}

table tbody tr:hover .row-actions,
.row-actions.dropdown-active,
.row-actions:has(.dropdown-menu.open) { opacity: 1; }

.dropdown {
  position: relative;
}

.dropdown-menu {
  position: absolute;
  right: 0;
  top: 100%;
  min-width: 160px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  padding: 0.35rem;
  z-index: 150;
  display: none;
}

.dropdown-menu.open { display: block; }

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  border-radius: 4px;
  font-size: 0.87rem;
  cursor: pointer;
  transition: var(--transition);
  border: none;
  background: none;
  width: 100%;
  font-family: var(--font-body);
  color: var(--text-primary);
}

.dropdown-item:hover { background: var(--bg-hover); }
.dropdown-item.danger { color: var(--red); }
.dropdown-item.danger:hover { background: var(--red-bg); }

/* ─── INVOICE EDIT ─── */
.invoice-edit-layout {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 1.5rem;
  align-items: start;
}

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

.invoice-sidebar {
  position: sticky;
  top: 72px;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.edit-tabs {
  display: flex;
  gap: 0.25rem;
  margin-bottom: 1.5rem;
  background: var(--bg-input);
  padding: 0.25rem;
  border-radius: var(--radius-sm);
  width: fit-content;
}

.edit-tab {
  padding: 0.5rem 1.1rem;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 0.87rem;
  font-weight: 500;
  color: var(--text-secondary);
  background: transparent;
  cursor: pointer;
  transition: var(--transition);
}

.edit-tab:hover { color: var(--text-primary); }

.edit-tab.active {
  background: var(--bg-card);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}

.from-to-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
}

.section-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-tertiary);
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--border);
}

.business-title-input {
  font-family: var(--font-display);
  font-size: 1.5rem;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.75rem;
  background: transparent;
  color: var(--text-primary);
  width: 100%;
  outline: none;
  transition: var(--transition);
}

.business-title-input:focus {
  border-color: var(--border-focus);
  border-style: solid;
  background: var(--bg-card);
}

/* Line items */
.line-items-table {
  width: 100%;
  border-collapse: collapse;
}

.line-items-table th {
  padding: 0.6rem 0.75rem;
  text-align: left;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-tertiary);
  border-bottom: 2px solid var(--border);
}

.line-items-table th.text-right,
.line-items-table td.text-right { text-align: right; }

.line-items-table td {
  padding: 0.5rem;
  vertical-align: top;
  border-bottom: 1px solid var(--border);
}

.line-items-table td:first-child { padding-left: 0; }

.line-item-input {
  width: 100%;
  padding: 0.5rem 0.65rem;
  border: 1px solid transparent;
  border-radius: 4px;
  font-family: var(--font-body);
  font-size: 0.9rem;
  background: transparent;
  outline: none;
  transition: var(--transition);
}

.line-item-input:hover { border-color: var(--border); }
.line-item-input:focus { border-color: var(--border-focus); background: var(--bg-card); }

.line-item-input.mono {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  text-align: right;
}

.line-item-amount {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  padding: 0.5rem 0.65rem;
  text-align: right;
  color: var(--text-secondary);
  min-width: 90px;
}

.remove-item-btn {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--text-tertiary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  margin-top: 0.35rem;
}

.remove-item-btn:hover { background: var(--red-bg); color: var(--red); }

.add-item-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.75rem;
  padding: 0.5rem 1rem;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition);
}

.add-item-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--bg-hover);
}

/* Totals */
.totals-section {
  display: flex;
  justify-content: flex-end;
  margin-top: 1.5rem;
}

.totals-table {
  width: 280px;
}

.totals-row {
  display: flex;
  justify-content: space-between;
  padding: 0.5rem 0;
  font-size: 0.9rem;
}

.totals-row .label { color: var(--text-secondary); }

.totals-row .value {
  font-family: var(--font-mono);
  font-size: 0.87rem;
  font-weight: 500;
}

.totals-row.total {
  border-top: 2px solid var(--text-primary);
  margin-top: 0.5rem;
  padding-top: 0.75rem;
  font-weight: 700;
}

.totals-row.total .value {
  font-size: 1rem;
  font-weight: 700;
}

.totals-row.balance {
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent);
}

.totals-row.balance .value {
  font-size: 1.1rem;
  font-weight: 700;
}

/* Sidebar widgets */
.sidebar-widget {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.sidebar-widget-header {
  padding: 0.85rem 1rem;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-tertiary);
  border-bottom: 1px solid var(--border);
}

.sidebar-widget-body {
  padding: 1rem;
}

.color-swatches {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 0.4rem;
  margin-bottom: 1rem;
}

.color-swatch {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 6px;
  border: 2px solid transparent;
  cursor: pointer;
  transition: var(--transition);
}

.color-swatch:hover { transform: scale(1.1); }
.color-swatch.active { border-color: var(--text-primary); box-shadow: 0 0 0 2px var(--bg-card); }

.sidebar-btn {
  width: 100%;
  padding: 0.65rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 0.87rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  background: var(--bg-card);
  color: var(--text-primary);
  text-align: center;
  display: block;
}

.sidebar-btn:hover {
  background: var(--bg-hover);
  border-color: var(--text-tertiary);
}

.sidebar-btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.sidebar-btn-primary:hover {
  background: var(--accent-light);
}

/* ─── INVOICE PREVIEW ─── */
.preview-container {
  max-width: 800px;
  margin: 2rem auto;
}

.preview-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}

.invoice-paper {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 3rem;
  position: relative;
  overflow: hidden;
}

.invoice-paper::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: var(--accent);
}

.invoice-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 2.5rem;
}

.invoice-brand {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.invoice-logo {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-sm);
  object-fit: contain;
}

.invoice-company {
  font-family: var(--font-display);
  font-size: 1.5rem;
  line-height: 1.2;
}

.invoice-meta {
  text-align: right;
}

.invoice-meta-number {
  font-family: var(--font-mono);
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 0.75rem;
}

.invoice-meta-row {
  display: flex;
  justify-content: flex-end;
  gap: 1rem;
  font-size: 0.87rem;
  line-height: 1.8;
}

.invoice-meta-label {
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  color: var(--text-tertiary);
}

.invoice-addresses {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
  margin-bottom: 2.5rem;
}

.invoice-address-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-tertiary);
  margin-bottom: 0.5rem;
}

.invoice-address-name {
  font-weight: 600;
  font-size: 1.05rem;
  margin-bottom: 0.25rem;
}

.invoice-address-detail {
  font-size: 0.87rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

.invoice-items-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 2rem;
}

.invoice-items-table th {
  padding: 0.75rem 1rem;
  text-align: left;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-tertiary);
  border-bottom: 2px solid var(--text-primary);
}

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

.invoice-items-table th:nth-child(3),
.invoice-items-table td:nth-child(3) { text-align: center; }

.invoice-items-table th:nth-child(2),
.invoice-items-table td:nth-child(2) { text-align: right; }

.invoice-items-table td {
  padding: 0.85rem 1rem;
  font-size: 0.93rem;
  border-bottom: 1px solid var(--border);
}

.invoice-items-table td:nth-child(2),
.invoice-items-table td:last-child {
  font-family: var(--font-mono);
  font-size: 0.87rem;
}

.invoice-items-table td:nth-child(3) {
  font-family: var(--font-mono);
  font-size: 0.87rem;
}

.invoice-totals {
  display: flex;
  justify-content: flex-end;
}

.invoice-totals-inner {
  width: 280px;
}

.invoice-totals-row {
  display: flex;
  justify-content: space-between;
  padding: 0.45rem 0;
  font-size: 0.9rem;
}

.invoice-totals-row .label {
  color: var(--text-secondary);
  font-size: 0.85rem;
}

.invoice-totals-row .value {
  font-family: var(--font-mono);
  font-weight: 500;
}

.invoice-totals-row.grand-total {
  border-top: 2px solid var(--text-primary);
  margin-top: 0.5rem;
  padding-top: 0.75rem;
  font-size: 1.05rem;
  font-weight: 700;
}

.invoice-totals-row.grand-total .value {
  font-size: 1.1rem;
  font-weight: 700;
}

.invoice-totals-row.balance-due {
  margin-top: 0.5rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
  font-size: 1.15rem;
  font-weight: 700;
}

.invoice-totals-row.balance-due .value {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--accent);
}

.invoice-payment-row {
  color: var(--green);
}

.invoice-notes {
  margin-top: 2.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

.invoice-notes-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-tertiary);
  margin-bottom: 0.5rem;
}

.invoice-notes-text {
  font-size: 0.87rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

.paid-stamp {
  position: absolute;
  top: 3rem;
  right: 3rem;
  padding: 0.5rem 1.5rem;
  border: 3px solid var(--green);
  border-radius: var(--radius-sm);
  color: var(--green);
  font-size: 1.1rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  transform: rotate(12deg);
  opacity: 0.7;
}

/* ─── INVOICE EDIT IN-PLACE ─── */
.invoice-paper-edit {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 3rem;
  position: relative;
  overflow: hidden;
  --accent: #1a1a2e;
}

.invoice-paper-edit::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: var(--accent);
}

.invoice-paper-edit .invoice-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 2.5rem;
}

.invoice-paper-edit .invoice-brand {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.logo-edit-wrapper {
  flex-shrink: 0;
}

.logo-edit-box {
  width: 56px;
  height: 56px;
  border: 2px dashed var(--border);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition);
  overflow: hidden;
  background: var(--bg);
}

.logo-edit-box:hover {
  border-color: var(--accent);
  background: var(--bg-hover);
}

.logo-edit-box .invoice-logo {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.logo-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  color: var(--text-tertiary);
}

.logo-placeholder span {
  font-size: 0.6rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.invoice-company-input {
  font-family: var(--font-display);
  font-size: 1.5rem;
  line-height: 1.2;
  border: none;
  border-bottom: 1px dashed transparent;
  padding: 0.15rem 0;
  background: transparent;
  color: var(--text-primary);
  width: 100%;
  outline: none;
  transition: var(--transition);
}

.invoice-company-input:hover {
  border-bottom-color: var(--border);
}

.invoice-company-input:focus {
  border-bottom-color: var(--accent);
  border-bottom-style: solid;
}

.invoice-email-input {
  font-size: 0.85rem;
  color: var(--text-secondary);
  border: none;
  border-bottom: 1px dashed transparent;
  padding: 0.15rem 0;
  margin-top: 0.25rem;
  background: transparent;
  width: 100%;
  outline: none;
  transition: var(--transition);
  font-family: var(--font-body);
}

.invoice-email-input:hover {
  border-bottom-color: var(--border);
}

.invoice-email-input:focus {
  border-bottom-color: var(--accent);
  border-bottom-style: solid;
}

.invoice-meta-number-input {
  font-family: var(--font-mono);
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--accent);
  text-align: right;
  border: none;
  background: transparent;
  padding: 0;
  margin-bottom: 0.75rem;
  width: 100%;
  outline: none;
}

.invoice-meta-value-input {
  font-size: 0.87rem;
  border: none;
  border-bottom: 1px dashed transparent;
  padding: 0.1rem 0;
  background: transparent;
  text-align: right;
  outline: none;
  transition: var(--transition);
  font-family: var(--font-body);
  color: var(--text-primary);
  appearance: none;
  -webkit-appearance: none;
}

.invoice-meta-value-input:hover {
  border-bottom-color: var(--border);
}

.invoice-meta-value-input:focus {
  border-bottom-color: var(--accent);
  border-bottom-style: solid;
}

select.invoice-meta-value-input {
  cursor: pointer;
  padding-right: 0;
}

.invoice-meta-balance {
  font-weight: 600;
  font-family: var(--font-mono);
  font-size: 0.93rem;
}

.invoice-inline-input {
  width: 100%;
  font-size: 0.87rem;
  color: var(--text-secondary);
  border: none;
  border-bottom: 1px dashed transparent;
  padding: 0.3rem 0;
  background: transparent;
  outline: none;
  transition: var(--transition);
  font-family: var(--font-body);
  line-height: 1.6;
}

.invoice-inline-input:hover {
  border-bottom-color: var(--border);
}

.invoice-inline-input:focus {
  border-bottom-color: var(--accent);
  border-bottom-style: solid;
  color: var(--text-primary);
}

.invoice-inline-input.invoice-inline-bold {
  font-weight: 600;
  font-size: 1.05rem;
  color: var(--text-primary);
  margin-bottom: 0.1rem;
}

/* Edit items table */
.invoice-items-table-edit {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 0;
}

.invoice-items-table-edit th {
  padding: 0.75rem 0.5rem;
  text-align: left;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-tertiary);
  border-bottom: 2px solid var(--text-primary);
}

.invoice-items-table-edit th:nth-child(3),
.invoice-items-table-edit th:nth-child(4),
.invoice-items-table-edit th:last-child { text-align: right; }

.invoice-items-table-edit td {
  padding: 0.35rem 0.25rem;
  vertical-align: middle;
  border-bottom: 1px solid var(--border);
}

.invoice-items-table-edit td:first-child {
  padding-left: 0;
  width: 28px;
}

.invoice-paper-edit .invoice-totals {
  margin-top: 1.5rem;
}

.invoice-paper-edit .add-item-btn {
  margin-top: 0.75rem;
  margin-bottom: 0;
}

/* Notes in edit */
.invoice-notes-edit {
  margin-top: 2.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

.invoice-notes-textarea {
  width: 100%;
  font-size: 0.87rem;
  color: var(--text-secondary);
  border: 1px dashed transparent;
  border-radius: var(--radius-sm);
  padding: 0.5rem;
  background: transparent;
  outline: none;
  transition: var(--transition);
  font-family: var(--font-body);
  line-height: 1.6;
  resize: vertical;
  min-height: 60px;
}

.invoice-notes-textarea:hover {
  border-color: var(--border);
}

.invoice-notes-textarea:focus {
  border-color: var(--accent);
  border-style: solid;
  background: var(--bg-hover);
}

/* ─── SETTINGS ─── */
.settings-layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 2rem;
  align-items: start;
}

.settings-nav {
  position: sticky;
  top: 72px;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.settings-nav-item {
  padding: 0.55rem 0.85rem;
  border-radius: var(--radius-sm);
  font-size: 0.87rem;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition);
  border: none;
  background: none;
  text-align: left;
  font-family: var(--font-body);
}

.settings-nav-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.settings-nav-item.active {
  background: var(--bg-card);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
  font-weight: 600;
}

.settings-sections {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.settings-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.75rem;
}

.settings-section-title {
  font-family: var(--font-display);
  font-size: 1.25rem;
  margin-bottom: 1.25rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.logo-upload {
  display: flex;
  align-items: center;
  gap: 1.25rem;
}

.logo-preview {
  width: 80px;
  height: 80px;
  border: 2px dashed var(--border);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  cursor: pointer;
  transition: var(--transition);
  background: var(--bg);
}

.logo-preview:hover {
  border-color: var(--text-tertiary);
}

.logo-preview img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.logo-upload-text {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

/* ─── EMPTY STATE ─── */
.empty-state {
  text-align: center;
  padding: 4rem 2rem;
}

.empty-state-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto 1.25rem;
  color: var(--text-tertiary);
  opacity: 0.5;
}

.empty-state-title {
  font-family: var(--font-display);
  font-size: 1.35rem;
  margin-bottom: 0.5rem;
}

.empty-state-text {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 1.5rem;
}

/* ─── MODAL ─── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  backdrop-filter: blur(4px);
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
}

.modal-backdrop.open { display: flex; }

.modal {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 480px;
  padding: 1.75rem;
}

.modal-title {
  font-family: var(--font-display);
  font-size: 1.25rem;
  margin-bottom: 1.25rem;
}

.modal-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  margin-top: 1.5rem;
}

/* ─── TOAST ─── */
.toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.toast {
  padding: 0.75rem 1.25rem;
  background: var(--text-primary);
  color: #fff;
  border-radius: var(--radius-sm);
  font-size: 0.87rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: toast-in 0.3s ease;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.toast.success { background: var(--green); }
.toast.error { background: var(--red); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ─── PAGINATION ─── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem;
  border-top: 1px solid var(--border);
}

.pagination-info {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.pagination-btns {
  display: flex;
  gap: 0.5rem;
}

/* ─── ANIMATIONS ─── */
@keyframes fade-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.animate-in {
  animation: fade-in 0.4s ease forwards;
}

.stagger-1 { animation-delay: 0.05s; opacity: 0; }
.stagger-2 { animation-delay: 0.1s; opacity: 0; }
.stagger-3 { animation-delay: 0.15s; opacity: 0; }
.stagger-4 { animation-delay: 0.2s; opacity: 0; }

/* ─── RESPONSIVE ─── */
@media (max-width: 900px) {
  .invoice-edit-layout { grid-template-columns: 1fr; }
  .settings-layout { grid-template-columns: 1fr; }
  .from-to-grid { grid-template-columns: 1fr; }
  .invoice-addresses { grid-template-columns: 1fr; }
  .form-row-2, .form-row-3, .form-row-4 { grid-template-columns: 1fr; }
  .page-container { padding: 1rem; }
}

@media (max-width: 640px) {
  .topbar-nav { display: none; }
  .list-toolbar { flex-direction: column; align-items: stretch; }
  .search-box { width: 100%; }
}

/* ─── UTILITIES ─── */
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-muted { color: var(--text-secondary); }
.text-mono { font-family: var(--font-mono); }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.hidden { display: none !important; }
