/* ==========================================================================
   Utility Classes
   ========================================================================== */
/* Tailwind handles these */
/* Remove old conflicting styles that were replaced by Tailwind */
/* These were hiding the right panel elements */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --accent:       #2563eb;
  --accent-light: #eff6ff;
  --accent-dark:  #1d4ed8;
  --bg:           #f8fafc;
  --surface:      #ffffff;
  --border:       #e2e8f0;
  --text:         #1e293b;
  --text-muted:   #64748b;
  --danger:       #dc2626;
  --success:      #059669;
  --radius:       8px;
  --shadow:       0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md:    0 4px 6px -1px rgba(0,0,0,.08), 0 2px 4px -1px rgba(0,0,0,.06);
  --shadow-lg:    0 10px 25px -5px rgba(0,0,0,.12), 0 4px 8px -2px rgba(0,0,0,.06);
  --topbar-h:     56px;
}

html, body {
  height: 100%;
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  /* overflow: hidden; */ /* Removing to allow individual panels to scroll */
}

/* ─────────────────── SCROLLBAR ─────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ═══════════════════════════════════════════════════════════
   TOP BAR
   ═══════════════════════════════════════════════════════════ */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 16px;
  z-index: 100;
  box-shadow: var(--shadow);
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  flex-shrink: 0;
}
.topbar-brand i { font-size: 20px; }

.template-selector {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  justify-content: center;
}
.template-selector .label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .5px;
}
.tpl-options {
  display: flex;
  gap: 4px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 3px;
}
.tpl-btn {
  padding: 5px 14px;
  border: none;
  border-radius: 6px;
  background: transparent;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  color: var(--text-muted);
  transition: all .2s;
  display: flex;
  align-items: center;
  gap: 5px;
}
.tpl-btn:hover { background: var(--surface); color: var(--text); }
.tpl-btn.active {
  background: var(--surface);
  color: var(--accent);
  box-shadow: var(--shadow);
  font-weight: 600;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* ─── Buttons ─── */
.btn-primary {
  /* display: inline-flex; */
  /* align-items: center; */
  /* gap: 6px; */
  /* padding: 7px 16px; */
  /* background: var(--accent); */
  /* color: #fff; */
  /* border: none; */
  /* border-radius: var(--radius); */
  /* font-family: inherit; */
  /* font-size: 13px; */
  /* font-weight: 600; */
  /* cursor: pointer; */
  /* transition: background .2s, transform .1s; */
}
/* .btn-primary:hover { background: var(--accent-dark); } */
/* .btn-primary:active { transform: scale(.97); } */

.btn-secondary,
.btn-load-json-label {
  /* display: inline-flex; */
  /* align-items: center; */
  /* gap: 6px; */
  /* padding: 7px 14px; */
  /* background: var(--surface); */
  /* color: var(--text-muted); */
  /* border: 1px solid var(--border); */
  /* border-radius: var(--radius); */
  /* font-family: inherit; */
  /* font-size: 13px; */
  /* font-weight: 500; */
  /* cursor: pointer; */
  /* transition: all .2s; */
}
/* .btn-secondary:hover, .btn-load-json-label:hover { border-color: var(--accent); color: var(--accent); } */

/* ═══════════════════════════════════════════════════════════
   MAIN LAYOUT
   ═══════════════════════════════════════════════════════════ */
/*.main-layout {
  display: flex;
  height: 100vh;
  padding-top: var(--topbar-h);
}*/

/* ─────────────────── FORM PANEL ─────────────────── */
/*.form-panel {
  width: 380px;
  min-width: 340px;
  max-width: 420px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
}*/

.tab-nav {
  /* display: flex; */
  /* overflow-x: auto; */
  /* border-bottom: 1px solid var(--border); */
  /* padding: 0 8px; */
  /* gap: 2px; */
  /* background: var(--surface); */
  /* flex-shrink: 0; */
}
.tab-nav::-webkit-scrollbar { height: 3px; }

.tab-btn {
  /* display: flex; */
  /* align-items: center; */
  /* gap: 4px; */
  /* padding: 10px 10px 8px; */
  /* border: none; */
  /* border-bottom: 2px solid transparent; */
  /* background: transparent; */
  font-family: inherit;
  /* font-size: 12px; */
  /* font-weight: 500; */
  /* color: var(--text-muted); */
  cursor: pointer;
  white-space: nowrap;
  /* transition: all .2s; */
  /* flex-shrink: 0; */
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

.tab-content {
  /* display: none; */ /* Handled by Tailwind hidden class */
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}
/*.tab-content.active { display: block; }*/ /* Handled by Tailwind block class */

.section-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--text-muted);
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

/* ─── Form Grid ─── */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.form-group { display: flex; flex-direction: column; gap: 4px; }
.form-group.full { grid-column: 1 / -1; }

.form-group label {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
}
.form-group input,
.form-group select,
.form-group textarea {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 15px;
  color: var(--text);
  background: var(--surface);
  transition: border-color .2s, box-shadow .2s;
  outline: none;
  width: 100%;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}
.form-group textarea { resize: vertical; min-height: 70px; }

/* ─── Logo Upload ─── */
.logo-upload-area {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
  margin-bottom: 16px;
  cursor: pointer;
  transition: border-color .2s, background .2s;
  position: relative;
}
.logo-upload-area:hover { border-color: var(--accent); background: var(--accent-light); }

.logo-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
}
.logo-placeholder i { font-size: 28px; opacity: .4; }
.logo-placeholder span { font-size: 13px; font-weight: 500; }
.logo-placeholder small { font-size: 11px; opacity: .7; }

#logoPreview {
  max-height: 80px;
  max-width: 200px;
  object-fit: contain;
  border-radius: 4px;
}

.btn-remove-logo {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 8px;
  padding: 4px 10px;
  background: #fee2e2;
  color: var(--danger);
  border: none;
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
}
.btn-remove-logo:hover { background: #fecaca; }

/* ─── Checkbox Group ─── */
.checkbox-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
}
.checkbox-group label {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
}
.checkbox-group input[type="checkbox"] { width: 14px; height: 14px; accent-color: var(--accent); }

/* ─── Items ─── */
.item-row {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 10px;
  background: #fafafa;
  position: relative;
  transition: box-shadow .2s;
}
.item-row:hover { box-shadow: var(--shadow-md); }

.item-row-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.item-row-num {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-light);
  padding: 2px 7px;
  border-radius: 4px;
}
.btn-delete-item {
  width: 24px;
  height: 24px;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .2s, color .2s;
}
.btn-delete-item:hover { background: #fee2e2; color: var(--danger); }

.item-desc input {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 13px;
  margin-bottom: 8px;
  outline: none;
}
.item-desc input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37,99,235,.1); }

.item-nums {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 6px;
}
.item-nums.with-discount { grid-template-columns: 1fr 1fr 1fr 1fr; }

.item-field { display: flex; flex-direction: column; gap: 3px; }
.item-field label { font-size: 10px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; }
.item-field input {
  padding: 5px 7px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 12px;
  outline: none;
  width: 100%;
}
.item-field input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37,99,235,.1); }

.item-total {
  text-align: right;
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  margin-top: 6px;
}

.btn-add-item {
  width: 100%;
  padding: 9px;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: transparent;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: all .2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-bottom: 20px;
}
.btn-add-item:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-light); }

/* ─── Totals ─── */
.totals-section {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.totals-grid { padding: 0; }
.totals-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
  gap: 8px;
  min-height: 40px;
}
.totals-row:last-child { border-bottom: none; }
.totals-row label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
.totals-row label input[type="checkbox"] { accent-color: var(--accent); }
.totals-row span { font-size: 13px; font-weight: 600; color: var(--text); white-space: nowrap; }

.discount-inputs,
.tax-inputs,
.shipping-inputs {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
  justify-content: flex-end;
}
.discount-inputs input,
.tax-inputs input,
.shipping-inputs input {
  width: 64px;
  padding: 4px 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 12px;
  outline: none;
  text-align: right;
}
.discount-inputs input:focus,
.tax-inputs input:focus,
.shipping-inputs input:focus { border-color: var(--accent); }
.discount-inputs select {
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 12px;
  outline: none;
}
.tax-inputs span { font-size: 12px; color: var(--text-muted); }
.tax-inputs #taxLabel { width: 70px; text-align: left; }

.totals-row.total-row {
  background: var(--bg);
  padding: 12px 14px;
}
.totals-row.total-row label {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
}
.grand-total {
  font-size: 18px !important;
  font-weight: 800 !important;
  color: var(--accent) !important;
}
.amount-due {
  font-size: 15px !important;
  font-weight: 700 !important;
  color: var(--danger) !important;
}

#amountPaid {
  width: 100px;
  padding: 4px 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 12px;
  outline: none;
  text-align: right;
}
#amountPaid:focus { border-color: var(--accent); }

/* ─── Color Presets ─── */
.color-presets {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}
.color-swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform .2s, border-color .2s;
}
.color-swatch:hover { transform: scale(1.15); }
.color-swatch.active { border-color: #fff; box-shadow: 0 0 0 2px var(--text); }

#customColor {
  width: 36px;
  height: 28px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  cursor: pointer;
  padding: 2px;
  background: var(--surface);
}

/* ═══════════════════════════════════════════════════════════
   PREVIEW PANEL
   ═══════════════════════════════════════════════════════════ */
.preview-panel {
  /* flex: 1; */
  /* display: flex; */
  /* flex-direction: column; */
  /* background: #e2e8f0; */
  /* overflow: hidden; */
}

.preview-toolbar {
  /* display: flex; */
  /* align-items: center; */
  /* gap: 8px; */
  /* padding: 8px 16px; */
  /* background: var(--surface); */
  /* border-bottom: 1px solid var(--border); */
  /* flex-shrink: 0; */
}
.preview-label {
  /* font-size: 12px; */
  /* font-weight: 600; */
  /* color: var(--text-muted); */
  /* margin-right: auto; */
  /* display: flex; */
  /* align-items: center; */
  /* gap: 6px; */
}
.btn-zoom {
  /* width: 28px; */
  /* height: 28px; */
  /* border: 1px solid var(--border); */
  /* border-radius: var(--radius); */
  /* background: var(--surface); */
  /* color: var(--text-muted); */
  /* cursor: pointer; */
  /* display: flex; */
  /* align-items: center; */
  /* justify-content: center; */
  /* transition: all .2s; */
}
/* .btn-zoom:hover { border-color: var(--accent); color: var(--accent); } */
/* #zoomLevel { font-size: 12px; font-weight: 600; color: var(--text-muted); min-width: 40px; text-align: center; } */

.preview-scroll {
  /* flex: 1; */
  /* overflow: auto; */
  /* display: flex; */
  /* align-items: flex-start; */
  /* justify-content: center; */
  /* padding: 32px; */
}

.preview-wrapper {
  /* transform-origin: top center; */
  /* transition: transform .2s; */
}

/* The actual invoice paper */
#invoicePreview {
  background: #fff;
  /* box-shadow: var(--shadow-lg), 0 0 0 1px rgba(0,0,0,.05); */
  width: 100%;
  height: 100%;
  /* width: 794px; */ /* A4 at 96dpi */
  /* min-height: 1123px; */
  font-family: 'Inter', sans-serif;
  position: relative;
}

#previewWrapper {
    transform-origin: top center;
}

/* ═══════════════════════════════════════════════════════════
   MODAL
   ═══════════════════════════════════════════════════════════ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
}
.modal-box {
  background: var(--surface);
  border-radius: 16px;
  padding: 40px 60px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  box-shadow: var(--shadow-lg);
  color: var(--text);
  font-weight: 600;
}
.modal-box i { color: var(--accent); }

/* ═══════════════════════════════════════════════════════════
   INVOICE TEMPLATE SHARED STYLES
   ═══════════════════════════════════════════════════════════ */
.inv-table {
  width: 100%;
  border-collapse: collapse;
}
.inv-table th {
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  padding: 9px 12px;
}
.inv-table td {
  padding: 9px 12px;
  font-size: 13px;
  vertical-align: top;
}
.inv-table tr:last-child td { border-bottom: none; }
.inv-table td.num, .inv-table th.num { text-align: right; }

/* ═══════════════════════════════════════════════════════════
   LANGUAGE SWITCHER
   ═══════════════════════════════════════════════════════════ */
.lang-switcher { position: relative; }
.lang-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 7px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  color: var(--text-muted);
  transition: all .2s;
  white-space: nowrap;
}
.lang-btn:hover { border-color: var(--accent); color: var(--accent); }
.lang-arrow { font-size: 10px; transition: transform .2s; }
.lang-switcher.open .lang-arrow { transform: rotate(180deg); }
.lang-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  min-width: 165px;
  z-index: 200;
  overflow: hidden;
}
.lang-switcher.open .lang-dropdown { display: block; }
.lang-option {
  display: block;
  width: 100%;
  padding: 9px 14px;
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  text-align: left;
  color: var(--text);
  transition: background .15s;
}
.lang-option:hover { background: var(--accent-light); }
.lang-option.active { color: var(--accent); font-weight: 600; background: var(--accent-light); }

/* ═══════════════════════════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════════════════════════ */
@media (max-width: 900px) {
  .main-layout { flex-direction: column; overflow: auto; }
  html, body { overflow: auto; }
  .form-panel { width: 100%; max-width: 100%; border-right: none; border-bottom: 1px solid var(--border); max-height: 60vh; }
  .preview-panel { min-height: 600px; }
  .preview-scroll { padding: 16px; }
  .template-selector .label { display: none; }
}

@media (max-width: 600px) {
  .topbar-brand span { display: none; }
  .tpl-btn i { display: none; }
  .tpl-btn { padding: 5px 8px; font-size: 11px; }
}
