/* ═══════════════════════════════════════════════
   CSS VARIABLES — change these to retheme everything
   ═══════════════════════════════════════════════ */
:root {
  --accent:       #2563eb;
  --accent-light: #eff6ff;
  --text:         #1e293b;
  --muted:        #64748b;
  --border:       #e2e8f0;
  --danger:       #ef4444;
  --bg:           #f1f5f9;
  --card:         white;
}

/*
  DARK MODE — toggled by adding .dark to <body>.
  We only override the variables here; every other rule
  that uses var(--...) automatically adapts.
*/
body.dark {
  --accent:       #60a5fa;   /* lighter blue — readable on dark bg */
  --accent-light: #1e3a5f;
  --text:         #e2e8f0;
  --muted:        #94a3b8;
  --border:       #334155;
  --bg:           #0f172a;
  --card:         #1e293b;
}

/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Segoe UI', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding: 2rem;
  transition: background 0.3s, color 0.3s;
}

/* ═══════════════════════════════════════════════
   CONTROL BAR
   ═══════════════════════════════════════════════ */
.controls {
  display: flex;
  flex-wrap: wrap;   /* wraps to next line on small screens */
  gap: 0.6rem;
  justify-content: center;
  margin-bottom: 1.5rem;
}

.controls button,
.controls select {
  padding: 0.55rem 1.1rem;
  border: none;
  border-radius: 6px;
  font-size: 0.88rem;
  cursor: pointer;
  font-weight: 600;
  transition: opacity 0.2s, background 0.2s;
}

.controls button:hover { opacity: 0.85; }

/* Individual button colors */
#addItemBtn    { background: var(--accent); color: white; }
#darkModeBtn   { background: #475569; color: white; }
#saveBtn       { background: #16a34a; color: white; }   /* green  */
#newInvoiceBtn { background: #ea580c; color: white; }   /* orange */
#printBtn      { background: #0f172a; color: white; }

/* Currency select — styled to match buttons */
#currencySelect {
  background: var(--card);
  color: var(--text);
  border: 1.5px solid var(--border);
  font-weight: 600;
  cursor: pointer;
}

/* ═══════════════════════════════════════════════
   INVOICE CARD
   ═══════════════════════════════════════════════ */
.invoice {
  max-width: 820px;
  margin: 0 auto;
  background: var(--card);
  padding: 3rem;
  border-radius: 10px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.08);
  transition: background 0.3s;
}

/* ── Header ── */
.invoice-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 2rem;
  margin-bottom: 2rem;
}

.business-info {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
}

/* ── Logo ── */
.logo-placeholder {
  width: 90px;
  height: 90px;
  border: 2px dashed var(--border);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 0.72rem;
  color: var(--muted);
  cursor: pointer;
  flex-shrink: 0;
  position: relative;  /* anchor for the absolute-positioned input */
  overflow: hidden;
  transition: border-color 0.2s;
}

.logo-placeholder:hover { border-color: var(--accent); }

/*
  The real file input is stretched to cover the entire box.
  opacity:0 makes it invisible but it still receives clicks —
  so clicking anywhere on the logo area opens the file picker.
*/
.logo-placeholder input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  z-index: 1;
}

/*
  The logo image is hidden by default.
  JS calls showLogo() which sets display:block.
*/
#logoImg {
  display: none;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* ── Invoice meta (right side) ── */
.invoice-meta { text-align: right; }

.invoice-meta h1 {
  font-size: 2.4rem;
  font-weight: 800;
  color: var(--accent);
  letter-spacing: 2px;
  margin-bottom: 0.75rem;
}

.meta-table { margin-left: auto; }

.meta-table td {
  padding: 0.15rem 0.5rem;
  font-size: 0.9rem;
}

.meta-table .label {
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.75rem;
}

/* ── Divider ── */
hr {
  border: none;
  border-top: 2px solid var(--accent);
  margin-bottom: 1.5rem;
}

/* ── Section labels ── */
.section-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--accent);
  margin-bottom: 0.4rem;
}

/* ── Bill To ── */
.bill-to { margin-bottom: 2rem; }

/* ═══════════════════════════════════════════════
   EDITABLE FIELDS
   Inline editing: hover/focus shows a dashed underline.
   :empty::before shows placeholder text from data-placeholder.
   ═══════════════════════════════════════════════ */
.editable {
  outline: none;
  border-bottom: 1px dashed transparent;
  min-width: 60px;
  display: inline-block;
  transition: border-color 0.2s, background 0.2s;
}

.editable:hover,
.editable:focus {
  border-bottom-color: var(--accent);
  background: var(--accent-light);
  border-radius: 3px;
}

.editable:empty::before {
  content: attr(data-placeholder);
  color: var(--muted);
  font-style: italic;
}

.muted { color: var(--muted); font-size: 0.9rem; }

/* ═══════════════════════════════════════════════
   LINE ITEMS TABLE
   ═══════════════════════════════════════════════ */
.line-items { margin-bottom: 1.5rem; }

#itemsTable {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

#itemsTable thead tr {
  background: var(--accent);
  color: white;
}

#itemsTable th {
  padding: 0.65rem 0.75rem;
  text-align: left;
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.5px;
}

#itemsTable td {
  padding: 0.55rem 0.75rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

#itemsTable tbody tr:hover { background: var(--accent-light); }

.col-desc   { width: 45%; }
.col-qty    { width: 10%; }
.col-rate   { width: 15%; }
.col-amount { width: 15%; }
.col-del    { width: 10%; }

#itemsTable td .editable { width: 100%; display: block; }

td.amount-cell { text-align: right; font-weight: 500; }

/* Delete row button */
.del-btn {
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 1.1rem;
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
  transition: background 0.2s;
}

.del-btn:hover { background: #fee2e2; }

/* ═══════════════════════════════════════════════
   TOTALS
   ═══════════════════════════════════════════════ */
.totals { display: flex; justify-content: flex-end; margin-bottom: 2rem; }

.totals-inner { width: 280px; }

.totals-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.4rem 0;
  font-size: 0.9rem;
  border-bottom: 1px solid var(--border);
}

.total-line {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--accent);
  border-bottom: 2px solid var(--accent);
  padding-top: 0.6rem;
}

/* ── Tax rows ── */
/*
  Each tax row is a .totals-row with two children:
    .tax-label-group  (label + rate% + delete button)
    .tax-amount-display (right-aligned calculated amount)
*/
.tax-label-group {
  display: flex;
  align-items: center;
  gap: 0.2rem;
  flex-wrap: wrap;
}

.tax-label-group .editable { min-width: 40px; }

/* Small "✕" button inside the tax row */
.del-tax-btn {
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 0.8rem;
  padding: 0.1rem 0.3rem;
  border-radius: 3px;
  margin-left: 0.25rem;
  transition: background 0.2s;
}

.del-tax-btn:hover { background: #fee2e2; }

/* "+ Add Tax Line" button — styled as a subtle dashed button */
.add-tax-btn {
  display: block;
  width: 100%;
  margin: 0.5rem 0;
  padding: 0.3rem 0;
  background: none;
  border: 1px dashed var(--accent);
  color: var(--accent);
  border-radius: 4px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.add-tax-btn:hover { background: var(--accent-light); }

/* ── Notes ── */
.notes {
  background: var(--accent-light);
  border-left: 4px solid var(--accent);
  padding: 1rem 1.25rem;
  border-radius: 0 6px 6px 0;
}

.notes .editable {
  display: block;
  font-size: 0.88rem;
  color: var(--muted);
  line-height: 1.5;
}

/* ═══════════════════════════════════════════════
   TOAST NOTIFICATION
   A small message that appears at the bottom-right
   and fades out automatically.
   ═══════════════════════════════════════════════ */
.toast {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  background: #0f172a;
  color: white;
  padding: 0.75rem 1.25rem;
  border-radius: 8px;
  font-size: 0.88rem;
  font-weight: 600;
  z-index: 9999;
  pointer-events: none;
  animation: toastFade 2.5s ease forwards;
}

/*
  CSS animation: fadeInOut.
  @keyframes defines keyframe stops at 0%, 15%, 75%, 100%.
  The element fades in, stays visible, then fades out.
*/
@keyframes toastFade {
  0%   { opacity: 0; transform: translateY(10px); }
  15%  { opacity: 1; transform: translateY(0); }
  75%  { opacity: 1; }
  100% { opacity: 0; }
}

/* ═══════════════════════════════════════════════
   PRINT STYLES
   @media print rules only apply when the browser
   is rendering the page for printing / PDF export.
   ═══════════════════════════════════════════════ */
@media print {
  body {
    background: white;
    padding: 0;
    /* Force light mode text regardless of dark mode toggle */
    color: #1e293b;
  }

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

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

  .editable { border-bottom: none; }

  /* Override dark mode colors for print so PDFs are always light */
  body.dark .invoice    { background: white; }
  body.dark .notes      { background: #eff6ff; border-left-color: #2563eb; }
  body.dark .section-label  { color: #2563eb; }
  body.dark .invoice-meta h1 { color: #2563eb; }
  body.dark .total-line { color: #2563eb; border-bottom-color: #2563eb; }
  body.dark #itemsTable thead tr { background: #2563eb; }
  body.dark #itemsTable td  { border-bottom-color: #e2e8f0; color: #1e293b; }
  body.dark .totals-row { border-bottom-color: #e2e8f0; color: #1e293b; }
  body.dark .total-line { color: #2563eb; }
  body.dark hr { border-top-color: #2563eb; }
  body.dark .muted { color: #64748b; }
}
