:root {
  color-scheme: light;
  --bg: #f8fafc;
  --panel: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --success: #059669;
  --danger: #dc2626;
  --warning: #d97706;
  --sidebar-w: 248px;
  --sidebar-bg: #0b1220;
  --sidebar-border: #1e293b;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.hidden { display: none !important; }

/* ── Login ── */
.login-screen {
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-height: 100vh;
}

.login-left {
  background: linear-gradient(145deg, #0b1220 0%, #1e3a5f 50%, #2563eb 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px;
  color: #fff;
}

.login-brand {
  max-width: 360px;
}

.login-mark, .brand-mark {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: rgba(255,255,255,.15);
  backdrop-filter: blur(8px);
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 16px;
  letter-spacing: -.03em;
  margin-bottom: 24px;
}

.login-brand h1 {
  margin: 0 0 12px;
  font-size: 36px;
  font-weight: 700;
  letter-spacing: -.02em;
}

.login-brand p {
  margin: 0;
  font-size: 16px;
  line-height: 1.6;
  color: rgba(255,255,255,.75);
}

.login-right {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px 32px;
  background: #fff;
}

.login-form {
  width: min(100%, 380px);
  display: grid;
  gap: 16px;
}

.login-form h2 {
  margin: 0;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -.02em;
}

.login-lead {
  margin: -8px 0 8px;
  color: var(--muted);
  font-size: 15px;
}

.login-form label {
  display: grid;
  gap: 6px;
  font-size: 14px;
  font-weight: 500;
}

.login-form input {
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font: inherit;
  transition: border-color .15s, box-shadow .15s;
}

.login-form input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}

/* ── App shell ── */
.shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 10;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 16px;
  border-bottom: 1px solid var(--sidebar-border);
}

.brand-mark {
  margin-bottom: 0;
  flex-shrink: 0;
  font-size: 14px;
}

.brand-title {
  font-size: 15px;
  font-weight: 700;
  color: #f8fafc;
}

.brand-user {
  font-size: 12px;
  color: #64748b;
  margin-top: 2px;
}

.brand-org {
  font-size: 11px;
  color: #475569;
  margin-top: 2px;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 12px 10px;
}

.nav-group {
  margin-bottom: 16px;
}

.nav-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: #475569;
  padding: 0 10px 6px;
}

.nav-item {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  color: #94a3b8;
  padding: 9px 10px;
  border-radius: 8px;
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  transition: background .12s, color .12s;
}

.nav-item:hover {
  background: #1e293b;
  color: #e2e8f0;
}

.nav-item.active {
  background: var(--primary);
  color: #fff;
  font-weight: 500;
}

.nav-item.subtle {
  font-size: 13px;
  color: #64748b;
}

.sidebar-footer {
  padding: 10px;
  border-top: 1px solid var(--sidebar-border);
  display: grid;
  gap: 2px;
}

.main {
  flex: 1;
  margin-left: var(--sidebar-w);
  padding: 28px 32px 48px;
  min-width: 0;
}

.page-intro {
  margin-bottom: 24px;
}

.page-intro h2 {
  margin: 0;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -.02em;
}

.page-intro p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
}

.stat-card .label { color: var(--muted); font-size: 13px; }
.stat-card .value { font-size: 22px; font-weight: 700; margin-top: 6px; }

.stat-card.highlight {
  border-color: #bfdbfe;
  background: linear-gradient(180deg, #eff6ff 0%, var(--panel) 100%);
}

.stat-card.highlight .value {
  color: #1d4ed8;
}

.dashboard-intro {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.login-divider {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 12px;
  align-items: center;
  color: var(--muted);
  font-size: 13px;
  margin: 16px 0;
}

.login-divider::before,
.login-divider::after {
  content: "";
  height: 1px;
  background: var(--border);
}

.btn-google {
  background: #fff;
  color: #1f2937;
  border: 1px solid var(--border);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 600;
}

.btn-google::before {
  content: "G";
  display: inline-flex;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #4285f4;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  align-items: center;
  justify-content: center;
}

#googleLoginBtn:not(.hidden) {
  margin-bottom: 4px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  margin-bottom: 20px;
}

.panel-head {
  margin-bottom: 14px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.panel-head h3 { margin: 0; font-size: 16px; font-weight: 600; flex: 1; }

.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 20px;
}

.form {
  display: grid;
  gap: 12px;
}

.form-wide { max-width: 540px; }

.form label {
  display: grid;
  gap: 6px;
  font-size: 14px;
  font-weight: 500;
}

.form input,
.form select,
.form textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
}

.checkbox {
  display: flex !important;
  align-items: center;
  gap: 8px;
  font-weight: 400 !important;
}

.checkbox input { width: auto; }

.line-items { display: grid; gap: 8px; }

.line-items-block {
  display: grid;
  gap: 8px;
}

.line-item {
  display: grid;
  grid-template-columns: 2fr 72px 110px;
  gap: 8px;
  align-items: end;
}

.line-item-field {
  display: grid;
  gap: 4px;
  margin: 0;
}

.line-item-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  background: var(--primary);
  color: white;
}

.btn:hover { background: var(--primary-dark); }
.btn-block { width: 100%; padding: 13px; font-size: 15px; border-radius: 10px; }
.btn.secondary { background: #eff6ff; color: var(--primary); }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn.danger { background: #fee2e2; color: var(--danger); }
.btn.saved {
  background: #047857;
  border-color: #047857;
  color: #fff;
  cursor: default;
}
.btn.saved:hover { background: #047857; }

.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.badge.ok { background: #d1fae5; color: var(--success); }
.badge.warn { background: #fef3c7; color: var(--warning); }
.badge.bad { background: #fee2e2; color: var(--danger); }

.connection-status {
  margin-bottom: 16px;
  padding: 12px 14px;
  border-radius: 10px;
  background: #f8fafc;
  border: 1px solid var(--border);
  font-size: 14px;
}

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

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th, td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
}

th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }

.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.status-bar {
  margin-bottom: 16px;
  padding: 11px 14px;
  border-radius: 10px;
  font-size: 14px;
}

.status-bar.info { background: #eff6ff; color: #1d4ed8; }
.status-bar.success { background: #ecfdf5; color: #047857; }
.status-bar.error { background: #fef2f2; color: #b91c1c; }

.form-error {
  margin: 0;
  color: var(--danger);
  font-size: 14px;
}

.design-layout {
  display: grid;
  grid-template-columns: 200px minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}

.design-nav {
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: sticky;
  top: 0;
}

.design-nav-item {
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: 10px;
  padding: 12px 14px;
  text-align: left;
  font: inherit;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  color: var(--text);
}

.design-nav-item:hover { border-color: #93c5fd; background: #f8fafc; }
.design-nav-item.active {
  border-color: var(--primary);
  background: #eff6ff;
  color: var(--primary);
}

.design-panels { min-width: 0; }

.design-panel { display: none; }
.design-panel.active { display: block; }

.design-panel .panel { margin-bottom: 0; }

.logo-field {
  display: grid;
  gap: 10px;
}

.logo-field .field-label {
  font-size: 14px;
  font-weight: 600;
}

.logo-preview-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #f8fafc;
}

.logo-preview-wrap img {
  max-height: 48px;
  max-width: 180px;
  object-fit: contain;
}

.file-upload-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: fit-content;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px dashed #93c5fd;
  background: #eff6ff;
  color: var(--primary);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}

.file-upload-btn:hover { background: #dbeafe; }

.addon-templates-list,
.invoice-addons-section {
  display: grid;
  gap: 12px;
}

.addon-template-row,
.invoice-addon-row {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #f8fafc;
}

.addon-template-row {
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  align-items: end;
}

.invoice-addons-section .section-label {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 4px;
}

.invoice-addon-row .addon-enable {
  margin: 0;
}

.customer-mode {
  border: none;
  margin: 0;
  padding: 0;
}

.customer-mode legend {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 8px;
}

.segmented {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.segmented label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}

.segmented label:has(input:checked) {
  border-color: var(--primary);
  background: #eff6ff;
  color: var(--primary);
}

.segmented input { margin: 0; }

.invoice-preview {
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  max-width: 520px;
  width: 100%;
}

.preview-header { padding: 20px; color: #fff; }
.preview-body { padding: 20px; background: #fff; }
.preview-footer {
  padding: 12px 20px;
  background: #f8fafc;
  color: var(--muted);
  font-size: 13px;
  border-top: 1px solid var(--border);
}

.panel-span { grid-column: 1 / -1; }

.field-hint {
  margin: -6px 0 0;
  font-size: 13px;
  color: var(--muted);
}

.search-input {
  width: 100%;
  margin-top: 10px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
}

.contacts-layout {
  display: grid;
  grid-template-columns: minmax(260px, 340px) 1fr;
  gap: 20px;
  align-items: start;
}

.contacts-list {
  display: grid;
  gap: 6px;
  max-height: 620px;
  overflow-y: auto;
}

.contact-row {
  width: 100%;
  text-align: left;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 10px;
  padding: 12px 14px;
  cursor: pointer;
  font: inherit;
  transition: border-color .12s, background .12s;
}

.contact-row:hover { border-color: #93c5fd; background: #f8fafc; }
.contact-row.active { border-color: var(--primary); background: #eff6ff; }

.contact-row-name { font-weight: 600; font-size: 14px; }
.contact-row-meta { font-size: 12px; color: var(--muted); margin-top: 4px; }

.form-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 4px 0;
}

@media (max-width: 900px) {
  .contacts-layout { grid-template-columns: 1fr; }
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 24px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, .45);
}

.modal-card {
  position: relative;
  width: min(100%, 420px);
  background: #fff;
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 24px 60px rgba(0,0,0,.18);
}

.modal-card h3 {
  margin: 0 0 8px;
  font-size: 18px;
}

.modal-message {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
}

@media (max-width: 768px) {
  .login-screen { grid-template-columns: 1fr; }
  .login-left { min-height: 200px; padding: 32px 24px; }
  .login-left h1 { font-size: 28px; }
  :root { --sidebar-w: 200px; }
  .main { padding: 20px 16px 40px; }
  .line-item { grid-template-columns: 1fr; }
  .line-item-field { margin-bottom: 4px; }
  .design-layout { grid-template-columns: 1fr; }
  .design-nav { flex-direction: row; flex-wrap: wrap; position: static; }
}
