/* ═══════════════════════════════════════════
   ROOT & RESET
═══════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #f0f2f5;
  --surface: #ffffff;
  --surface2: #f7f8fa;
  --surface3: #eef0f4;
  --border: #e2e5eb;
  --border2: #cdd1da;
  --accent: #2563eb;
  --accent2: #1d4ed8;
  --accent-pale: rgba(37,99,235,0.07);
  --text: #111827;
  --text2: #4b5563;
  --text3: #9ca3af;
  --white: #ffffff;
  --green: #16a34a;
  --red: #dc2626;
  --font-ui: 'Syne', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  --r: 10px;
  --r-lg: 16px;
}
html { scroll-behavior: smooth; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  min-height: 100vh;
  overflow-x: hidden;
}
input, textarea, select, button { font-family: inherit; }
button { cursor: pointer; }
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--surface); }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }

/* ═══════════════════════════════════════════
   LAYOUT
═══════════════════════════════════════════ */
.app { display: flex; flex-direction: column; min-height: 100vh; }

/* TOP BAR */
.topbar {
  height: 60px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 24px; gap: 16px;
  position: sticky; top: 0; z-index: 200;
}
.topbar-logo {
  font-size: 18px; font-weight: 800; letter-spacing: -0.5px;
  color: var(--text);
}
.topbar-logo span { color: var(--accent); }
.topbar-sep { width: 1px; height: 24px; background: var(--border); }
.topbar-title { font-size: 13px; color: var(--text2); font-weight: 500; }
.topbar-actions { margin-left: auto; display: flex; gap: 10px; align-items: center; }

/* MAIN SPLIT */
.main-split {
  display: flex;
  flex: 1;
  height: calc(100vh - 60px);
}

/* SIDEBAR */
.sidebar {
  width: 380px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

/* PREVIEW AREA */
.preview-area {
  flex: 1;
  background: #e4e7ed;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 32px 24px;
  gap: 20px;
}
.preview-toolbar {
  width: 100%;
  max-width: 860px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.preview-label {
  font-size: 11px; font-weight: 700; letter-spacing: 1.5px;
  text-transform: uppercase; color: var(--text3);
  margin-right: auto;
}
.preview-wrapper {
  width: 100%;
  max-width: 860px;
  background: white;
  border-radius: var(--r-lg);
  overflow: hidden;
  box-shadow: 0 24px 80px rgba(0,0,0,0.18);
}

/* ═══════════════════════════════════════════
   SIDEBAR COMPONENTS
═══════════════════════════════════════════ */
.sidebar-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  padding: 0 4px;
  gap: 2px;
  flex-shrink: 0;
  overflow-x: auto;
}
.stab {
  padding: 14px 14px 13px;
  font-size: 12px; font-weight: 600; letter-spacing: 0.3px;
  color: var(--text3);
  border: none; background: none;
  border-bottom: 2px solid transparent;
  cursor: pointer; white-space: nowrap;
  transition: color 0.2s;
}
.stab:hover { color: var(--text2); }
.stab.active { color: var(--accent); border-bottom-color: var(--accent); }

.tab-panel { display: none; flex-direction: column; gap: 0; flex: 1; }
.tab-panel.active { display: flex; }

/* SECTION */
.s-section {
  border-bottom: 1px solid var(--border);
  padding: 16px 20px;
}
.s-section-title {
  font-size: 10px; font-weight: 700; letter-spacing: 1.8px;
  text-transform: uppercase; color: var(--text3);
  margin-bottom: 12px;
  display: flex; align-items: center; gap: 6px;
}
.s-section-title .icon { font-size: 12px; }

/* FORM ELEMENTS */
.form-row { display: flex; gap: 8px; margin-bottom: 8px; }
.form-row:last-child { margin-bottom: 0; }
.form-col { flex: 1; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.form-label {
  font-size: 10px; font-weight: 600; letter-spacing: 0.8px;
  text-transform: uppercase; color: var(--text3);
}
.form-input, .form-select, .form-textarea {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 9px 12px;
  font-size: 13px; font-weight: 400;
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
  width: 100%;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--accent);
}
.form-input::placeholder, .form-textarea::placeholder { color: var(--text3); }
.form-textarea { resize: vertical; min-height: 60px; line-height: 1.5; }
.form-select { appearance: none; cursor: pointer; }
.form-select option { background: var(--surface); color: var(--text); }

/* COLOR SWATCH */
.color-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.color-swatch {
  width: 28px; height: 28px;
  border-radius: 8px;
  cursor: pointer;
  border: 2px solid transparent;
  transition: transform 0.15s, border-color 0.15s;
  flex-shrink: 0;
}
.color-swatch:hover { transform: scale(1.12); }
.color-swatch.active { border-color: white; transform: scale(1.1); }
.color-picker-wrap { position: relative; }
.color-picker-wrap input[type=color] {
  width: 28px; height: 28px;
  border-radius: 8px; border: 2px solid var(--border);
  padding: 2px; cursor: pointer; background: none;
}

/* TOGGLE */
.toggle-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 0;
}
.toggle-label { font-size: 13px; color: var(--text2); }
.toggle {
  position: relative; width: 36px; height: 20px;
  display: inline-block;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; inset: 0;
  background: var(--surface3); border-radius: 99px;
  transition: background 0.2s; cursor: pointer;
}
.toggle-slider::before {
  content: ''; position: absolute;
  width: 14px; height: 14px;
  left: 3px; top: 3px;
  background: white; border-radius: 50%;
  transition: transform 0.2s;
}
.toggle input:checked + .toggle-slider { background: var(--accent); }
.toggle input:checked + .toggle-slider::before { transform: translateX(16px); }

/* ITEMS TABLE */
.items-table { width: 100%; }
.items-header {
  display: grid;
  gap: 6px; margin-bottom: 6px;
}
.items-header span {
  font-size: 10px; font-weight: 700; letter-spacing: 1px;
  text-transform: uppercase; color: var(--text3);
}
.item-row {
  display: grid;
  gap: 6px; margin-bottom: 6px; align-items: center;
}
.item-input {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 8px;
  font-size: 12px; color: var(--text);
  outline: none; width: 100%;
  transition: border-color 0.2s;
}
.item-input:focus { border-color: var(--accent); }
.item-del {
  width: 24px; height: 24px;
  background: none; border: none;
  color: var(--text3); font-size: 16px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  border-radius: 6px;
  transition: background 0.15s, color 0.15s;
}
.item-del:hover { background: rgba(239,68,68,0.12); color: var(--red); }

.btn-add-item {
  background: var(--accent-pale);
  border: 1px dashed rgba(244,169,31,0.3);
  border-radius: 8px;
  padding: 8px;
  font-size: 12px; font-weight: 600; color: var(--accent);
  width: 100%; text-align: center;
  transition: background 0.2s;
  margin-top: 4px;
}
.btn-add-item:hover { background: rgba(244,169,31,0.14); }

/* TEMPLATE GRID */
.template-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 16px 20px;
}
.tpl-card {
  border: 2px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.2s, transform 0.15s, box-shadow 0.2s;
  background: var(--surface2);
  position: relative;
}
.tpl-card:hover { border-color: var(--border2); transform: translateY(-2px); }
.tpl-card.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.tpl-thumb {
  height: 120px;
  display: flex; flex-direction: column;
  padding: 8px;
  gap: 4px;
  overflow: hidden;
}
.tpl-name {
  font-size: 11px; font-weight: 600; color: var(--text2);
  padding: 6px 8px;
  border-top: 1px solid var(--border);
  text-align: center;
}
.tpl-badge {
  position: absolute; top: 6px; right: 6px;
  font-size: 9px; font-weight: 700; letter-spacing: 0.5px;
  text-transform: uppercase;
  background: var(--accent); color: #000;
  padding: 2px 6px; border-radius: 4px;
}
.tpl-category {
  font-size: 10px; font-weight: 700; letter-spacing: 1.5px;
  text-transform: uppercase; color: var(--text3);
  padding: 14px 20px 6px; grid-column: 1/-1;
}

/* BUTTONS */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 18px; border-radius: var(--r);
  font-size: 13px; font-weight: 600; border: none;
  transition: all 0.15s;
  white-space: nowrap;
}
.btn-accent { background: var(--accent); color: #000; }
.btn-accent:hover { background: var(--accent2); }
.btn-outline {
  background: var(--surface2);
  border: 1px solid var(--border2);
  color: var(--text);
}
.btn-outline:hover { background: var(--surface3); border-color: var(--text3); }
.btn-sm { padding: 7px 14px; font-size: 12px; }
.btn-ghost { background: none; border: 1px solid var(--border); color: var(--text2); }
.btn-ghost:hover { border-color: var(--border2); color: var(--text); }
.btn-green { background: var(--green); color: #000; }
.btn-green:hover { background: #16a34a; }

/* LOGO UPLOAD */
.logo-upload {
  border: 2px dashed var(--border2);
  border-radius: var(--r);
  padding: 16px;
  text-align: center; cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  position: relative; overflow: hidden;
}
.logo-upload:hover { border-color: var(--accent); background: var(--accent-pale); }
.logo-upload input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.logo-upload-icon { font-size: 24px; margin-bottom: 6px; }
.logo-upload-text { font-size: 12px; color: var(--text3); }
.logo-preview { max-height: 60px; max-width: 160px; object-fit: contain; border-radius: 6px; }

/* FONT SELECT */
.font-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.font-opt {
  border: 1.5px solid var(--border);
  border-radius: 8px; padding: 8px 10px;
  cursor: pointer; transition: all 0.15s;
  background: var(--surface2);
}
.font-opt:hover { border-color: var(--border2); }
.font-opt.active { border-color: var(--accent); background: var(--accent-pale); }
.font-opt-name { font-size: 12px; font-weight: 600; color: var(--text2); margin-bottom: 2px; }
.font-opt-sample { font-size: 14px; color: var(--text3); }

/* NOTES */
.notes-area { font-size: 12px; }

/* ═══════════════════════════════════════════
   INVOICE TEMPLATES (inside white preview)
═══════════════════════════════════════════ */
#invoice-preview {
  background: white;
  width: 100%;
  min-height: 900px;
  position: relative;
  font-family: 'Lato', sans-serif;
  color: #1a1a2e;
}

/* Template rendering happens in JS */

/* ═══════════════════════════════════════════
   MODAL
═══════════════════════════════════════════ */
.modal-overlay {
  position: fixed; inset: 0; z-index: 500;
  background: rgba(0,0,0,0.35);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s;
}
.modal-overlay.open { opacity: 1; pointer-events: all; }
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 28px;
  max-width: 480px; width: 100%;
  transform: scale(0.95);
  transition: transform 0.2s;
}
.modal-overlay.open .modal { transform: scale(1); }
.modal-title { font-size: 18px; font-weight: 700; margin-bottom: 6px; }
.modal-sub { font-size: 13px; color: var(--text2); margin-bottom: 20px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }

/* TOAST */
.toast {
  position: fixed; bottom: 24px; right: 24px; z-index: 9999;
  background: #1f2937;
  border: 1px solid #374151;
  border-radius: var(--r);
  padding: 12px 18px;
  font-size: 13px; color: #f9fafb;
  display: flex; align-items: center; gap: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.15);
  transform: translateY(80px); opacity: 0;
  transition: all 0.3s;
}
.toast.show { transform: translateY(0); opacity: 1; }
.toast.success { border-color: var(--green); }
.toast.success .toast-icon { color: var(--green); }

/* RANGE SLIDER */
input[type=range] {
  width: 100%; -webkit-appearance: none;
  height: 4px; border-radius: 2px;
  background: var(--surface3); outline: none;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--accent); cursor: pointer;
}

/* BADGE PRO */
.pro-badge {
  font-size: 9px; font-weight: 700;
  background: linear-gradient(135deg, #f4a91f, #e05d0a);
  color: #000; padding: 2px 6px; border-radius: 4px;
  letter-spacing: 0.5px;
}

/* LOADING */
.loading-overlay {
  position: fixed; inset: 0; z-index: 9998;
  background: rgba(255,255,255,0.85);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 16px;
  opacity: 0; pointer-events: none; transition: opacity 0.2s;
}
.loading-overlay.show { opacity: 1; pointer-events: all; }
.loading-spinner {
  width: 44px; height: 44px;
  border: 3px solid var(--surface3);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { font-size: 14px; color: var(--text2); }


/* ═══════════════════════════════════════════
   DARK MODE
═══════════════════════════════════════════ */
body.dark-mode {
  --bg: #0d1117;
  --surface: #161b22;
  --surface2: #1c2128;
  --surface3: #21262d;
  --border: #30363d;
  --border2: #484f58;
  --accent: #58a6ff;
  --accent2: #388bfd;
  --accent-pale: rgba(88,166,255,0.1);
  --text: #e6edf3;
  --text2: #8b949e;
  --text3: #6e7681;
  --white: #1c2128;
  --green: #3fb950;
  --red: #f85149;
}

/* ═══════════════════════════════════════════
   NEW HEADER (replaces old topbar)
═══════════════════════════════════════════ */
.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 200;
}
.header-brand {
  display: flex; align-items: center;
  padding: 0 24px;
  height: 56px;
  gap: 14px;
  border-bottom: 1px solid var(--border);
}
.header-logo-icon {
  width: 34px; height: 34px;
  background: linear-gradient(135deg, var(--accent), #7c3aed);
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(37,99,235,0.3);
}
.header-logo-text {
  font-size: 17px; font-weight: 800; letter-spacing: -0.5px;
  color: var(--text);
  line-height: 1;
}
.header-logo-text span { color: var(--accent); }
.header-tagline {
  font-size: 11px; color: var(--text3); font-weight: 500;
  letter-spacing: 0.2px;
  margin-top: 1px;
}
.header-theme-toggle {
  margin-left: auto;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 12px; font-weight: 600;
  color: var(--text2);
  cursor: pointer;
  display: flex; align-items: center; gap: 6px;
  transition: all 0.2s;
}
.header-theme-toggle:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.header-actions {
  display: flex; align-items: center;
  padding: 0 24px;
  height: 44px;
  gap: 8px;
}
.header-actions-left { margin-right: auto; display: flex; gap: 8px; }

/* ═══════════════════════════════════════════
   SECTION TABS (how to use / faq)
═══════════════════════════════════════════ */
.info-section {
  background: var(--bg);
  border-top: 1px solid var(--border);
  padding: 60px 24px;
}
.info-section .container {
  max-width: 960px;
  margin: 0 auto;
}
.info-section-title {
  font-size: 28px; font-weight: 800; letter-spacing: -0.5px;
  color: var(--text); margin-bottom: 8px;
  text-align: center;
}
.info-section-sub {
  font-size: 14px; color: var(--text2);
  text-align: center; margin-bottom: 40px;
}
.how-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 20px;
  margin-bottom: 60px;
}
.how-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px 20px;
  text-align: center;
}
.how-card-num {
  width: 40px; height: 40px;
  background: linear-gradient(135deg, var(--accent), #7c3aed);
  color: white; font-weight: 800; font-size: 16px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 14px;
}
.how-card-title {
  font-size: 14px; font-weight: 700; color: var(--text);
  margin-bottom: 6px;
}
.how-card-desc {
  font-size: 12px; color: var(--text2); line-height: 1.6;
}
.faq-list { display: flex; flex-direction: column; gap: 12px; }
.faq-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}
.faq-q {
  padding: 16px 20px;
  font-size: 14px; font-weight: 600; color: var(--text);
  cursor: pointer;
  display: flex; justify-content: space-between; align-items: center;
  user-select: none;
}
.faq-q:hover { background: var(--surface2); }
.faq-arrow { font-size: 12px; color: var(--text3); transition: transform 0.2s; }
.faq-item.open .faq-arrow { transform: rotate(180deg); }
.faq-a {
  display: none;
  padding: 0 20px 16px;
  font-size: 13px; color: var(--text2); line-height: 1.7;
  border-top: 1px solid var(--border);
  padding-top: 14px;
}
.faq-item.open .faq-a { display: block; }

/* ═══════════════════════════════════════════
   FOOTER
═══════════════════════════════════════════ */
.site-footer {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 40px 24px 24px;
}
.footer-inner {
  max-width: 960px; margin: 0 auto;
}
.footer-top {
  display: grid;
  grid-template-columns: 1.5fr 1fr 1fr 1fr;
  gap: 32px;
  padding-bottom: 32px;
  border-bottom: 1px solid var(--border);
}
@media(max-width:700px){
  .footer-top { grid-template-columns: 1fr 1fr; }
}
.footer-brand-desc {
  font-size: 12px; color: var(--text3); line-height: 1.7;
  margin-top: 10px;
}
.footer-col-title {
  font-size: 11px; font-weight: 700; letter-spacing: 1.2px;
  text-transform: uppercase; color: var(--text3);
  margin-bottom: 12px;
}
.footer-links { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.footer-links li a {
  font-size: 13px; color: var(--text2); text-decoration: none;
  transition: color 0.15s;
}
.footer-links li a:hover { color: var(--accent); }
.footer-bottom {
  display: flex; justify-content: space-between; align-items: center;
  padding-top: 20px; flex-wrap: wrap; gap: 8px;
}
.footer-copy { font-size: 12px; color: var(--text3); }
.footer-badges { display: flex; gap: 8px; }
.footer-badge {
  font-size: 10px; font-weight: 700; letter-spacing: 0.5px;
  background: var(--surface2); border: 1px solid var(--border);
  color: var(--text3); padding: 4px 10px; border-radius: 6px;
}

/* RESPONSIVE */
@media (max-width: 900px) {
  .main-split { flex-direction: column; height: auto; }
  .sidebar { width: 100%; max-height: 60vh; }
  .preview-area { padding: 20px 12px; }
}
