﻿:root {
  --bg: #f5f7fb;
  --card: #ffffff;
  --ink: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --primary: #024A70;
  --accent: #2AA63E;
  --danger: #ef4444;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
  --radius: 14px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Space Grotesk", "Segoe UI", sans-serif;
  background: linear-gradient(135deg, #eef2ff 0%, #f8fafc 55%, #ebebeb 100%);
  color: var(--ink);
}

a {
  color: inherit;
  text-decoration: none;
}

.app {
  display: grid;
  grid-template-columns: 60px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: #ffffff;
  color: #cbd5f5;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 16px;
  gap: 18px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 18px;
  width: 100%;
  align-items: center;
}

.sidebar-bottom {
  margin-top: auto;
  width: 100%;
  display: flex;
  justify-content: center;
}

.sidebar .logo {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  background: transparent;
  display: grid;
  place-items: center;
  color: #6e6c6c;
  font-weight: 700;
  overflow: hidden;
}

.sidebar .logo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.sidebar a {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  color: inherit;
  transition: all 0.2s ease;
  border: 1px solid transparent;
}

.sidebar a svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
}

.sidebar a.active,
.sidebar a:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.2);
  color: #fff;
}

.main {
  padding: 28px 32px 40px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.topbar h1 {
  margin: 0;
  font-size: 28px;
}

.topbar .actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  border: 1px solid rgba(148, 163, 184, 0.12);
}

.card + .card {
  margin-top: 20px;
}

.grid {
  display: grid;
  gap: 18px;
}

.grid.two {
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

.grid.three {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.grid.four {
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}

.stats-grid {
  margin-bottom: 20px;
}

.stat-card {
  display: flex;
  align-items: center;
  gap: 16px;
}

.stat-icon {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: rgba(75, 107, 251, 0.12);
  display: grid;
  place-items: center;
  font-size: 22px;
}

.search-card {
  margin-bottom: 20px;
}

.search-row {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.invoice-filters {
  display: grid;
  grid-template-columns: minmax(220px, 1.4fr) repeat(2, minmax(160px, 0.7fr)) auto;
  gap: 16px;
  align-items: end;
}

.invoice-filters .filter-field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.invoice-filters .filter-actions {
  display: flex;
  gap: 10px;
}

.contacts-toolbar {
  display: grid;
  grid-template-columns: minmax(220px, 280px) 1fr;
  gap: 20px;
  align-items: center;
  margin-bottom: 20px;
}

.contacts-toolbar .stat-card {
  padding: 0;
}

.contacts-toolbar .notice {
  font-weight: 700;
}

/* Dashboard layout (matches reference UI) */
.dashboard-body {
  background: #FAFAF9;
}

.dashboard-shell {
  display: grid;
  grid-template-columns: 200px 1fr;
  min-height: 100vh;
}

.dashboard-sidebar {
  background: #0F172B;
  border-right: 1px solid #e7ebf2;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.dashboard-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 500;
}

.dashboard-logo span {
  color: #ffffff;
}

.dashboard-logo img {
  width: 38px;
  height: 38px;
  object-fit: contain;
}

.sidebar-section {
  font-size: 12px;
  color: #98a1b3;
  margin: 8px 0 0;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  font-weight: 500;
}

.dashboard-nav {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.dashboard-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  color: #fff;
  font-weight: 400;
  border-left: 3px solid transparent;
}

.dashboard-nav a.active {
  background: #f0f7f4;
  color: #2AA63E;
  border-left-color: #2AA63E;
}

.nav-icon {
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: inherit;
}

.nav-icon svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.nav-icon i {
  font-size: 18px;
  line-height: 1;
}

.sidebar-footer {
  margin-top: auto;
}

.logout-link {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #ffffff;
  font-weight: 400;
}

.dashboard-main {
  padding: 0 28px 40px;
}

.dashboard-topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 26px;
  background: #fff;
  border-bottom: 1px solid #e7ebf2;
  padding: 10px 18px;
  margin-left: -28px;
  margin-right: -28px;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 12px;
  color: #64748b;
}

.topbar-left .powered {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
  color: #0f172b;
}

.topbar-left .powered i {
  color: var(--accent);
  font-size: 14px;
}

.topbar-link {
  color: #2563eb;
  font-weight: 600;
  text-decoration: none;
}

.topbar-link:hover {
  color: #1d4ed8;
}

.search-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #f5f7fb;
  border: 1px solid #e1e6f0;
  padding: 8px 12px;
  border-radius: 12px;
  min-width: 320px;
}

.search-bar input {
  border: none;
  outline: none;
  background: transparent;
  font-size: 14px;
  width: 100%;
}

.search-icon svg {
  width: 18px;
  height: 18px;
  fill: #9aa4b2;
}

.search-hint {
  font-size: 12px;
  color: #9aa4b2;
  border: 1px solid #d9e0ec;
  padding: 2px 6px;
  border-radius: 6px;
  background: #fff;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.topbar-right .icon-btn {
  border: none;
  padding: 6px;
}

.topbar-logo {
  width: 32px;
  height: 32px;
  object-fit: contain;
  border-radius: 10px;
  background: #fff;
  border: none;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  border-radius: 999px;
  border: none;
  background: #fff;
}

.user-meta {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}

.user-name {
  font-size: 11px;
  color: #6b7280;
}

.user-email {
  font-size: 12px;
  font-weight: 600;
  color: #111827;
}

.dashboard-cards {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.dashboard-greeting {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  margin: 16px 0 20px;
}

.dashboard-greeting h2 {
  margin: 0 0 6px;
  font-size: 24px;
  color: #111827;
}

.stat-tile {
  background: #fff;
  border-radius: 16px;
  border: 1px solid #e7ebf2;
  padding: 18px;
  display: flex;
  gap: 14px;
  align-items: center;
}

.tile-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: #FAFAF9;
  color: #2AA63E;
  font-weight: 700;
}

.tile-icon i {
  font-size: 20px;
  line-height: 1;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: 1.6fr 1fr 1fr;
  gap: 18px;
}

.dashboard-grid .card {
  border-radius: 16px;
  border: 1px solid #e7ebf2;
  box-shadow: none;
}

.recent-list {
  display: grid;
  gap: 12px;
}

.recent-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid #eef1f5;
  background: #fafbfc;
  font-size: 13px;
}

.recent-item span {
  color: #6b7280;
  font-size: 12px;
}

.chart-total {
  margin-top: 12px;
  padding: 20px 12px 10px;
  border-radius: 12px;
  background: #f0f7f4;
  color: #2AA63E;
  font-size: 14px;
  font-weight: 600;
}

.chart-total strong {
  font-size: 16px;
  color: #0f4f47;
}

.contact-invoice-history {
  margin-top: 24px;
}

.contact-email-history {
  margin-top: 24px;
}

@media (max-width: 960px) {
  .dashboard-shell {
    grid-template-columns: 1fr;
  }

  .dashboard-sidebar {
    position: static;
  }

  .search-bar {
    min-width: 0;
    width: 100%;
  }

  .dashboard-topbar {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .dashboard-grid {
    grid-template-columns: 1fr;
  }
}

.logo-preview {
  width: 120px;
  height: 120px;
  border-radius: 12px;
  border: 1px dashed var(--line);
  display: grid;
  place-items: center;
  background: #fff;
}

.logo-preview img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.invoice-logo {
  display: none;
  align-items: center;
  justify-content: flex-end;
  padding: 0;
}

.invoice-logo img {
  max-height: 60px;
  max-width: 200px;
  object-fit: contain;
}

.invoice-title {
  display: none;
  margin: 0 0 12px;
  font-size: 32px;
  letter-spacing: 1px;
}

.print-header {
  display: none;
}
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.4);
  display: grid;
  place-items: center;
  z-index: 50;
  padding: 20px;
}

.modal-card {
  background: #fff;
  width: min(520px, 95vw);
  border-radius: 16px;
  padding: 20px;
  box-shadow: var(--shadow);
}

.hidden {
  display: none;
}
label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 8px;
  font-weight: 700;
}

input,
textarea,
select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  font-family: inherit;
  font-size: 14px;
  background: #fff;
}

textarea {
  min-height: 90px;
  resize: vertical;
}

.autosize {
  resize: none;
  overflow: hidden;
}

.btn {
  padding: 10px 16px;
  border-radius: 10px;
  border: 1px solid var(--primary);
  background: var(--primary);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn.secondary {
  border-color: #94a3b8;
  background: #fff;
  color: var(--ink);
}

.btn.ghost {
  border-color: transparent;
  background: rgba(75, 107, 251, 0.1);
  color: var(--primary);
}

.btn.success {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.btn.accent {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.btn.danger {
  border-color: var(--danger);
  background: #fff;
  color: var(--danger);
}

.btn.disabled,
.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: btn-spin 0.8s linear infinite;
}

.btn-spinner.hidden {
  display: none;
}

@keyframes btn-spin {
  to {
    transform: rotate(360deg);
  }
}

.icon-btn {
  border: 1px solid var(--line);
  background: #fff;
  padding: 8px 10px;
  border-radius: 10px;
  cursor: pointer;
}

.icon-btn.danger {
  border-color: rgba(239, 68, 68, 0.4);
  color: var(--danger);
}

.status {
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  text-transform: capitalize;
}

.status-paid {
  background: #2AA63E;
  color: #fff;
}

.status-sent {
  background: #024A70;
  color: #fff;
}

.status-approved {
  background: #024A70;
  color: #fff;
}

.status-issued {
  background: #2AA63E;
  color: #fff;
}

.status-draft {
  background: rgba(148, 163, 184, 0.2);
  color: #64748b;
}

.status-paused {
  background: rgba(148, 163, 184, 0.2);
  color: #475569;
}

.table {
  width: 100%;
  border-collapse: collapse;
}

.invoice-items .table th:nth-child(1),
.invoice-items .table td:nth-child(1) {
  width: 42%;
}

.invoice-items .table th:nth-child(2),
.invoice-items .table td:nth-child(2) {
  width: 8%;
}

.invoice-items .table th:nth-child(3),
.invoice-items .table td:nth-child(3) {
  width: 10%;
}

.invoice-items .table th:nth-child(4),
.invoice-items .table td:nth-child(4) {
  width: 10%;
}

.invoice-items .table th:nth-child(5),
.invoice-items .table td:nth-child(5) {
  width: 15%;
}

.invoice-items .table th:nth-child(6),
.invoice-items .table td:nth-child(6) {
  width: 15%;
}

.table th,
.table td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}

.table th:nth-child(4),
.table td:nth-child(4) {
  min-width: 90px;
}

.table thead th {
  font-size: 13px;
  color: var(--ink);
  font-weight: 700;
}

.invoice-number-link {
  color: #2563eb;
  font-weight: 600;
}

.invoice-number-link:hover {
  color: #1d4ed8;
}

.plan-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.plan-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 700;
  background: rgba(42, 166, 62, 0.15);
  color: #0f5132;
  border: 1px solid rgba(42, 166, 62, 0.3);
}

.plan-status.is-free {
  background: rgba(249, 115, 22, 0.16);
  color: #9a3412;
  border-color: rgba(249, 115, 22, 0.35);
}

.creditnote-date {
  width: 50%;
}

.form-message {
  margin-top: 12px;
  color: var(--danger);
  font-size: 13px;
}

.form-message.success {
  color: var(--accent);
}

.auth-layout {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 40px 20px;
}

.auth-card {
  width: min(420px, 90vw);
  padding: 32px;
  border-radius: 20px;
  background: #fff;
  box-shadow: var(--shadow);
}

.auth-card h1 {
  margin-top: 0;
}

.notice {
  font-size: 13px;
  color: var(--muted);
}

.totals {
  display: grid;
  gap: 10px;
}

.totals .row {
  display: flex;
  justify-content: space-between;
  font-weight: 600;
}

.totals .row strong {
  font-size: 18px;
}

.footer-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 12px;
}

.contact-footer {
  align-items: flex-start;
}

.contact-footer .footer-left {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sticky-footer {
  position: sticky;
  bottom: 0;
  background: #fff;
  padding: 12px 0;
  border-top: 1px solid var(--line);
  z-index: 5;
}

.footer-buttons {
  display: flex;
  gap: 12px;
  align-items: center;
}

.section-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.section-title h3 {
  margin: 0;
}

.banner {
  display: none;
  background: rgba(21, 183, 126, 0.2);
  border: 1px solid rgba(21, 183, 126, 0.35);
  color: #0f8a5c;
  padding: 12px 16px;
  border-radius: 12px;
  font-weight: 600;
  margin-bottom: 16px;
}

.banner.show {
  display: block;
}

.pdf-mode .sidebar,
.pdf-mode .topbar,
.pdf-mode .footer-actions,
.pdf-mode .icon-btn,
.pdf-mode .btn,
.pdf-mode .internal-note,
.pdf-mode select[name="status"],
.pdf-mode .banner {
  display: none !important;
}


@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr;
  }

  .sidebar {
    flex-direction: row;
    justify-content: space-between;
  }

  .main {
    padding: 20px;
  }
}

@media print {
  body,
  .dashboard-body,
  .dashboard-main,
  .main {
    background: #fff;
  }

  /* Keep these sections together */
  .invoice-totals,
  .invoice-notes,
  .invoice-totals *,
  .invoice-notes * {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  /* Keep a whole row together */
  .invoice-items tr {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  /* Ensure table headers repeat on new pages */
  .invoice-items thead { display: table-header-group; }
  .invoice-items tbody { display: table-row-group; }

  form.grid {
    display: grid;
    grid-template-columns: 1fr 65mm;
    gap: 12px 12mm;
  }

  .sidebar,
  .topbar,
  .dashboard-sidebar,
  .dashboard-topbar,
  .footer-actions,
  .icon-btn,
  .btn,
  .contact-field,
  [data-recurring-fields],
  select[name="recurring_type"],
  .recurring-type-field {
    display: none !important;
  }

  .card {
    box-shadow: none;
    border: none;
    border-radius: 0;
    padding: 0;
  }

  .main {
    padding: 0;
  }

  .invoice-header {
    display: contents;
  }

  .invoice-title {
    display: block;
    font-size: 24pt;
    letter-spacing: 1px;
    margin: 0;
  }

  .print-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12mm;
    margin-bottom: 10mm;
  }

  .invoice-logo {
    display: flex;
  }

  .invoice-logo img {
    max-height: 60px;
  }

  .invoice-parties label,
  .invoice-items label,
  .invoice-notes label {
    color: #111827;
    font-weight: 600;
    font-size: 10pt;
  }

  .invoice-parties textarea,
  .invoice-parties input,
  .invoice-items input,
  .invoice-items select,
  .invoice-notes textarea {
    border: none;
    padding: 0;
    font-size: 10pt;
    line-height: 1.35;
  }

  select[name="status"],
  .status-field,
  .internal-note {
    display: none !important;
  }

  .invoice-parties {
    display: flex;
    flex-direction: column;
    gap: 12px;
    grid-column: 1 / -1;
    grid-row: 1;
  }

  .invoice-meta-row {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6mm;
    margin-top: 6mm;
    order: 2;
    align-items: start;
  }

  .invoice-meta-row > div {
    min-width: 0;
  }

  .invoice-meta,
  .invoice-dates {
    display: contents;
  }

  .invoice-items {
    margin-top: 8mm;
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .invoice-items .table th,
  .invoice-items .table td {
    padding: 2.5mm 1.5mm;
    font-size: 9.5pt;
  }

  .invoice-items .table th {
    border-bottom: 1px solid #e5e7eb;
  }

  .invoice-totals {
    margin-top: 8mm;
    border-top: none;
    padding-top: 0;
    grid-column: 2 / 3;
    grid-row: 3;
  }

  .invoice-totals .totals,
  .invoice-totals .totals .row,
  .invoice-totals .totals .row strong {
    font-size: 10pt;
  }

  .invoice-notes {
    margin-top: 8mm;
    display: block;
    grid-column: 1 / 2;
    grid-row: 3;
  }
}
