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

:root {
  --font-sans: 'DM Sans', system-ui, sans-serif;
  --font-mono: 'DM Mono', monospace;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;
  --t-fast: 120ms cubic-bezier(0.4,0,0.2,1);
  --t-med:  220ms cubic-bezier(0.4,0,0.2,1);
  --t-slow: 380ms cubic-bezier(0.4,0,0.2,1);
}

[data-theme="dark"] {
  --bg:         #0d0d0d;
  --bg-2:       #141414;
  --bg-3:       #1a1a1a;
  --surface:    #1e1e1e;
  --surface-2:  #252525;
  --border:     #2a2a2a;
  --border-2:   #333;
  --text:       #f0f0ee;
  --text-2:     #888884;
  --text-3:     #555550;
  --accent:     #e8e6df;
  --accent-dim: rgba(232,230,223,0.06);
  --blue:       #3b82f6;
  --blue-dim:   rgba(59,130,246,0.12);
  --blue-bdr:   rgba(59,130,246,0.3);
  --green:      #22c55e;
  --green-dim:  rgba(34,197,94,0.12);
  --red:        #f87171;
  --shadow-sm:  0 1px 3px rgba(0,0,0,0.5);
  --shadow-md:  0 4px 16px rgba(0,0,0,0.6);
  --shadow-lg:  0 8px 40px rgba(0,0,0,0.8);
}

[data-theme="light"] {
  --bg:         #f2f1ee;
  --bg-2:       #ebebea;
  --bg-3:       #e4e3e0;
  --surface:    #fafaf8;
  --surface-2:  #f5f4f1;
  --border:     #dddbd6;
  --border-2:   #ccc9c3;
  --text:       #111110;
  --text-2:     #6b6966;
  --text-3:     #a8a5a0;
  --accent:     #111110;
  --accent-dim: rgba(17,17,16,0.05);
  --blue:       #2563eb;
  --blue-dim:   rgba(37,99,235,0.08);
  --blue-bdr:   rgba(37,99,235,0.25);
  --green:      #16a34a;
  --green-dim:  rgba(22,163,74,0.1);
  --red:        #dc2626;
  --shadow-sm:  0 1px 3px rgba(0,0,0,0.08);
  --shadow-md:  0 4px 16px rgba(0,0,0,0.1);
  --shadow-lg:  0 8px 40px rgba(0,0,0,0.15);
}

html, body {
  font-family: var(--font-sans);
  font-size: 13px;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  transition: background var(--t-med), color var(--t-med);
}

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 3px; }
::-webkit-scrollbar-track { background: transparent; }

/* ══════════════════════════════════════════════════════════════
   TOPBAR (global)
   ══════════════════════════════════════════════════════════════ */
.topbar {
  position: sticky; top: 0; z-index: 300;
  height: 48px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 20px; gap: 12px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.topbar-brand {
  display: flex; align-items: center; gap: 7px;
  font-size: 12px; font-weight: 700;
  letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--text);
  cursor: pointer;
  user-select: none;
}
.topbar-brand-dot {
  width: 6px; height: 6px;
  background: var(--blue); border-radius: 50%;
  flex-shrink: 0;
}
.topbar-sep {
  width: 1px; height: 16px;
  background: var(--border);
  flex-shrink: 0;
}
.topbar-title {
  font-size: 13px; font-weight: 500;
  color: var(--text-2); letter-spacing: 0.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar-spacer { flex: 1; }

.theme-toggle {
  width: 32px; height: 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-2);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; font-size: 14px;
  transition: all var(--t-fast);
  flex-shrink: 0;
}
.theme-toggle:hover {
  border-color: var(--blue);
  color: var(--blue);
  background: var(--blue-dim);
}

.topbar-link {
  font-size: 11px; color: var(--text-3); text-decoration: none;
  padding: 5px 9px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); white-space: nowrap;
  transition: all var(--t-fast);
  flex-shrink: 0;
}
.topbar-link:hover { color: var(--blue); border-color: var(--blue-bdr); text-decoration: none; }

@media (max-width: 640px) {
  .topbar-link, .topbar-sep { display: none; }
  .topbar { padding: 0 14px; }
}

/* ══════════════════════════════════════════════════════════════
   VIEW SWITCHING
   ══════════════════════════════════════════════════════════════ */
.view { display: none; }
.view.active { display: block; }
.view.active.flex { display: flex; flex-direction: column; min-height: calc(100dvh - 48px); }

@keyframes slide-in { from { opacity:0; transform:translateY(10px); } to { opacity:1; transform:none; } }
.fade-in { animation: slide-in 0.35s ease both; }

/* ══════════════════════════════════════════════════════════════
   HUB / HOME VIEW
   ══════════════════════════════════════════════════════════════ */
.hub {
  max-width: 980px;
  margin: 0 auto;
  padding: 56px 24px 60px;
}

.hub-eyebrow {
  font-size: 11px; font-weight: 600;
  letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--blue);
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 14px;
}
.hub-eyebrow::before {
  content: '';
  width: 18px; height: 1px;
  background: var(--blue);
}

.hub-title {
  font-size: 34px; font-weight: 700;
  letter-spacing: -0.025em; line-height: 1.15;
  margin-bottom: 10px;
}
.hub-title em {
  font-style: normal; color: var(--blue);
}

.hub-sub {
  font-size: 14px; color: var(--text-2);
  max-width: 540px; line-height: 1.7;
  margin-bottom: 40px;
}

.hub-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.tool-card {
  position: relative;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  cursor: pointer;
  transition: all var(--t-med);
  display: flex; flex-direction: column; gap: 14px;
  overflow: hidden;
  text-align: left;
  text-decoration: none;
}
.tool-card::after {
  content: '';
  position: absolute; inset: 0;
  background: linear-gradient(135deg, var(--blue-dim) 0%, transparent 55%);
  opacity: 0; transition: opacity var(--t-med);
  pointer-events: none;
}
.tool-card:hover {
  border-color: var(--blue-bdr);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  text-decoration: none;
}
.tool-card:hover::after { opacity: 1; }

.tool-card-top {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
}

.tool-icon {
  width: 40px; height: 40px;
  border-radius: var(--radius-md);
  background: var(--blue-dim);
  border: 1px solid var(--blue-bdr);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
  color: var(--blue);
}

.tool-tag {
  font-size: 9px; font-weight: 700;
  letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--text-3);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 100px;
  padding: 3px 9px;
  white-space: nowrap;
}

.tool-name {
  font-size: 16px; font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
}

.tool-desc {
  font-size: 12px; color: var(--text-2);
  line-height: 1.65;
  flex: 1;
}

.tool-cta {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 600;
  color: var(--blue);
  margin-top: 2px;
}
.tool-cta svg { transition: transform var(--t-fast); }
.tool-card:hover .tool-cta svg { transform: translateX(3px); }
.tool-card.external .tool-tag { color: var(--blue); border-color: var(--blue-bdr); background: var(--blue-dim); }

/* Placeholder card for future modules */
.tool-card.is-empty {
  cursor: default;
  border-style: dashed;
  align-items: center; justify-content: center;
  text-align: center;
  color: var(--text-3);
  min-height: 168px;
}
.tool-card.is-empty:hover { transform: none; box-shadow: none; border-color: var(--border); }
.tool-card.is-empty::after { display: none; }
.tool-card.is-empty .tool-icon { background: var(--bg); border-color: var(--border); color: var(--text-3); }

.hub-footer-note {
  margin-top: 48px;
  font-size: 11px; color: var(--text-3);
  text-align: center;
}

/* ══════════════════════════════════════════════════════════════
   SHARED: back link inside tool views
   ══════════════════════════════════════════════════════════════ */
.tool-topbar-extra {
  display: flex; align-items: center; gap: 10px;
}
.back-link {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 500; color: var(--text-2);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 5px 10px;
  cursor: pointer;
  transition: all var(--t-fast);
  flex-shrink: 0;
}
.back-link:hover { border-color: var(--blue); color: var(--blue); background: var(--blue-dim); }

/* ══════════════════════════════════════════════════════════════
   GLOBAL FOOTER
   ══════════════════════════════════════════════════════════════ */
.global-footer {
  border-top: 1px solid var(--border);
  padding: 14px 20px;
  text-align: center;
  font-size: 11px; color: var(--text-3);
  margin-top: auto;
}
.global-footer a { color: var(--blue); font-weight: 500; }

/* ══════════════════════════════════════════════════════════════
   DONATION WIDGET
   ══════════════════════════════════════════════════════════════ */
.donation-fab {
  position: fixed;
  right: 20px;
  bottom: 72px;
  z-index: 850;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 16px;
  border: 1px solid var(--blue-bdr);
  border-radius: 999px;
  background: var(--surface);
  color: var(--blue);
  box-shadow: var(--shadow-md);
  font: 600 12px/1 var(--font-sans);
  cursor: pointer;
  transition: transform var(--t-fast), border-color var(--t-fast), background var(--t-fast), box-shadow var(--t-fast);
}
.donation-fab:hover {
  transform: translateY(-2px);
  border-color: var(--blue);
  background: var(--blue-dim);
  box-shadow: var(--shadow-lg);
}
.donation-fab:focus-visible,
.donation-close:focus-visible,
.donation-action:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 3px;
}
.donation-heart { font-size: 15px; line-height: 1; }

.donation-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(0,0,0,0.62);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.donation-modal.open { display: flex; }
.donation-dialog {
  position: relative;
  width: min(400px, 100%);
  padding: 28px;
  border: 1px solid var(--border-2);
  border-radius: var(--radius-xl);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
  animation: donation-in var(--t-med) both;
}
.donation-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 30px;
  height: 30px;
  border: 1px solid transparent;
  border-radius: 50%;
  background: transparent;
  color: var(--text-2);
  font-size: 16px;
  cursor: pointer;
}
.donation-close:hover { border-color: var(--border); background: var(--bg); color: var(--text); }
.donation-icon {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  margin-bottom: 18px;
  border: 1px solid var(--blue-bdr);
  border-radius: var(--radius-lg);
  background: var(--blue-dim);
  font-size: 22px;
}
.donation-title {
  margin: 0 34px 8px 0;
  font-size: 21px;
  line-height: 1.25;
  letter-spacing: -0.02em;
}
.donation-copy {
  margin-bottom: 20px;
  color: var(--text-2);
  font-size: 13px;
  line-height: 1.7;
}
.donation-copy strong { color: var(--text); }
.donation-benefits {
  display: grid;
  gap: 8px;
  margin: 0 0 22px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg);
  color: var(--text-2);
  font-size: 12px;
  list-style: none;
}
.donation-benefits li::before {
  content: '✓';
  margin-right: 8px;
  color: var(--green);
  font-weight: 700;
}
.donation-actions { display: grid; grid-template-columns: 1fr auto; gap: 9px; }
.donation-action {
  min-height: 42px;
  padding: 0 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font: 600 12px/1 var(--font-sans);
  cursor: pointer;
  transition: all var(--t-fast);
}
.donation-action.primary {
  border-color: var(--blue);
  background: var(--blue);
  color: #fff;
}
.donation-action.primary:hover { filter: brightness(1.08); transform: translateY(-1px); }
.donation-action.secondary { background: var(--surface); color: var(--text-2); }
.donation-action.secondary:hover { border-color: var(--border-2); color: var(--text); }
body.donation-open { overflow: hidden; }

@keyframes donation-in {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

@media (max-width: 520px) {
  .donation-fab { right: 14px; bottom: 66px; padding: 0; width: 44px; justify-content: center; }
  .donation-fab-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .donation-dialog { padding: 24px 20px 20px; }
  .donation-actions { grid-template-columns: 1fr; }
  .donation-action.secondary { order: 2; }
}

@media (prefers-reduced-motion: reduce) {
  .donation-dialog { animation: none; }
}

/* ══════════════════════════════════════════════════════════════
   MODULE: IMAGE CONVERTER
   ══════════════════════════════════════════════════════════════ */
.converter-shell {
  width: min(1080px, calc(100% - 32px));
  margin: 0 auto;
  padding: 34px 0 60px;
}
.converter-hero { margin-bottom: 22px; text-align: center; }
.converter-hero-icon {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin-bottom: 10px;
  border: 1px solid var(--blue-bdr);
  border-radius: var(--radius-md);
  background: var(--blue-dim);
  color: var(--blue);
}
.converter-title { font-size: 25px; letter-spacing: -0.025em; }
.converter-sub { margin-top: 5px; color: var(--text-2); font-size: 13px; }
.converter-settings {
  display: grid;
  gap: 22px;
  padding: 22px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.converter-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  color: var(--text-2);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
}
.converter-quality-value {
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--blue-dim);
  color: var(--blue);
  font-family: var(--font-mono);
  letter-spacing: 0;
}
.converter-formats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.converter-format {
  min-height: 40px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text-2);
  font: 700 11px/1 var(--font-sans);
  cursor: pointer;
  transition: all var(--t-fast);
}
.converter-format:hover { border-color: var(--blue-bdr); color: var(--blue); }
.converter-format.active {
  border-color: var(--blue);
  background: var(--blue);
  color: #fff;
}
.converter-range { width: 100%; accent-color: var(--blue); cursor: pointer; }
.converter-quality-hints {
  display: flex;
  justify-content: space-between;
  margin-top: 7px;
  color: var(--text-3);
  font-size: 10px;
}
.converter-drop {
  display: grid;
  place-items: center;
  min-height: 210px;
  margin-top: 18px;
  padding: 28px;
  border: 1.5px dashed var(--border-2);
  border-radius: var(--radius-lg);
  background: var(--surface);
  text-align: center;
  cursor: pointer;
  transition: all var(--t-med);
}
.converter-drop:hover,
.converter-drop.over {
  border-color: var(--blue);
  background: var(--blue-dim);
}
.converter-drop:focus-visible,
.converter-format:focus-visible,
.converter-download:focus-visible,
.converter-clear:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}
.converter-drop-icon { margin-bottom: 12px; color: var(--text-3); }
.converter-drop-title { font-size: 15px; font-weight: 650; }
.converter-drop-hint { margin-top: 5px; color: var(--text-3); font-size: 11px; }
.converter-status {
  display: none;
  margin-top: 16px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-2);
  background: var(--surface);
  font-size: 11px;
}
.converter-status.show { display: block; }
.converter-status.error { border-color: rgba(220,38,38,.3); color: var(--red); }
.converter-results { display: grid; gap: 10px; margin-top: 18px; }
.converter-result {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
}
.converter-thumb {
  width: 54px;
  height: 54px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  background: var(--bg-3);
}
.converter-file-name {
  overflow: hidden;
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.converter-file-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  margin-top: 5px;
  color: var(--text-3);
  font-size: 10px;
}
.converter-saving { color: var(--green); font-weight: 700; }
.converter-download {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--blue-bdr);
  border-radius: var(--radius-sm);
  background: var(--blue-dim);
  color: var(--blue);
  font: 650 11px/1 var(--font-sans);
  cursor: pointer;
  text-decoration: none;
}
.converter-download:hover { border-color: var(--blue); text-decoration: none; }
.converter-footer-actions {
  display: none;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
}
.converter-footer-actions.show { display: flex; }
.converter-clear {
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-2);
  font: 600 11px/1 var(--font-sans);
  cursor: pointer;
}
.converter-clear:hover { border-color: var(--border-2); color: var(--text); }
.converter-note { margin-top: 12px; color: var(--text-3); font-size: 10px; text-align: center; }

@media (max-width: 640px) {
  .converter-shell { width: min(100% - 24px, 1080px); padding-top: 24px; }
  .converter-settings { padding: 16px; }
  .converter-drop { min-height: 180px; }
  .converter-result { grid-template-columns: 48px minmax(0,1fr); }
  .converter-thumb { width: 48px; height: 48px; }
  .converter-download { grid-column: 1 / -1; width: 100%; }
}

/* ══════════════════════════════════════════════════════════════
   MODULE 1: SOCIAL FORMAT STUDIO
   ══════════════════════════════════════════════════════════════ */
.app {
  display: grid;
  grid-template-columns: 320px 1fr;
  flex: 1;
  min-height: 0;
}

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow-y: auto;
  position: sticky; top: 48px;
  height: calc(100dvh - 48px);
  align-self: start;
}

.s-section {
  padding: 18px 16px;
  border-bottom: 1px solid var(--border);
}
.s-section:last-of-type { border-bottom: none; }

.s-label {
  font-size: 10px; font-weight: 600;
  letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--text-3); margin-bottom: 12px;
}

.drop-zone {
  border: 1.5px dashed var(--border-2);
  border-radius: var(--radius-lg);
  padding: 20px 14px;
  text-align: center;
  cursor: pointer;
  transition: all var(--t-med);
  background: var(--bg);
  position: relative; overflow: hidden;
}
.drop-zone::before {
  content: '';
  position: absolute; inset: 0;
  background: var(--blue-dim);
  opacity: 0; transition: opacity var(--t-med);
}
.drop-zone:hover::before, .drop-zone.over::before { opacity: 1; }
.drop-zone:hover, .drop-zone.over { border-color: var(--blue); }
.drop-zone.over { transform: scale(1.01); }
.drop-zone:focus-visible,
.fmt-btn:focus-visible,
.fill-opt:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

.drop-icon {
  width: 36px; height: 36px;
  background: var(--surface-2);
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 8px; font-size: 16px;
  position: relative;
}
.drop-title { font-size: 13px; font-weight: 600; color: var(--text); margin-bottom: 2px; }
.drop-hint { font-size: 11px; color: var(--text-3); line-height: 1.5; }

.thumbs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 5px; margin-top: 12px;
  max-height: 200px; overflow-y: auto;
}

.thumb {
  position: relative; aspect-ratio: 1;
  border-radius: var(--radius-sm); overflow: hidden;
  cursor: pointer;
  border: 2px solid transparent;
  transition: all var(--t-fast);
  background: var(--bg-3);
}
.thumb:hover { border-color: var(--blue-bdr); }
.thumb.active { border-color: var(--blue); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }

.thumb-n {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: rgba(0,0,0,0.72);
  color: #fff; font-size: 9px; font-weight: 600;
  font-family: var(--font-mono);
  padding: 2px 4px;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: text;
  line-height: 1.6;
  transition: background var(--t-fast);
}
.thumb-n:hover { background: rgba(37,99,235,0.85); }
.thumb-n:focus {
  outline: none;
  background: rgba(37,99,235,0.95);
  white-space: normal;
  overflow: visible;
  text-overflow: unset;
}

.thumb-rm {
  position: absolute; top: 2px; right: 2px;
  width: 16px; height: 16px;
  background: rgba(220,38,38,0.85); color: #fff;
  border: none; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; font-size: 10px; font-weight: 700;
  opacity: 0; transition: opacity var(--t-fast);
  line-height: 1;
}
.thumb:hover .thumb-rm { opacity: 1; }

.img-counter {
  margin-top: 8px; padding: 6px 10px;
  background: var(--blue-dim);
  border: 1px solid var(--blue-bdr);
  border-radius: var(--radius-sm);
  font-size: 11px; font-weight: 500; color: var(--blue);
  text-align: center; display: none;
}

.formats-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px;
}
.fmt-btn {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 5px; padding: 10px 6px;
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer; transition: all var(--t-fast);
  text-align: center;
}
.fmt-btn:hover { border-color: var(--blue-bdr); background: var(--blue-dim); }
.fmt-btn.active { border-color: var(--blue); background: var(--blue-dim); }
.fmt-icon { display: flex; align-items: center; justify-content: center; }
.fmt-icon svg rect {
  fill: var(--surface-2);
  stroke: var(--text-3);
  stroke-width: 1.5;
  transition: fill var(--t-fast), stroke var(--t-fast);
}
.fmt-btn.active .fmt-icon svg rect,
.fmt-btn:hover .fmt-icon svg rect { fill: var(--blue-dim); stroke: var(--blue); }
.fmt-name {
  font-size: 10px; font-weight: 600;
  letter-spacing: 0.04em; color: var(--text-2);
  transition: color var(--t-fast);
}
.fmt-btn.active .fmt-name, .fmt-btn:hover .fmt-name { color: var(--blue); }
.fmt-size {
  font-size: 9px; color: var(--text-3);
  font-family: var(--font-mono); letter-spacing: 0.03em;
  transition: color var(--t-fast);
}
.fmt-btn.active .fmt-size { color: var(--blue); opacity: 0.8; }

.fill-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.fill-opt {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 10px;
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer; transition: all var(--t-fast);
}
.fill-opt:hover { border-color: var(--blue-bdr); background: var(--blue-dim); }
.fill-opt.active { border-color: var(--blue); background: var(--blue-dim); }
.fill-dot {
  width: 8px; height: 8px; border-radius: 50%;
  border: 1.5px solid var(--text-3);
  flex-shrink: 0; transition: all var(--t-fast);
}
.fill-opt.active .fill-dot { border-color: var(--blue); background: var(--blue); }
.fill-label { font-size: 11px; font-weight: 500; color: var(--text-2); transition: color var(--t-fast); }
.fill-opt.active .fill-label { color: var(--blue); }

.blur-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-top: 7px;
  transition: opacity var(--t-fast);
}
.blur-row.disabled { opacity: 0.35; pointer-events: none; }
.blur-label { font-size: 11px; color: var(--text-2); flex-shrink: 0; font-weight: 500; }
input[type="range"] {
  flex: 1; height: 3px;
  -webkit-appearance: none;
  background: var(--border-2);
  border-radius: 2px; outline: none;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px;
  background: var(--blue);
  border-radius: 50%; border: 2px solid var(--surface);
  cursor: pointer;
  box-shadow: 0 0 0 0 rgba(59,130,246,0);
  transition: box-shadow var(--t-fast);
}
input[type="range"]::-webkit-slider-thumb:hover { box-shadow: 0 0 0 4px var(--blue-dim); }
.blur-val {
  font-size: 11px; font-family: var(--font-mono);
  color: var(--text-3); min-width: 26px; text-align: right;
}

.img-info {
  padding: 9px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 11px; color: var(--text-2);
  line-height: 1.8; display: none;
}
.img-info.show { display: block; }
.img-info strong { color: var(--text); font-weight: 600; }

.export-fmt-row { display: flex; gap: 6px; margin-bottom: 8px; }
.exp-fmt-btn {
  flex: 1; padding: 7px 6px;
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
  font-size: 11px; font-weight: 600;
  color: var(--text-2);
  cursor: pointer; transition: all var(--t-fast);
  text-align: center;
}
.exp-fmt-btn:hover { border-color: var(--blue-bdr); color: var(--blue); background: var(--blue-dim); }
.exp-fmt-btn.active { border-color: var(--blue); color: var(--blue); background: var(--blue-dim); }
.exp-fmt-note { font-size: 10px; color: var(--text-3); margin-bottom: 8px; padding: 0 2px; line-height: 1.5; }

.btn-dl {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; padding: 11px 16px;
  background: var(--accent);
  color: var(--bg);
  border: none; border-radius: var(--radius-md);
  font-family: var(--font-sans);
  font-size: 13px; font-weight: 600; letter-spacing: 0.02em;
  cursor: pointer; transition: all var(--t-med);
}
.btn-dl:hover:not(:disabled) { transform: translateY(-1px); box-shadow: var(--shadow-md); opacity: 0.9; }
.btn-dl:active:not(:disabled) { transform: translateY(0); }
.btn-dl:disabled { background: var(--surface-2); color: var(--text-3); cursor: not-allowed; }

.preview-panel {
  display: flex; flex-direction: column;
  background: var(--bg-2);
  padding: 20px;
  align-items: center;
  justify-content: flex-start;
  gap: 14px;
  min-height: 0;
}

.preview-head {
  width: 100%; display: flex;
  align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 8px;
}
.preview-head-left { display: flex; align-items: center; gap: 10px; }
.preview-label {
  font-size: 11px; font-weight: 600;
  letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--text-3);
}
.preview-badge {
  font-size: 10px; font-weight: 600;
  font-family: var(--font-mono);
  padding: 3px 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-2);
  letter-spacing: 0.05em;
}
.preview-badge.active-format { background: var(--blue-dim); border-color: var(--blue-bdr); color: var(--blue); }

.preview-nav { display: flex; align-items: center; gap: 6px; }
.nav-btn {
  width: 28px; height: 28px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-2);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; font-size: 12px;
  transition: all var(--t-fast);
}
.nav-btn:hover:not(:disabled) { border-color: var(--blue); color: var(--blue); background: var(--blue-dim); }
.nav-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.nav-count { font-size: 11px; font-family: var(--font-mono); color: var(--text-3); min-width: 36px; text-align: center; }

.preview-area { flex: 1; width: 100%; display: flex; align-items: center; justify-content: center; min-height: 0; }

#previewCanvas {
  display: none;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
  max-height: calc(100dvh - 230px);
  max-width: 100%;
  transition: opacity var(--t-med);
}
#previewCanvas.rendering { opacity: 0.5; }

.placeholder {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 12px;
  width: 220px; aspect-ratio: 9/16;
  border: 1.5px dashed var(--border);
  border-radius: var(--radius-lg);
  color: var(--text-3);
  background: var(--surface);
}
.ph-icon {
  width: 44px; height: 44px;
  background: var(--surface-2);
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
}
.ph-text { font-size: 12px; font-weight: 500; text-align: center; padding: 0 20px; line-height: 1.6; }

.proc-bar { width: 100%; max-width: 400px; height: 2px; background: var(--border); border-radius: 1px; overflow: hidden; display: none; }
.proc-bar.show { display: block; }
.proc-fill { height: 100%; background: var(--blue); border-radius: 1px; transition: width var(--t-slow); width: 0%; }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { border-right: none; border-bottom: 1px solid var(--border); max-height: 55dvh; height: auto; position: static; }
  #previewCanvas { max-height: 50dvh; }
  .placeholder { width: 140px; }
}
@media (max-width: 560px) {
  .preview-panel { padding: 14px 12px; }
}

@keyframes spin { to { transform: rotate(360deg); } }
.spinning { animation: spin 0.8s linear infinite; }

/* ══════════════════════════════════════════════════════════════
   MODULE 2: CUENTA DE COBRO
   ══════════════════════════════════════════════════════════════ */
.inv-shell { background: var(--bg-2); flex: 1; }

.inv-config-bar {
  position: sticky; top: 48px; z-index: 150;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 10px 20px;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.inv-config-group { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.inv-config-sep { width: 1px; height: 20px; background: var(--border); flex-shrink: 0; }

.inv-config-label {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--text-2); cursor: pointer; white-space: nowrap;
}
.inv-config-label input[type="checkbox"] { width: 14px; height: 14px; accent-color: var(--blue); cursor: pointer; }
.inv-config-label input[type="text"] {
  width: 38px; background: var(--bg); border: 1px solid var(--border);
  border-radius: 4px; padding: 2px 5px; color: var(--text);
  font-size: 11px; text-align: center; font-family: var(--font-sans);
}
input[type="color"]#muestrario {
  width: 24px; height: 24px; border: none; border-radius: 50%;
  cursor: pointer; padding: 0; background: none;
}
.inv-config-spacer { flex: 1; }

.tb-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px;
  border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--bg); color: var(--text-2);
  font-size: 11px; font-weight: 500; letter-spacing: 0.02em;
  cursor: pointer; white-space: nowrap;
  transition: all var(--t-fast); text-decoration: none;
}
.tb-btn:hover { border-color: var(--blue); color: var(--blue); background: var(--blue-dim); text-decoration: none; }
.tb-btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.tb-btn.primary:hover { background: var(--blue); opacity: 0.9; color: #fff; }

.inv-config-toggle {
  display: none;
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text-2); padding: 6px 8px; cursor: pointer; font-size: 14px;
  margin-left: auto;
}
.inv-config-overflow { display: flex; align-items: center; gap: 16px; flex: 1; flex-wrap: wrap; }

@media (max-width: 768px) {
  .inv-config-bar { flex-wrap: wrap; gap: 8px; }
  .inv-config-toggle { display: flex; }
  .inv-config-overflow {
    display: none; flex-basis: 100%; padding: 8px 0 4px;
    border-top: 1px solid var(--border);
    flex-direction: column; align-items: flex-start; gap: 10px;
  }
  .inv-config-overflow.open { display: flex; }
  .inv-config-sep { display: none; }
  .inv-config-group { flex-wrap: wrap; }
}

.page-wrap {
  max-width: 860px;
  margin: 28px auto 60px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05), 0 10px 30px -5px rgba(0,0,0,0.08);
  padding: 40px;
}
@media (max-width: 900px) { .page-wrap { margin: 20px 12px 40px; padding: 24px 18px; border-radius: 10px; } }

@media print {
  .topbar, .inv-config-bar, .global-footer, .invoice-actions, .remove-row-btn, .add-row-btn, #tools-modal,
  .donation-fab, .donation-modal { display: none !important; }
  body { background: #fff; }
  .page-wrap { margin: 0; border: none; border-radius: 0; box-shadow: none; padding: 20px; max-width: none; }
  .view { display: none !important; }
  #view-invoice { display: block !important; }
}

.inv-header {
  display: grid;
  grid-template-columns: 100px 1fr 1fr 1fr;
  gap: 20px;
  padding-bottom: 28px;
  border-bottom: 1px solid var(--border);
  align-items: start;
}
@media (max-width: 640px) {
  .inv-header { grid-template-columns: 1fr 1fr; row-gap: 16px; }
  .inv-header .logo-cell { grid-column: 1 / -1; text-align: center; }
}
@media (max-width: 400px) {
  .inv-header { grid-template-columns: 1fr; }
  .inv-header .logo-cell { text-align: left; }
}

.logo-cell { display: flex; flex-direction: column; align-items: center; gap: 8px; }
#logo-image { max-width: 90px; max-height: 70px; object-fit: contain; display: block; border-radius: 4px; }
.logo-btn {
  font-size: 10px; font-weight: 500; color: var(--text-3);
  background: none; border: 1px solid var(--border); border-radius: 4px;
  padding: 3px 8px; cursor: pointer; transition: all var(--t-fast);
}
.logo-btn:hover { border-color: var(--blue); color: var(--blue); }

.inv-header p { font-size: 12px; color: var(--text-2); line-height: 1.7; }
.inv-header strong { color: var(--text); font-weight: 600; }

[contenteditable="true"] {
  border-radius: 4px;
  transition: background var(--t-fast), outline var(--t-fast);
  outline: none; cursor: text;
}
[contenteditable="true"]:hover { background: var(--blue-dim); }
[contenteditable="true"]:focus { background: var(--blue-dim); outline: 1px solid var(--blue-bdr); }

.inv-meta {
  display: grid; grid-template-columns: 1fr 1fr; gap: 20px;
  margin: 28px 0 0; padding-bottom: 28px; border-bottom: 1px solid var(--border);
}
@media (max-width: 500px) { .inv-meta { grid-template-columns: 1fr; } }

.inv-title { font-size: 26px; font-weight: 700; letter-spacing: -0.03em; color: var(--blue); line-height: 1.1; margin-bottom: 4px; }
.inv-num-row { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-2); margin-bottom: 6px; }
.inv-num-row strong { color: var(--text); font-weight: 600; }

.meta-input {
  background: transparent; border: none; border-bottom: 1px solid var(--border);
  font-size: 12px; color: var(--text); font-family: var(--font-sans);
  padding: 2px 0; width: 110px; transition: border-color var(--t-fast);
}
.meta-input:focus { outline: none; border-color: var(--blue); }

.inv-meta-right { text-align: right; }
.date-row { font-size: 12px; color: var(--text-2); display: flex; align-items: center; gap: 6px; justify-content: flex-end; margin-bottom: 5px; }
.date-row.due { color: var(--red); }
.date-label { font-weight: 600; color: var(--text); min-width: 48px; text-align: right; }

.client-section {
  display: grid; grid-template-columns: 1fr 1fr; gap: 20px;
  margin: 24px 0 0; padding-bottom: 24px; border-bottom: 1px solid var(--border);
}
@media (max-width: 500px) { .client-section { grid-template-columns: 1fr; } }
.client-block p { font-size: 12px; color: var(--text-2); line-height: 1.8; }
.client-block strong { color: var(--text); font-weight: 600; font-size: 12px; }

.detail-table-wrap { margin: 24px 0 0; padding-bottom: 16px; border-bottom: 1px solid var(--border); }
.detail-table { width: 100%; border-collapse: collapse; }
.detail-table th {
  font-size: 10px; font-weight: 600; letter-spacing: 0.07em; text-transform: uppercase;
  color: var(--text-3); padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--border);
}
.detail-table td { padding: 7px 10px; font-size: 12px; color: var(--text-2); border-bottom: 1px solid var(--border); }
@media (max-width: 500px) {
  .detail-table-wrap { overflow-x: auto; }
  .detail-table { min-width: 420px; }
}

.items-wrap { margin: 24px 0 0; }
.items-table { width: 100%; border-collapse: collapse; }
.items-table thead th {
  font-size: 10px; font-weight: 600; letter-spacing: 0.07em; text-transform: uppercase;
  color: var(--text-3); padding: 10px 12px; text-align: left;
  background: var(--bg); border-bottom: 1px solid var(--border);
}
.items-table thead th:last-child { text-align: right; }
.items-table thead th.right { text-align: right; }
.items-table tbody tr { border-bottom: 1px solid var(--border); transition: background var(--t-fast); }
.items-table tbody tr:hover { background: var(--blue-dim); }
.items-table tbody tr:nth-child(even) { background: var(--bg); }
.items-table tbody tr:nth-child(even):hover { background: var(--blue-dim); }
.items-table td { padding: 10px 12px; font-size: 13px; color: var(--text); vertical-align: middle; }
.items-table td.right, .items-table td.sum, .items-table td.tax { text-align: right; }

.item-input {
  background: transparent; border: none; font-size: 13px; font-family: var(--font-sans);
  color: var(--text); width: 100%; padding: 2px 4px; border-radius: 4px;
  transition: background var(--t-fast);
}
.item-input:hover { background: var(--blue-dim); }
.item-input:focus { outline: 1px solid var(--blue-bdr); background: var(--blue-dim); }
.item-input.num { width: 60px; text-align: right; }

.remove-row-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 18px; height: 18px; background: none; border: 1px solid var(--border);
  border-radius: 4px; color: var(--text-3); font-size: 11px;
  cursor: pointer; transition: all var(--t-fast); vertical-align: middle; margin-right: 4px;
}
.remove-row-btn:hover { background: var(--red); border-color: var(--red); color: #fff; opacity: 0.85; }

.add-row-btn {
  display: inline-flex; align-items: center; gap: 6px; margin-top: 12px; padding: 7px 14px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
  font-size: 12px; font-weight: 500; color: var(--text-2); cursor: pointer; transition: all var(--t-fast);
}
.add-row-btn:hover { background: var(--blue-dim); border-color: var(--blue); color: var(--blue); }

.sym::before { content: var(--currency-symbol, '$'); color: var(--text-3); font-size: 11px; margin-right: 1px; }

.pct-input {
  width: 32px; background: transparent; border: none; border-bottom: 1px solid var(--border);
  font-size: 12px; color: var(--text-2); font-family: var(--font-sans);
  text-align: center; padding: 0 1px; transition: border-color var(--t-fast);
}
.pct-input:focus { outline: none; border-color: var(--blue); color: var(--text); }

.subtotal-row { display: none; }
body.show-discount .subtotal-row,
body.show-tax .subtotal-row { display: flex; }

.totals-section { display: flex; justify-content: flex-end; margin: 20px 0 0; padding-bottom: 24px; border-bottom: 1px solid var(--border); }
.totals-box { width: 220px; }
.totals-row { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; font-size: 12px; color: var(--text-2); border-bottom: 1px solid var(--border); }
.totals-row:last-child { border-bottom: none; }
.totals-row.total-main { padding: 12px 0 4px; font-size: 20px; font-weight: 700; color: var(--blue); letter-spacing: -0.02em; }
.totals-row.total-main span:first-child { font-size: 13px; font-weight: 600; color: var(--text); }

.discount-row { display: none; }
.tax-row { display: none; }

.note-section { margin: 24px 0 0; padding: 18px; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; display: none; }
.note-section h3 { font-size: 11px; font-weight: 600; letter-spacing: 0.07em; text-transform: uppercase; color: var(--text-3); margin-bottom: 10px; }
.note-section [contenteditable] { font-size: 12px; color: var(--text-2); line-height: 1.7; }
.note-section ul { padding-left: 16px; }

.inv-footer-note { margin: 28px 0 0; padding: 20px 0 0; border-top: 1px solid var(--border); text-align: center; }
.inv-footer-note p { font-size: 11px; color: var(--text-3); }

#tools-modal {
  display: none; position: fixed; z-index: 9999; top: 80px; right: 20px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: var(--shadow-lg); padding: 14px; width: 200px;
}
.tools-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; padding-bottom: 10px; border-bottom: 1px solid var(--border); }
.tools-title { font-size: 13px; font-weight: 600; color: var(--text); }
.tools-close { background: none; border: none; cursor: pointer; color: var(--text-3); font-size: 18px; line-height: 1; }
.tools-close:hover { color: var(--red); }
.tools-body { display: flex; gap: 6px; flex-wrap: wrap; }
.tool-btn {
  width: 38px; height: 38px; display: flex; align-items: center; justify-content: center;
  background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
  cursor: pointer; font-size: 14px; color: var(--text-2); transition: all var(--t-fast);
}
.tool-btn:hover { background: var(--blue-dim); border-color: var(--blue); color: var(--blue); }

body.show-tax .tax-row { display: flex; }
body.show-tax .col-tax { display: table-cell; }
body.hide-tax .col-tax { display: none; }
body.show-note .note-section { display: block; }
body.show-discount .discount-row { display: flex; }

.tool-topbar-extra { display:flex; align-items:center; gap:8px; }
.accent-picker { width:32px; height:32px; padding:3px; border:1px solid var(--border); border-radius:var(--radius-sm); background:var(--surface); cursor:pointer; flex-shrink:0; }
.accent-picker::-webkit-color-swatch-wrapper { padding:0; }
.accent-picker::-webkit-color-swatch { border:0; border-radius:4px; }
.topbar-brand { text-decoration:none; }
@media (max-width:640px){ .topbar{height:auto; min-height:48px; flex-wrap:wrap; row-gap:8px; padding-block:8px;} .topbar-title{order:5; flex-basis:100%;} .tool-topbar-extra{order:4;} }
@media print{ .topbar,.global-footer,.donation-fab,.donation-modal,.inv-config-bar,#tools-modal,.toast{display:none!important;} body{background:#fff!important;} .view,.view.active,.view.active.flex{display:block!important;min-height:0!important;} .inv-shell{padding:0!important;} .page-wrap{box-shadow:none!important;margin:0 auto!important;border:none!important;} }

.hostinger-marquee { overflow: hidden; background: #090909; border-bottom: 1px solid rgba(103,59,230,.55); white-space: nowrap; }
.hostinger-marquee-track { display: flex; width: max-content; animation: hostinger-scroll 24s linear infinite; }
.hostinger-marquee-content { display: inline-flex; align-items: center; gap: 10px; padding: 9px 36px 9px 0; color: #fff; font-size: 12px; font-weight: 600; }
.hostinger-marquee-content strong { color: #9f87f5; }
.hostinger-marquee-content a { color: #fff; text-decoration: none; border-bottom: 1px solid #673be6; }
.hostinger-marquee-content a:hover { color: #b8a5ff; }
@keyframes hostinger-scroll { from { transform: translateX(0); } to { transform: translateX(-50%); } }
@media (prefers-reduced-motion: reduce) { .hostinger-marquee-track { animation: none; } }
@media print { .hostinger-marquee { display: none !important; } }

.toast.show { opacity: 1 !important; transform: translateY(0) !important; }
.toast.success { border-color: var(--green) !important; color: var(--green) !important; }
.toast.error { border-color: var(--red) !important; color: var(--red) !important; }
