/* apayable styles — hand-written, served by the Go app (no runtime Tailwind CDN,
   which caused scroll jank). Kept small and dependency-free.

   Theming: all colors are CSS variables. Light is the :root default; dark is
   applied via html[data-theme="dark"] (set by the inline no-flash script + the
   theme.js toggle). A prefers-color-scheme fallback covers the no-JS case. */
:root {
  --bg: #f8fafc;
  --card: #ffffff;
  --ink: #0f172a;
  --muted: #475569;
  --muted-2: #64748b;
  --line: #e2e8f0;
  --surface-2: #f1f5f9;      /* table headers, subtle fills, icon-btn hover */
  --input-bg: #ffffff;
  --input-border: #cbd5e1;
  --accent: #4f46e5;         /* link / interactive text */
  --accent-hover: #4338ca;
  --accent-ring: rgba(79, 70, 229, 0.25);
  --on-accent: #ffffff;      /* text on accent/colored buttons */
  --btn-primary: #4f46e5;    /* primary button bg (kept dark enough for white text) */
  --btn-primary-hover: #6366f1;
  /* semantic status colors (text/badges) */
  --danger: #b91c1c;
  --danger-bg: #fef2f2;
  --danger-border: #fecaca;
  --success: #15803d;
  --warning: #b45309;
  --warning-bg: #fffbeb;
  --warning-border: #fde68a;
  --info: #2563eb;
  /* colored button backgrounds (keep readable white text in both themes) */
  --btn-secondary: #475569;
  --btn-success: #15803d;
  --shadow: rgba(15, 23, 42, 0.08);
  --shadow-sm: rgba(15, 23, 42, 0.06);
}

html[data-theme="dark"] {
  --bg: #0f172a;
  --card: #1e293b;
  --ink: #e2e8f0;
  --muted: #94a3b8;
  --muted-2: #94a3b8;
  --line: #334155;
  --surface-2: #273449;
  --input-bg: #0f172a;
  --input-border: #475569;
  --accent: #a5b4fc;         /* brighter link text for contrast on dark */
  --accent-hover: #c7d2fe;
  --accent-ring: rgba(129, 140, 248, 0.4);
  --btn-primary: #6366f1;    /* filled button bg — white text stays readable */
  --btn-primary-hover: #818cf8;
  --danger: #f87171;
  --danger-bg: #3a1a1a;
  --danger-border: #7f1d1d;
  --success: #4ade80;
  --warning: #fbbf24;
  --warning-bg: #3a2a0a;
  --warning-border: #78530f;
  --info: #60a5fa;
  --btn-secondary: #475569;
  --btn-success: #16a34a;
  --shadow: rgba(0, 0, 0, 0.55);
  --shadow-sm: rgba(0, 0, 0, 0.4);
}

/* No-JS fallback: honor the OS preference when no explicit theme is chosen. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: #0f172a; --card: #1e293b; --ink: #e2e8f0; --muted: #94a3b8; --muted-2: #94a3b8;
    --line: #334155; --surface-2: #273449; --input-bg: #0f172a; --input-border: #475569;
    --accent: #a5b4fc; --accent-hover: #c7d2fe; --accent-ring: rgba(129, 140, 248, 0.4);
    --btn-primary: #6366f1; --btn-primary-hover: #818cf8;
    --danger: #f87171; --danger-bg: #3a1a1a; --danger-border: #7f1d1d;
    --success: #4ade80; --warning: #fbbf24; --warning-bg: #3a2a0a; --warning-border: #78530f;
    --info: #60a5fa; --btn-secondary: #475569; --btn-success: #16a34a;
    --shadow: rgba(0, 0, 0, 0.55); --shadow-sm: rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.15s ease, color 0.15s ease;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

.wrap { max-width: 64rem; margin: 0 auto; padding: 0 1.5rem; }
.topbar { display: flex; align-items: center; gap: 1rem; padding: 1.5rem; max-width: 64rem; margin: 0 auto; }
/* brand takes the slack so any nav links + the theme toggle cluster at the right */
.topbar .brand { margin-right: auto; }
.brand { font-size: 1.25rem; font-weight: 600; letter-spacing: -0.01em; }

.hero { text-align: center; padding: 4rem 0; }
.hero h1 { font-size: clamp(2rem, 5vw, 3rem); font-weight: 700; letter-spacing: -0.02em; margin: 0; }
.hero p { max-width: 42rem; margin: 1.25rem auto 0; font-size: 1.125rem; color: var(--muted); }
.hero .cta { margin-top: 2rem; }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--btn-primary); color: var(--on-accent); font-weight: 500;
  padding: 0.75rem 1.5rem; border-radius: 0.5rem; border: 0; cursor: pointer;
  transition: background-color 0.12s ease;
}
.btn:hover { background: var(--btn-primary-hover); color: var(--on-accent); }
.btn-block { width: 100%; padding: 0.625rem 1rem; }

.btn:disabled { opacity: 0.65; cursor: not-allowed; }
/* Loading state: hide the label and show a spinner (used while a file uploads). */
.btn.loading { color: transparent; pointer-events: none; position: relative; opacity: 0.85; }
.btn.loading:hover { background: var(--btn-primary); }
.btn.loading::after {
  content: ""; position: absolute; inset: 0; margin: auto;
  width: 1rem; height: 1rem;
  border: 2px solid rgba(255, 255, 255, 0.5); border-top-color: #fff; border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Square icon-only buttons (download / delete on catalog cards). */
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 2.5rem; height: 2.5rem; padding: 0;
  background: var(--card); color: var(--muted);
  border: 1px solid var(--line); border-radius: 0.5rem; cursor: pointer;
  transition: background-color 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn svg { width: 1.1rem; height: 1.1rem; display: block; }
.icon-btn.icon-danger:hover { background: var(--danger-bg); color: var(--danger); border-color: var(--danger-border); }

.features { display: grid; gap: 1.5rem; grid-template-columns: 1fr; grid-auto-rows: 1fr; padding-bottom: 4rem; }
@media (min-width: 640px) { .features { grid-template-columns: repeat(3, 1fr); } }
.feature { display: flex; flex-direction: column; background: var(--card); border: 1px solid var(--line); border-radius: 0.75rem; padding: 1.5rem; box-shadow: 0 1px 2px var(--shadow-sm); }
.feature .card-actions { margin-top: auto; padding-top: 0.75rem; }
.feature h3 { margin: 0; font-size: 1rem; font-weight: 600; }
.feature p { margin: 0.5rem 0 0; font-size: 0.875rem; color: var(--muted); }

.signup { max-width: 28rem; margin: 0 auto; padding-bottom: 6rem; }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: 1rem; padding: 2rem; box-shadow: 0 4px 12px var(--shadow); }
.panel h2 { margin: 0; font-size: 1.5rem; font-weight: 700; }
.panel .sub { margin: 0.25rem 0 1.5rem; color: var(--muted); }
.field { display: block; margin-bottom: 1rem; }
.field span { display: block; font-size: 0.875rem; font-weight: 500; margin-bottom: 0.25rem; }
.field input {
  width: 100%; padding: 0.5rem 0.75rem; border: 1px solid var(--input-border); border-radius: 0.5rem;
  font: inherit; color: var(--ink); background: var(--input-bg);
}
.field input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-ring); }
.fineprint { text-align: center; font-size: 0.75rem; color: var(--muted-2); margin-top: 0.75rem; }

.plans { border: 0; padding: 0; margin: 0 0 1rem; display: grid; gap: 0.5rem; }
.plans legend { font-size: 0.875rem; font-weight: 500; margin-bottom: 0.25rem; padding: 0; }
.plan { display: flex; align-items: flex-start; gap: 0.625rem; border: 1px solid var(--input-border); border-radius: 0.5rem; padding: 0.75rem; cursor: pointer; transition: border-color 0.12s ease, box-shadow 0.12s ease; }
.plan:hover { border-color: var(--accent); }
.plan:has(input:checked) { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-ring); }
.plan input { margin-top: 0.2rem; }
.plan-body { display: flex; flex-direction: column; gap: 0.15rem; }
.plan-head { display: flex; align-items: baseline; gap: 0.5rem; }
.plan-price { font-size: 0.8125rem; color: var(--accent); font-weight: 600; }
.plan-feat { font-size: 0.8125rem; color: var(--muted); }

.field select {
  width: 100%; padding: 0.5rem 0.75rem; border: 1px solid var(--input-border); border-radius: 0.5rem;
  font: inherit; color: var(--ink); background: var(--input-bg);
}
.field select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-ring); }

table.preview { border-collapse: collapse; width: 100%; font-size: 0.8125rem; }
table.preview th, table.preview td {
  border: 1px solid var(--line); padding: 0.35rem 0.5rem; text-align: left; white-space: nowrap;
}
table.preview th { background: var(--surface-2); font-weight: 600; }
/* Text inputs inside data tables (invoice coding grid) inherit the theme. */
table.preview input, table.preview select {
  background: var(--input-bg); color: var(--ink);
  border: 1px solid var(--input-border); border-radius: 0.3rem;
  padding: 0.25rem 0.4rem; font: inherit;
}

.note { text-align: center; max-width: 36rem; margin: 0 auto; padding: 6rem 1.5rem; }
.note h1 { font-size: 1.875rem; font-weight: 700; }
.note p { color: var(--muted); }
.addr { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-weight: 600; color: var(--accent); }

footer { border-top: 1px solid var(--line); padding: 2rem 0; text-align: center; font-size: 0.875rem; color: var(--muted-2); }

/* Dark-mode toggle, injected by theme.js — into the header top-right when a
   .topbar exists, otherwise floated top-right (login/welcome). */
.theme-toggle {
  width: 2.5rem; height: 2.5rem; border-radius: 999px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--card); color: var(--ink);
  border: 1px solid var(--line);
  cursor: pointer; font-size: 1.1rem; line-height: 1; padding: 0;
  transition: background-color 0.12s ease, border-color 0.12s ease, transform 0.12s ease;
}
.theme-toggle:hover { background: var(--surface-2); transform: translateY(-1px); }
.theme-toggle:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-ring); }
.theme-toggle.floating {
  position: fixed; top: 1rem; right: 1rem; z-index: 50;
  box-shadow: 0 4px 12px var(--shadow);
}
