:root {
  --bg: #eef2f6;
  --surface: #ffffff;
  --surface-soft: #f7f9fc;
  --line: #d8dfeb;
  --line-strong: #b8c2d3;
  --text: #152033;
  --muted: #6b778c;
  --primary: #0f766e;
  --primary-dark: #0a4f4a;
  --secondary: #d97706;
  --danger: #c0392b;
  --shadow: 0 18px 45px rgba(21, 32, 51, 0.08);
  --radius: 20px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Outfit", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(15, 118, 110, 0.12), transparent 26%),
    radial-gradient(circle at bottom right, rgba(217, 119, 6, 0.12), transparent 22%),
    var(--bg);
  position: relative;
  min-height: 100vh;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image: none;
  background-position: center;
  background-size: cover;
  background-repeat: no-repeat;
  opacity: 1;
  pointer-events: none;
  z-index: 0;
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  background: transparent;
  pointer-events: none;
  z-index: 0;
}

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

.app-shell {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100vh;
  position: relative;
  z-index: 1;
}

.sidebar {
  padding: 28px 22px;
  background: linear-gradient(180deg, #0e1727 0%, #14243b 100%);
  color: #f5f8ff;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 24px;
}

.brand-card {
  padding: 22px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.04);
  backdrop-filter: blur(14px);
}

.brand-card h1 {
  margin: 10px 0 8px;
  font-size: 1.7rem;
}

.brand-card p,
.brand-kicker {
  color: rgba(245, 248, 255, 0.78);
}

.brand-kicker,
.eyebrow,
.mini-heading {
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.72rem;
  font-weight: 600;
}

.nav-links {
  display: grid;
  gap: 10px;
  margin-top: 22px;
}

.nav-link {
  border: 0;
  border-radius: 14px;
  padding: 14px 16px;
  text-align: left;
  background: transparent;
  color: #d7dfef;
  cursor: pointer;
  transition: 0.2s ease;
}

.nav-link:hover,
.nav-link.active {
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
}

.sidebar-actions {
  display: grid;
  gap: 10px;
}

.main-content {
  padding: 28px;
}

.topbar,
.panel-header,
.line-items-head,
.modal-header,
.modal-actions,
.toolbar,
.topbar-actions,
.upload-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.topbar {
  margin-bottom: 24px;
}

.topbar h2,
.panel h3,
.line-items-head h4,
.modal-header h3 {
  margin: 6px 0 0;
}

.content-section {
  display: none;
}

.content-section.active {
  display: block;
}

.stats-grid,
.panel-grid,
.form-grid {
  display: grid;
  gap: 18px;
}

.stats-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 24px;
}

.panel-grid,
.form-grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

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

.form-grid.compact {
  align-content: start;
}

.form-grid.end {
  align-items: end;
}

.panel,
.stat-card,
.info-card,
.totals-card,
.modal-card {
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.9);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.panel {
  padding: 22px;
}

.stat-card {
  padding: 22px;
  display: grid;
  gap: 10px;
}

.stat-card strong {
  font-size: 2rem;
}

.stat-card span,
.panel p,
.info-card,
.client-info-card,
.empty-state {
  color: var(--muted);
}

.stat-card.accent {
  background: linear-gradient(135deg, #0f766e, #124e78);
  color: white;
}

.stat-card.accent span {
  color: rgba(255, 255, 255, 0.82);
}

.button,
.file-button {
  appearance: none;
  border: 0;
  border-radius: 14px;
  padding: 12px 16px;
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
  text-align: center;
}

.button:hover,
.file-button:hover {
  transform: translateY(-1px);
}

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

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

.button.ghost,
.button.subtle,
.file-button {
  background: var(--surface-soft);
  color: var(--text);
  border: 1px solid var(--line);
}

.button.danger {
  color: var(--danger);
}

.button.wide {
  width: 100%;
}

.input,
.textarea {
  width: 100%;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: white;
  color: var(--text);
}

.textarea {
  resize: vertical;
}

label {
  display: grid;
  gap: 8px;
  font-weight: 500;
}

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

.toolbar.multi {
  flex-wrap: wrap;
}

.toolbar input,
.toolbar select {
  min-width: 180px;
}

.list-preview {
  display: grid;
  gap: 12px;
}

.preview-row,
.client-info-card,
.totals-card > div {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.preview-row {
  padding: 14px 16px;
  border-radius: 16px;
  background: var(--surface-soft);
}

.client-info-card {
  flex-direction: column;
  min-height: 140px;
}

.line-items-block {
  margin: 22px 0;
}

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

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

.data-table th,
.data-table td {
  padding: 14px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

.data-table thead th {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  background: #f9fbfe;
}

.lines-table .input {
  min-width: 90px;
}

.mono {
  font-family: "IBM Plex Mono", monospace;
}

.price-stack,
.move-controls,
.quick-actions,
.upload-stack {
  display: grid;
  gap: 10px;
}

.price-mode-label {
  color: var(--muted);
}

.info-card {
  padding: 18px;
}

.totals-card {
  padding: 18px;
}

.totals-card > div {
  padding: 8px 0;
}

.totals-card .grand-total {
  margin-top: 8px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  font-size: 1.1rem;
}

.preview-stage {
  padding: 26px;
  background:
    linear-gradient(140deg, rgba(15, 118, 110, 0.08), transparent 36%),
    linear-gradient(320deg, rgba(217, 119, 6, 0.08), transparent 32%),
    #eff3f9;
  border-radius: 24px;
  overflow: auto;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

.invoice-preview {
  width: 210mm;
  min-height: 297mm;
  margin: 18px auto 0;
  background: white;
  color: #1b1b1b;
  position: relative;
  padding: 24mm 16mm 14mm;
  overflow: hidden;
  box-shadow: 0 18px 40px rgba(15, 23, 42, 0.18);
}

.invoice-watermark {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 1;
  pointer-events: none;
}

.invoice-watermark img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center center;
}

.invoice-inner {
  position: relative;
  z-index: 1;
  max-width: 180mm;
  margin: 0 auto;
  padding-top: 50px;
}

.invoice-head {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  margin-bottom: 18px;
  align-items: start;
}

.invoice-head h1 {
  margin: 0 0 10px;
  font-size: 2rem;
}

.invoice-head .invoice-client-box {
  margin-bottom: 0;
}

.invoice-meta,
.invoice-client-box,
.invoice-totals,
.invoice-signature,
.invoice-footer {
  border: 1px solid #cfd7e2;
  border-radius: 14px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.9);
}

.invoice-meta {
  display: grid;
  gap: 10px;
  align-content: start;
}

.invoice-client-box {
  margin-bottom: 16px;
}

.invoice-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 16px;
  background: #ffffff;
}

.invoice-table th,
.invoice-table td {
  border: 1px solid #cfd7e2;
  padding: 8px;
  font-size: 0.92rem;
  background: #ffffff;
}

.invoice-table thead th {
  background: #eef4f6;
}

.invoice-bottom {
  display: grid;
  grid-template-columns: 1.2fr 0.9fr;
  gap: 16px;
  align-items: start;
}

.invoice-totals .row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px dashed #d6dde8;
}

.invoice-totals .row:last-child {
  border-bottom: 0;
  font-weight: 700;
}

.invoice-signature {
  min-height: 110px;
  margin-top: 14px;
}

.invoice-signature img {
  max-height: 70px;
  max-width: 180px;
  object-fit: contain;
}

.invoice-footer {
  margin-top: 18px;
  font-size: 0.86rem;
  text-align: center;
}

.settings-form,
.invoice-form {
  display: grid;
  gap: 18px;
}

.upload-card {
  padding: 14px;
  border-radius: 16px;
  border: 1px dashed var(--line-strong);
  background: var(--surface-soft);
}

.modal {
  border: 0;
  padding: 0;
  background: transparent;
}

.modal::backdrop {
  background: rgba(12, 18, 28, 0.45);
}

.modal-card {
  width: min(640px, calc(100vw - 30px));
  padding: 22px;
}

.icon-button {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: white;
  cursor: pointer;
}

.empty-state {
  padding: 18px;
  background: var(--surface-soft);
  border: 1px dashed var(--line-strong);
  border-radius: 18px;
  margin-bottom: 14px;
}

.toast-container {
  position: fixed;
  top: 22px;
  right: 22px;
  display: grid;
  gap: 10px;
  z-index: 999;
}

.toast {
  min-width: 240px;
  padding: 14px 16px;
  border-radius: 16px;
  background: #10243d;
  color: white;
  box-shadow: var(--shadow);
}

.toast.success {
  background: #0f766e;
}

.toast.error {
  background: #b42318;
}

.hidden {
  display: none !important;
}

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

  .sidebar {
    padding-bottom: 18px;
  }

  .stats-grid,
  .panel-grid,
  .form-grid.two,
  .form-grid.three,
  .invoice-head,
  .invoice-bottom {
    grid-template-columns: 1fr;
  }

  .preview-stage {
    padding: 12px;
  }

  .invoice-preview {
    width: 100%;
    min-height: auto;
    margin-top: 12px;
    padding: 32px 24px 24px;
  }
}

@media (max-width: 760px) {
  .main-content {
    padding: 16px;
  }

  .panel,
  .stat-card {
    padding: 16px;
  }

  .topbar,
  .panel-header.responsive,
  .toolbar,
  .topbar-actions,
  .modal-actions {
    flex-direction: column;
    align-items: stretch;
  }
}

@media print {
  body {
    background: white;
  }

  body::before,
  body::after {
    display: none;
  }

  .sidebar,
  .topbar,
  .panel-header,
  .toast-container {
    display: none !important;
  }

  .main-content {
    padding: 0;
  }

  .content-section {
    display: none !important;
  }

  #preview-section {
    display: block !important;
  }

  .panel,
  .preview-stage {
    padding: 0;
    background: white;
    box-shadow: none;
    border: 0;
  }

  .invoice-preview {
    width: 210mm;
    min-height: 297mm;
    box-shadow: none;
    margin: 0;
  }
}
