/* Faturista — design system
   Drop into static/app.css, link from base.html. No Bootstrap dependency.
*/

:root {
  --bg: #FAF8F5;
  --bg-2: #F5F2EC;
  --bg-elev: #FFFFFF;
  --ink: #141413;
  --ink-2: #3A3936;
  --muted: #8A857D;
  --muted-2: #B8B3AA;
  --line: #E8E4DC;
  --line-2: #F0ECE3;
  --accent: #3B4A2B;
  --accent-soft: #EEF0E6;
  --ok: #4A6B3A;    --ok-soft: #EBF0E4;
  --warn: #8B6914;  --warn-soft: #F4ECD8;
  --err: #8B2E2E;   --err-soft: #F5E4E1;
  --dup: #6B6660;   --dup-soft: #EEEAE2;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg); color: var(--ink);
  font-size: 14px; line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
.mono { font-family: 'JetBrains Mono', ui-monospace, monospace; }
.serif { font-family: 'Instrument Serif', serif; }
.dim { color: var(--muted-2); }

/* Layout shell */
.app { display: grid; grid-template-columns: 220px 1fr; grid-template-rows: 60px 1fr; min-height: 100vh; max-width: 1800px; margin: 0 auto; }
.topbar { grid-column: 1 / 3; grid-row: 1; background: var(--bg); border-bottom: 1px solid var(--line); }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; height: 100%; padding: 0 24px; gap: 24px; }
.brand { display: flex; align-items: baseline; gap: 10px; text-decoration: none; color: var(--ink); }
.brand-mark { width: 22px; height: 22px; border-radius: 50%; background: var(--accent); position: relative; display: inline-block; transform: translateY(3px); flex-shrink: 0; }
.brand-mark::after { content:""; position:absolute; inset: 5px 5px auto auto; width: 6px; height: 6px; background: var(--bg); border-radius: 50%; }
.brand-name { font-family: 'Instrument Serif', serif; font-size: 24px; letter-spacing: -0.01em; }
.brand-name em { font-style: italic; color: var(--muted); }
.crumbs { font-size: 13px; color: var(--muted); display: flex; gap: 8px; align-items: center; }
.crumb-cur { color: var(--ink); font-weight: 500; }
.crumb-link { color: var(--muted); text-decoration: none; }
.crumb-link:hover { color: var(--ink); text-decoration: underline; }
.topbar-right { display: flex; align-items: center; gap: 6px; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--accent); color: var(--bg); font-size: 11px; font-weight: 600; display: flex; align-items: center; justify-content: center; }

.sidenav { grid-column: 1; grid-row: 2; border-right: 1px solid var(--line); padding: 20px 14px; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 6px; color: var(--ink-2); font-size: 13px; font-weight: 500; text-decoration: none; cursor: pointer; }
.nav-item:hover { background: var(--bg-2); }
.nav-item.active { background: var(--ink); color: var(--bg); }
.nav-item span:nth-child(2) { flex: 1; }
.nav-badge { font-size: 11px; padding: 1px 6px; border-radius: 10px; background: var(--line); color: var(--muted); }
.nav-item.active .nav-badge { background: rgba(255,255,255,.15); color: var(--bg); }

.main { grid-column: 2; grid-row: 2; padding: 36px 44px 60px; }
.main-full { grid-column: 1 / 3; }

/* Buttons */
.btn { font-family: inherit; font-size: 13px; font-weight: 500; color: var(--ink-2); background: transparent; border: 1px solid transparent; padding: 7px 12px; border-radius: 7px; cursor: pointer; display: inline-flex; align-items: center; gap: 7px; transition: all .12s; white-space: nowrap; text-decoration: none; }
.btn:hover { background: var(--bg-2); color: var(--ink); }
.btn-outline { border-color: var(--line); background: var(--bg-elev); }
.btn-outline:hover { border-color: var(--muted-2); }
.btn-primary { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.btn-primary:hover { background: var(--ink-2); color: var(--bg); }
.btn-primary:disabled { background: var(--muted-2); border-color: var(--muted-2); cursor: not-allowed; }
.btn-tiny { padding: 4px 9px; font-size: 12px; }
.btn-ghost { color: var(--muted); }
.icon-btn { background: none; border: none; color: var(--muted); width: 30px; height: 30px; border-radius: 6px; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
.icon-btn:hover { background: var(--bg-2); color: var(--ink); }
.icon { width: 14px; height: 14px; }

/* Type primitives */
.eyebrow { font-size: 11px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); font-weight: 500; margin-bottom: 6px; }
.hero-title { font-family: 'Instrument Serif', serif; font-size: 48px; font-weight: 400; letter-spacing: -0.02em; line-height: 1.05; margin: 0; }
.hero-sub { color: var(--muted); font-size: 14px; margin: 6px 0 0; }
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-weight: 600; margin: 28px 0 14px; }
.panel { background: var(--bg-elev); border: 1px solid var(--line); border-radius: 10px; }

/* Page heads */
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 24px; margin-bottom: 24px; }

/* Stats strip */
.q-stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 18px 0; margin-bottom: 28px; }
.stat { padding: 0 24px; border-right: 1px solid var(--line-2); }
.stat:last-child { border-right: none; }
.stat-label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 500; margin-bottom: 6px; }
.stat-value { font-size: 22px; font-weight: 500; letter-spacing: -0.01em; font-family: 'JetBrains Mono', monospace; }
.stat .cur { color: var(--muted-2); font-weight: 400; margin-right: 2px; }

/* Category cards */
.cat-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.cat-card { background: var(--bg-elev); border: 1px solid var(--line); border-radius: 10px; padding: 18px; position: relative; overflow: hidden; }
.cat-card::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; }
.cat-card.cat-PT::before { background: #3B4A2B; }
.cat-card.cat-EU_GOODS::before { background: #3B3F52; }
.cat-card.cat-EU_SERVICES::before { background: #6B4D2B; }
.cat-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.cat-count { font-size: 12px; color: var(--muted); font-family: 'JetBrains Mono', monospace; }
.cat-title { font-family: 'Instrument Serif', serif; font-size: 22px; margin-bottom: 14px; }
.cat-nums { display: flex; flex-direction: column; gap: 6px; font-size: 13px; padding-bottom: 10px; border-bottom: 1px solid var(--line-2); margin-bottom: 10px; }
.cat-nums > div { display: flex; justify-content: space-between; }
.cat-nums .k { color: var(--muted); }
.cat-total .v { font-weight: 600; color: var(--ink); }

/* Category tags */
.cat-tag { display: inline-block; font-size: 11px; font-weight: 500; padding: 2px 7px; border-radius: 20px; }
.cat-tag.cat-PT { background: #EEF0E6; color: #3B4A2B; }
.cat-tag.cat-EU_GOODS { background: #EAEBEF; color: #3B3F52; }
.cat-tag.cat-EU_SERVICES { background: #F1E9DE; color: #6B4D2B; }

/* Country flag + RC tag */
.cc-flag { display: inline-block; font-family: 'JetBrains Mono', monospace; font-size: 10px; font-weight: 500; padding: 1px 5px; margin-right: 8px; background: var(--bg-2); color: var(--muted); border-radius: 3px; letter-spacing: .04em; vertical-align: 1px; }
.rc-tag { display: inline-block; font-family: 'JetBrains Mono', monospace; font-size: 10px; font-weight: 500; padding: 1px 5px; margin-left: 6px; background: #F1E9DE; color: #6B4D2B; border-radius: 3px; letter-spacing: .04em; vertical-align: 1px; }

/* Tabs */
.tabs { display: flex; align-items: center; gap: 4px; margin-bottom: 14px; border-bottom: 1px solid var(--line); }
.tab { background: none; border: none; padding: 10px 14px; font-family: inherit; font-size: 13px; color: var(--muted); cursor: pointer; display: flex; align-items: center; gap: 8px; border-bottom: 2px solid transparent; margin-bottom: -1px; font-weight: 500; text-decoration: none; }
.tab:hover { color: var(--ink-2); }
.tab.active { color: var(--ink); border-bottom-color: var(--ink); }
.tab-count { font-size: 11px; padding: 1px 7px; border-radius: 10px; background: var(--line-2); color: var(--muted); font-family: 'JetBrains Mono', monospace; }
.tab.active .tab-count { background: var(--ink); color: var(--bg); }

/* Quarter select */
.q-select { font-family: inherit; font-size: 13px; padding: 7px 28px 7px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg-elev) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23888'/%3E%3C/svg%3E") no-repeat right 10px center; color: var(--ink); cursor: pointer; appearance: none; }

/* Invoice table */
table.invoices { width: 100%; border-collapse: collapse; font-size: 13px; }
table.invoices thead th { text-align: left; font-size: 11px; font-weight: 500; color: var(--muted); letter-spacing: 0.06em; text-transform: uppercase; padding: 14px; border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--bg-2); }
table.invoices thead th.num { text-align: right; }
table.invoices tbody td { padding: 14px; border-bottom: 1px solid var(--line-2); color: var(--ink-2); }
table.invoices tbody tr:last-child td { border-bottom: none; }
table.invoices tbody tr:hover { background: var(--bg-2); }
table.invoices tr.row-warn { background: linear-gradient(to right, #FDF7EA 0%, transparent 40%); }
.warn-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--warn); display: inline-block; }
td.num { text-align: right; font-family: 'JetBrains Mono', monospace; }
td.inv-no { font-family: 'JetBrains Mono', monospace; font-size: 12.5px; color: var(--ink); }
td.date { color: var(--muted); white-space: nowrap; }
td.supplier { color: var(--ink); font-weight: 500; max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
td.nif { font-family: 'JetBrains Mono', monospace; color: var(--muted); font-size: 12px; white-space: nowrap; }
td.total { color: var(--ink); font-weight: 600; }
.row-act { background: none; border: 1px solid transparent; color: var(--muted); width: 24px; height: 24px; border-radius: 4px; cursor: pointer; }
tr:hover .row-act { border-color: var(--line); background: var(--bg-elev); }

.list-foot { display: flex; justify-content: space-between; align-items: center; padding: 14px 20px; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); }
.list-foot .totals { display: flex; gap: 24px; }
.list-foot .totals .v { color: var(--ink); font-weight: 500; font-family: 'JetBrains Mono', monospace; margin-left: 6px; }

/* Dropzone */
.dropzone { border: 1.5px dashed var(--line); border-radius: 8px; padding: 36px 20px; text-align: center; cursor: pointer; transition: border-color .15s, background .15s; background: var(--bg); }
.dropzone:hover { border-color: var(--muted-2); background: var(--bg-2); }
.dropzone.drag-over { border-color: var(--accent); background: var(--accent-soft); border-style: solid; }
.dropzone input[type=file] { display: none; }
.dz-icon { width: 36px; height: 36px; margin: 0 auto 12px; border: 1px solid var(--line); border-radius: 8px; display: flex; align-items: center; justify-content: center; background: var(--bg-elev); color: var(--ink-2); }
.dz-title { font-size: 13px; font-weight: 500; color: var(--ink); margin: 0 0 4px; }
.dz-sub { font-size: 12px; color: var(--muted); margin: 0; }

/* Export cards */
.export-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 32px; }
.export-card { background: var(--bg-elev); border: 1px solid var(--line); border-radius: 12px; padding: 20px; display: flex; flex-direction: column; }
.ec-title { font-family: 'Instrument Serif', serif; font-size: 26px; line-height: 1.1; margin-bottom: 2px; }
.ec-sub { font-size: 12px; color: var(--muted); margin-bottom: 16px; }
.ec-totals { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; margin-bottom: 14px; }
.ec-totals > div { display: flex; justify-content: space-between; }
.ec-totals .k { color: var(--muted); }
.ec-total { padding-top: 6px; border-top: 1px solid var(--line-2); }
.ec-total .v { font-weight: 600; color: var(--ink); }
.ec-filename { font-size: 11px; color: var(--muted); background: var(--bg-2); padding: 6px 10px; border-radius: 6px; margin-bottom: 12px; font-family: 'JetBrains Mono', monospace; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ec-btn { width: 100%; justify-content: center; padding: 9px; }

/* Badge */
.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 500; padding: 2px 8px; border-radius: 20px; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.err { background: var(--err-soft); color: var(--err); }
.badge.dup { background: var(--dup-soft); color: var(--dup); }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(20, 20, 19, 0.35); display: none; align-items: center; justify-content: center; z-index: 50; }
.modal-backdrop.open { display: flex; }
.modal { background: var(--bg-elev); border-radius: 12px; width: min(480px, 92vw); max-height: 80vh; overflow: hidden; display: flex; flex-direction: column; }
.modal-head { padding: 20px 24px 12px; display: flex; justify-content: space-between; }
.modal-body { padding: 4px 24px 20px; overflow-y: auto; }
.modal-foot { padding: 14px 24px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }

.htmx-indicator { display: none; }
.htmx-request .htmx-indicator,
.htmx-indicator.htmx-request { display: flex; }

.upload-overlay {
  position: absolute; inset: 0; border-radius: 12px;
  background: rgba(250,248,245, 0.85);
  backdrop-filter: blur(2px);
  align-items: center; justify-content: center; z-index: 10;
}
.upload-overlay-content {
  text-align: center; font-size: 15px; font-weight: 500; color: var(--ink);
}
.upload-overlay-content p { margin: 12px 0 0; }

.spinner-ring {
  width: 32px; height: 32px; margin: 0 auto;
  border: 3px solid var(--line);
  border-top-color: var(--accent, #6366f1);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Mobile placeholder */
.mobile-placeholder {
  display: none;
  min-height: 100vh;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
}
.mobile-placeholder p {
  font-size: 16px;
  color: var(--muted);
  font-weight: 500;
  margin: 0;
}

@media (max-width: 768px) {
  .mobile-placeholder { display: flex; }
  .app { display: none !important; }
  .sidenav { display: none !important; }
  .main { display: none !important; }
  .landing { display: none !important; }
}

/* Landing page */
.landing { max-width: 960px; margin: 0 auto; padding: 0 24px; }
.landing-nav { display: flex; align-items: center; justify-content: space-between; padding: 16px 0; border-bottom: 1px solid var(--line); margin-bottom: 48px; }
.landing-hero { text-align: center; padding: 40px 0 56px; display: flex; flex-direction: column; align-items: center; }
.landing-sub { color: var(--muted); font-size: 16px; line-height: 1.6; max-width: 520px; margin: 12px auto 0; }
.landing-section { padding: 40px 0; }
.landing-features { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.landing-feature { padding: 24px; }
.landing-feature-icon { width: 44px; height: 44px; border-radius: 10px; display: flex; align-items: center; justify-content: center; margin-bottom: 14px; }
.landing-feature-title { font-size: 15px; font-weight: 600; margin: 0 0 6px; }
.landing-feature-desc { font-size: 13px; color: var(--muted); line-height: 1.5; margin: 0; }
.billing-toggle { display: flex; justify-content: center; gap: 4px; margin: 0 auto 24px; background: var(--line-2); border-radius: 999px; padding: 4px; width: fit-content; }
.billing-opt { border: none; background: transparent; color: var(--muted); font-size: 13px; font-weight: 500; padding: 7px 18px; border-radius: 999px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.billing-opt.is-active { background: var(--surface, #fff); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.billing-save { font-size: 11px; color: var(--ok); font-weight: 600; }
.landing-pricing { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; max-width: 640px; margin: 0 auto; }
.landing-pricing-4 { grid-template-columns: repeat(4, 1fr); max-width: 980px; }
.landing-price-card { padding: 28px 24px; display: flex; flex-direction: column; position: relative; }
.landing-price-featured { border: 2px solid var(--ink); }
.landing-price-badge { position: absolute; top: -10px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--surface, #fff); font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; padding: 3px 10px; border-radius: 999px; white-space: nowrap; }
.landing-price-tier { font-size: 18px; font-weight: 600; margin-bottom: 4px; }
.landing-price-tagline { font-size: 13px; color: var(--muted); margin-bottom: 16px; min-height: 34px; }
.landing-price-amount { font-family: 'Instrument Serif', serif; font-size: 28px; margin-bottom: 14px; }
.landing-price-amount .price-per { font-family: inherit; font-size: 14px; color: var(--muted); }
.landing-price-amount .price-eq { font-family: var(--font-sans, inherit); font-size: 13px; color: var(--muted); font-weight: 400; }
.landing-price-note { font-size: 12px; color: var(--muted); margin-bottom: 14px; }
.landing-pricing[data-billing="monthly"] .price-annual { display: none; }
.landing-pricing[data-billing="annual"] .price-monthly { display: none; }
@media (max-width: 860px) { .landing-pricing-4 { grid-template-columns: 1fr 1fr; } }
.landing-price-list { list-style: none; padding: 0; margin: 0 0 24px; flex: 1; }
.landing-price-list li { font-size: 13px; color: var(--ink-2); padding: 5px 0; border-bottom: 1px solid var(--line-2); }
.landing-price-list li::before { content: "\2713\00a0"; color: var(--ok); font-weight: 600; }
.landing-trust { border-top: 1px solid var(--line); }
.landing-footer { display: flex; align-items: center; justify-content: space-between; padding: 20px 0; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); }
.landing-footer a { color: var(--muted); text-decoration: none; font-size: 12px; }
.landing-footer a:hover { color: var(--ink); }
