:root {
  --bg: #f3efe6;
  --panel: #fffdf8;
  --sidebar: #1f3a37;
  --sidebar-text: #f4efe5;
  --text: #1f2220;
  --muted: #68706c;
  --line: #ded5c6;
  --accent: #c56b3d;
  --accent-deep: #8f4722;
  --success: #d7f0df;
  --success-text: #1d6a37;
  --error: #f5dedc;
  --error-text: #8b3025;
  --warning: #f9edd4;
  --warning-text: #8b6218;
  --bg-gradient-start: #f8f4ec;
  --bg-gradient-end: #efe7d9;
  --page-glow: rgba(197, 107, 61, 0.18);
  --panel-surface: rgba(255, 253, 248, 0.92);
  --panel-border-soft: rgba(222, 213, 198, 0.8);
  --soft-surface: rgba(31, 58, 55, 0.06);
  --chip-bg: rgba(31, 58, 55, 0.08);
  --chip-text: #224a46;
  --shadow: 0 24px 64px rgba(49, 39, 20, 0.08);
  --heading: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Palatino, Georgia, serif;
  --body: "Avenir Next", "Segoe UI", Helvetica, Arial, sans-serif;
}

body[data-theme="blue"] {
  --bg: #eef4fb;
  --panel: #fcfeff;
  --sidebar: #15324d;
  --sidebar-text: #f2f7fc;
  --text: #16212b;
  --muted: #5f7285;
  --line: #d5e1ec;
  --accent: #2e6fa3;
  --accent-deep: #1e4f78;
  --error: #f7e0e3;
  --error-text: #8c3040;
  --warning: #faedcc;
  --warning-text: #8a6116;
  --success: #d9f1e7;
  --success-text: #20684a;
  --bg-gradient-start: #f8fbff;
  --bg-gradient-end: #e7eff8;
  --page-glow: rgba(46, 111, 163, 0.18);
  --panel-surface: rgba(252, 254, 255, 0.94);
  --panel-border-soft: rgba(213, 225, 236, 0.9);
  --soft-surface: rgba(21, 50, 77, 0.06);
  --chip-bg: rgba(46, 111, 163, 0.14);
  --chip-text: #1e4f78;
  --shadow: 0 24px 64px rgba(21, 50, 77, 0.12);
}

body[data-theme="sage"] {
  --bg: #edf4ee;
  --panel: #fbfefb;
  --sidebar: #24433a;
  --sidebar-text: #eef5f1;
  --text: #1d2722;
  --muted: #61726a;
  --line: #d6e2da;
  --accent: #4f8a63;
  --accent-deep: #356046;
  --error: #f6dfe0;
  --error-text: #8a3240;
  --warning: #f8efcf;
  --warning-text: #7d6518;
  --success: #dcefe0;
  --success-text: #1f6940;
  --bg-gradient-start: #f8fcf8;
  --bg-gradient-end: #e6efe7;
  --page-glow: rgba(79, 138, 99, 0.18);
  --panel-surface: rgba(251, 254, 251, 0.94);
  --panel-border-soft: rgba(214, 226, 218, 0.9);
  --soft-surface: rgba(36, 67, 58, 0.06);
  --chip-bg: rgba(79, 138, 99, 0.14);
  --chip-text: #356046;
  --shadow: 0 24px 64px rgba(36, 67, 58, 0.1);
}

body[data-theme="rose"] {
  --bg: #f7edf1;
  --panel: #fffafc;
  --sidebar: #4a2436;
  --sidebar-text: #fdf0f6;
  --text: #2d1d25;
  --muted: #7f6672;
  --line: #e8d7df;
  --accent: #b65076;
  --accent-deep: #853653;
  --error: #f8dfe3;
  --error-text: #922f45;
  --warning: #faedd2;
  --warning-text: #876118;
  --success: #deefe4;
  --success-text: #246a49;
  --bg-gradient-start: #fff8fb;
  --bg-gradient-end: #f0e3e9;
  --page-glow: rgba(182, 80, 118, 0.18);
  --panel-surface: rgba(255, 250, 252, 0.94);
  --panel-border-soft: rgba(232, 215, 223, 0.9);
  --soft-surface: rgba(74, 36, 54, 0.06);
  --chip-bg: rgba(182, 80, 118, 0.14);
  --chip-text: #853653;
  --shadow: 0 24px 64px rgba(74, 36, 54, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--body);
  color: var(--text);
  background:
    radial-gradient(circle at top left, var(--page-glow), transparent 22rem),
    linear-gradient(180deg, var(--bg-gradient-start) 0%, var(--bg-gradient-end) 100%);
  overflow: hidden;
}

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

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

button {
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: white;
  padding: 0.85rem 1.2rem;
  cursor: pointer;
}

button:hover {
  background: var(--accent-deep);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.page-shell {
  display: flex;
  min-height: 100vh;
  height: 100vh;
}

.sidebar {
  width: 280px;
  padding: 2rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 2rem;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.05), transparent),
    var(--sidebar);
  color: var(--sidebar-text);
}

.sidebar-sticky {
  position: sticky;
  top: 0;
  align-self: flex-start;
  height: 100vh;
  overflow-y: auto;
}

.sidebar h1,
.content h1,
.content h2,
.content h3 {
  margin: 0;
  font-family: var(--heading);
  font-weight: 600;
}

.sidebar .eyebrow,
.sidebar .muted {
  color: rgba(255, 255, 255, 0.76);
}

.sidebar-logo {
  display: block;
  max-width: 150px;
  max-height: 150px;
  margin-bottom: 1rem;
  object-fit: contain;
}

.nav-links {
  display: grid;
  gap: 0.75rem;
}

.nav-links a {
  padding: 0.8rem 1rem;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.06);
}

.nav-links a:hover {
  background: rgba(255, 255, 255, 0.12);
}

.content {
  flex: 1;
  padding: 2rem;
  min-width: 0;
}

.content-scroll {
  height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
}

.content-auth {
  display: grid;
  place-items: center;
}

.sidebar-footer {
  display: grid;
  gap: 1rem;
}

.sidebar-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

.sidebar-actions form,
.sidebar-actions a,
.sidebar-actions button {
  width: 100%;
}

.sidebar-actions form {
  display: flex;
}

.sidebar-footer-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  appearance: none;
  -webkit-appearance: none;
  min-height: 48px;
  width: 100%;
  padding: 0.85rem 1.2rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: transparent;
  color: var(--sidebar-text);
  font: inherit;
  font-weight: 600;
  line-height: 1.2;
  text-align: center;
  text-decoration: none;
  box-shadow: none;
  transition: background 120ms ease, border-color 120ms ease;
}

.sidebar-footer-button:hover {
  background: rgba(255, 255, 255, 0.08);
}

body[data-theme="blue"] .sidebar-footer-button {
  background: rgba(255, 255, 255, 0.04);
  border-color: rgba(242, 247, 252, 0.32);
}

body[data-theme="blue"] .sidebar-footer-button:hover {
  background: rgba(255, 255, 255, 0.1);
}

.auth-card,
.panel,
.metric-card {
  background: var(--panel-surface);
  backdrop-filter: blur(10px);
  border: 1px solid var(--panel-border-soft);
  border-radius: 28px;
  box-shadow: var(--shadow);
}

.auth-card {
  width: min(100%, 560px);
  padding: 2.5rem;
}

.auth-alt {
  margin-top: 1rem;
  color: var(--muted);
}

.flash-stack {
  display: grid;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.flash {
  padding: 0.9rem 1rem;
  border-radius: 16px;
  font-weight: 600;
}

.flash-success {
  background: var(--success);
  color: var(--success-text);
}

.flash-error {
  background: var(--error);
  color: var(--error-text);
}

.page-header,
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.78rem;
  color: var(--muted);
  margin: 0 0 0.45rem;
}

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

.metric-grid,
.split-layout,
.panel-stack {
  display: grid;
  gap: 1.5rem;
}

.metric-grid {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  margin-bottom: 1.5rem;
}

.panel-stack {
  align-content: start;
}

.metric-card {
  padding: 1.4rem;
}

.metric-card span {
  color: var(--muted);
}

.metric-card strong {
  display: block;
  margin-top: 0.4rem;
  font-size: 2.3rem;
}

.split-layout {
  grid-template-columns: minmax(300px, 400px) minmax(0, 1fr);
}

.invoice-workspace {
  grid-template-columns: minmax(0, 1.15fr) minmax(360px, 0.95fr);
  align-items: start;
}

.split-layout-wide {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.panel {
  padding: 1.5rem;
}

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

.line-items-head {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 1rem;
}

.invoice-line-list {
  display: grid;
  gap: 0.9rem;
}

.invoice-line-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.8rem;
  align-items: end;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.7);
}

.invoice-line-row .remove-line-button {
  grid-column: 1 / -1;
  justify-self: start;
}

.invoice-note {
  display: grid;
  align-content: center;
}

.add-line-button {
  white-space: nowrap;
}

.remove-line-button {
  align-self: center;
}

.stacked-form label,
.grid-two label {
  display: grid;
  gap: 0.4rem;
  font-weight: 600;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: white;
  padding: 0.85rem 1rem;
}

textarea {
  resize: vertical;
}

.checkbox {
  grid-template-columns: auto 1fr;
  align-items: center;
}

.checkbox input {
  width: auto;
}

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

.button-row,
.actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.7rem;
}

.danger-border {
  border-color: rgba(156, 47, 47, 0.3);
  color: #9c2f2f;
}

.theme-form {
  display: grid;
  gap: 0.6rem;
}

.theme-toggle {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.6rem;
}

.theme-option {
  background: var(--theme-gradient);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.3);
  padding: 0.75rem 0.9rem;
  justify-content: center;
  font-weight: 600;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18);
  transition: transform 120ms ease, box-shadow 120ms ease, filter 120ms ease;
}

.theme-option:hover {
  background: var(--theme-gradient);
  transform: translateY(-1px);
  filter: saturate(1.06) brightness(1.02);
}

.theme-option.is-active {
  border-color: rgba(255, 255, 255, 0.78);
  box-shadow:
    0 0 0 3px rgba(31, 34, 32, 0.08),
    0 14px 28px rgba(31, 34, 32, 0.12);
  transform: translateY(-1px);
}

.theme-option[data-theme-option="warm"] {
  --theme-gradient: linear-gradient(135deg, #e7c8a9 0%, #c56b3d 55%, #8f4722 100%);
}

.theme-option[data-theme-option="blue"] {
  --theme-gradient: linear-gradient(135deg, #7eb2da 0%, #2e6fa3 55%, #15324d 100%);
}

.theme-option[data-theme-option="sage"] {
  --theme-gradient: linear-gradient(135deg, #9fc8ab 0%, #4f8a63 55%, #24433a 100%);
}

.theme-option[data-theme-option="rose"] {
  --theme-gradient: linear-gradient(135deg, #d796b1 0%, #b65076 55%, #4a2436 100%);
}

.anchor-button,
.ghost-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.85rem 1.2rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: transparent;
  color: inherit;
  cursor: pointer;
}

.ghost-button {
  background: transparent;
  color: var(--sidebar-text);
  border-color: rgba(255, 255, 255, 0.25);
}

.ghost-button:hover {
  background: rgba(255, 255, 255, 0.08);
}

.anchor-button {
  color: var(--text);
  border-color: var(--line);
}

.anchor-button:hover {
  background: transparent;
}

.text-link,
.text-button {
  color: var(--accent-deep);
  font-weight: 700;
}

.text-button {
  padding: 0;
  background: none;
}

.text-button:hover {
  background: none;
}

.danger {
  color: #9c2f2f;
}

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

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

th,
td {
  padding: 0.9rem 0.75rem;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.invoice-history-row:target td {
  background: var(--soft-surface);
}

th {
  color: var(--muted);
  font-weight: 700;
}

.status-chip {
  display: inline-flex;
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  background: var(--chip-bg);
  color: var(--chip-text);
  text-transform: capitalize;
  font-size: 0.9rem;
}

.inline-note,
.empty-state {
  padding: 1rem;
  border-radius: 18px;
  background: var(--soft-surface);
}

.logo-preview-card,
.invoice-brand,
.invoice-meta-grid,
.invoice-summary-grid,
.feature-list,
.summary-card-spaced {
  display: grid;
  gap: 1rem;
}

.logo-preview-card {
  align-items: center;
  grid-template-columns: minmax(0, 160px) minmax(0, 1fr);
  margin-bottom: 1rem;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.7);
}

.logo-preview-image,
.invoice-logo {
  width: 100%;
  max-width: 160px;
  max-height: 92px;
  object-fit: contain;
}

.invoice-sheet {
  display: grid;
  gap: 1.5rem;
}

.invoice-sheet-head {
  display: grid;
  gap: 1.5rem;
}

.invoice-brand {
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
}

.invoice-summary-grid {
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
}

.summary-card {
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.72);
}

.summary-card-spaced {
  margin-bottom: 1rem;
}

.feature-item {
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.72);
}

.summary-card span {
  display: block;
  color: var(--muted);
  margin-bottom: 0.5rem;
}

.summary-card strong {
  font-size: 1.1rem;
}

.invoice-meta-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.invoice-line {
  margin: 0 0 0.35rem;
}

.invoice-payment-options {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  margin-top: 1rem;
}

.payment-method-value {
  margin: 0.5rem 0 0;
  white-space: pre-line;
}

.invoice-memo {
  padding: 1rem;
  border-radius: 20px;
  background: var(--soft-surface);
}

.warning {
  background: var(--warning);
  color: var(--warning-text);
}

@media (max-width: 960px) {
  body {
    overflow: auto;
  }

  .page-shell {
    flex-direction: column;
    height: auto;
  }

  .sidebar {
    width: 100%;
  }

  .sidebar-sticky,
  .content-scroll {
    position: static;
    height: auto;
    overflow: visible;
  }

  .split-layout {
    grid-template-columns: 1fr;
  }

  .split-layout-wide,
  .invoice-meta-grid,
  .invoice-brand {
    grid-template-columns: 1fr;
  }

  .invoice-line-row {
    grid-template-columns: 1fr;
  }

  .line-items-head {
    display: grid;
    align-items: stretch;
  }
}

@media (max-width: 1240px) {
  .invoice-workspace {
    grid-template-columns: 1fr;
  }
}
