/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --accent:       #2563eb;
  --accent-dark:  #1d4ed8;
  --accent-light: #eff6ff;
  --surface:      #ffffff;
  --bg:           #f1f5f9;
  --sidebar-bg:   #0f172a;
  --sidebar-text: #94a3b8;
  --sidebar-head: #f8fafc;
  --border:       #e2e8f0;
  --text:         #1e293b;
  --text-muted:   #64748b;
  --red:          #ef4444;
  --radius:       10px;
  --shadow:       0 4px 24px rgba(0,0,0,.10);
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  min-height: 100vh;
  font-size: 14px;
}

/* ===== SIDEBAR ===== */
.sidebar {
  width: 280px;
  min-width: 280px;
  background: var(--sidebar-bg);
  padding: 24px 20px 32px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #fff;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: .3px;
  margin-bottom: 20px;
  padding-bottom: 20px;
  border-bottom: 1px solid #1e293b;
}

.section-title {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: #475569;
  margin-bottom: 2px;
  margin-top: 4px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.form-group label {
  font-size: 11px;
  color: var(--sidebar-text);
  font-weight: 500;
}

.form-group input,
.form-group select,
.form-group textarea {
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 6px;
  color: #f1f5f9;
  font-size: 13px;
  padding: 7px 10px;
  outline: none;
  transition: border-color .18s;
  width: 100%;
  font-family: inherit;
}

.form-group input::placeholder,
.form-group textarea::placeholder { color: #475569; }

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--accent);
}

.form-group select option { background: #1e293b; }
.form-group textarea { resize: vertical; }

/* Toggle */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #f1f5f9;
  font-size: 13px;
  font-weight: 500;
  background: #1e293b;
  border-radius: 6px;
  padding: 9px 12px;
  margin-top: 4px;
}

.toggle { position: relative; display: inline-block; width: 40px; height: 22px; }
.toggle input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; inset: 0;
  background: #334155;
  border-radius: 22px;
  cursor: pointer;
  transition: background .2s;
}
.slider::before {
  content: '';
  position: absolute;
  width: 16px; height: 16px;
  left: 3px; top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform .2s;
}
.toggle input:checked + .slider { background: var(--accent); }
.toggle input:checked + .slider::before { transform: translateX(18px); }

/* Print button */
.btn-print {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: auto;
  padding: 11px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background .18s, transform .1s;
  margin-top: 28px;
}
.btn-print:hover { background: var(--accent-dark); }
.btn-print:active { transform: scale(.98); }

/* ===== PREVIEW AREA ===== */
.preview-area {
  flex: 1;
  padding: 40px 32px;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  overflow-y: auto;
}

/* ===== INVOICE ===== */
.invoice {
  background: var(--surface);
  border-radius: 14px;
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 780px;
  padding: 48px 52px 40px;
  display: flex;
  flex-direction: column;
  gap: 0;
}

/* Header */
.inv-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 24px;
}

.inv-brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.inv-brand-icon {
  width: 48px; height: 48px;
  background: var(--accent-light);
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  color: var(--accent);
  flex-shrink: 0;
}

.inv-company-name {
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.3;
}

.inv-company-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.inv-title-block {
  text-align: right;
}

.inv-title {
  font-size: 28px;
  font-weight: 800;
  color: var(--accent);
  letter-spacing: 2px;
  margin-bottom: 10px;
}

.inv-meta {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  font-size: 13px;
  line-height: 1.8;
}

.inv-meta-label { color: var(--text-muted); }
.inv-meta-value { font-weight: 600; color: var(--text); }

/* Divider */
.inv-divider {
  height: 2px;
  background: linear-gradient(90deg, var(--accent) 0%, var(--accent-light) 100%);
  border-radius: 2px;
  margin: 28px 0;
}

/* Parties */
.inv-parties {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 20px;
  align-items: center;
}

.inv-party-arrow {
  color: var(--accent);
  opacity: .4;
  display: flex;
  align-items: center;
}

.inv-party-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 8px;
}

.inv-party-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 6px;
}

.inv-party-detail {
  font-size: 12.5px;
  color: var(--text-muted);
  line-height: 1.7;
}

/* Items table */
.inv-items { margin-top: 8px; }

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

.items-table thead tr {
  background: var(--accent);
  color: #fff;
}

.items-table th {
  padding: 10px 12px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .6px;
  text-transform: uppercase;
  text-align: left;
}

.col-num   { width: 36px; border-radius: 8px 0 0 0; }
.col-desc  { }
.col-qty   { width: 70px; text-align: center; }
.col-unit  { width: 70px; text-align: center; }
.col-price { width: 100px; text-align: right; }
.col-total { width: 110px; text-align: right; border-radius: 0 8px 0 0; }
.col-action{ width: 36px; background: transparent !important; }

.items-table tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background .12s;
}
.items-table tbody tr:hover { background: #f8fafc; }
.items-table tbody tr:last-child { border-bottom: none; }

.items-table td {
  padding: 10px 12px;
  font-size: 13px;
  vertical-align: middle;
}

.items-table td input,
.items-table td select {
  background: transparent;
  border: none;
  outline: none;
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
  width: 100%;
  padding: 2px 0;
}

.items-table td input:focus {
  border-bottom: 2px solid var(--accent);
  margin-bottom: -2px;
}

.items-table td input[type=number] { text-align: right; }

.td-num  { color: var(--text-muted); font-weight: 600; }
.td-total { font-weight: 700; color: var(--text); text-align: right; }

.btn-delete-row {
  background: none;
  border: none;
  color: #cbd5e1;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  transition: color .15s, background .15s;
}
.btn-delete-row:hover { color: var(--red); background: #fee2e2; }

.btn-add-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  padding: 8px 14px;
  background: var(--accent-light);
  color: var(--accent);
  border: 1.5px dashed #93c5fd;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
.btn-add-row:hover { background: #dbeafe; }

/* Totals */
.inv-totals {
  display: flex;
  justify-content: flex-end;
  margin-top: 28px;
}

.totals-box {
  width: 300px;
  background: #f8fafc;
  border-radius: 10px;
  padding: 18px 22px;
  border: 1px solid var(--border);
}

.totals-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  padding: 5px 0;
}

.totals-label { color: var(--text-muted); }
.totals-value { font-weight: 600; color: var(--text); }

.vat-row { display: none; }
.vat-row.visible { display: flex; }

.totals-divider {
  height: 1px;
  background: var(--border);
  margin: 10px 0 8px;
}

.totals-grand .totals-label {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .5px;
  text-transform: uppercase;
  color: var(--text);
}
.totals-grand .totals-value {
  font-size: 20px;
  font-weight: 800;
  color: var(--accent);
}

/* Notes */
.inv-notes {
  margin-top: 32px;
  padding: 16px 20px;
  background: var(--accent-light);
  border-left: 3px solid var(--accent);
  border-radius: 0 8px 8px 0;
}

.inv-notes-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 6px;
}

.inv-notes-text {
  font-size: 12.5px;
  color: var(--text-muted);
  line-height: 1.6;
  white-space: pre-wrap;
}

.inv-notes:empty,
.inv-notes[data-empty="true"] { display: none; }

/* Footer signatures */
.inv-footer {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-top: 52px;
  gap: 24px;
}

.inv-footer-sign { flex: 1; }

.sign-line {
  height: 1px;
  background: var(--border);
  margin-bottom: 8px;
}

.sign-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .8px;
  font-weight: 600;
}

.inv-footer-center { flex: 0 0 auto; }

.inv-footer-stamp {
  width: 64px; height: 64px;
  border: 2px dashed #cbd5e1;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: #cbd5e1;
  font-weight: 700;
  letter-spacing: 1px;
}

/* ===== PRINT ===== */
@media print {
  @page { margin: 16mm 14mm; size: A4; }

  body { background: white; display: block; font-size: 11pt; }

  .no-print { display: none !important; }

  .preview-area {
    padding: 0;
    display: block;
  }

  .invoice {
    box-shadow: none;
    border-radius: 0;
    padding: 0;
    max-width: 100%;
    width: 100%;
  }

  .items-table thead tr { -webkit-print-color-adjust: exact; print-color-adjust: exact; }

  .inv-divider { -webkit-print-color-adjust: exact; print-color-adjust: exact; }

  .btn-add-row, .btn-delete-row, .sidebar { display: none !important; }

  .vat-row { display: none !important; }
  .vat-row.visible { display: flex !important; }
}
