:root {
  color-scheme: light;
  --bg: #f6f4ef;
  --card: #ffffff;
  --ink: #1c1b19;
  --on-ink: #ffffff; /* tekst på --ink: knapper, aktiv fane, avatar */
  --ink-hover: #000000;
  --muted: #6b675f;
  --line: #e4e0d7;
  --line-strong: #cfc9bc;
  --field: #faf9f6;
  --paper: #ffffff; /* logoet vises på hvidt som på fakturaen – i begge temaer */
  --accent: #e8590c;
  --accent-hover: #d14f09;
  --accent-ink: #ffffff;
  --accent-soft: #fdeee4;
  --accent-soft-ink: #7a3206;
  --notice-bg: #fff8f3;
  --notice-line: #f3c9ad;
  --ok: #2f9e44;
  --ok-bg: #e6f4ea;
  --ok-ink: #1e5f2d;
  --danger: #b42318;
  --danger-bg: #fdecea;
  --info-bg: #eef0fb;
  --info-ink: #3b4a9a;
  --shadow: 0 10px 30px rgba(28, 27, 25, 0.12);
  --radius: 14px;
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
}

/* Mørkt tema (sættes af js/theme.js): næsten sort baggrund, mørkegrå kort og felter, lys tekst.
   Accentfarven og mikrofonen er de samme som i det lyse tema. */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121110;
  --card: #1b1a18;
  --ink: #ecebe6;
  --on-ink: #161513;
  --ink-hover: #ffffff;
  --muted: #a39f96;
  --line: #2e2c29;
  --line-strong: #4a4640;
  --field: #232220;
  --accent-soft: #3a2416;
  --accent-soft-ink: #f5b48c;
  --notice-bg: #211915;
  --notice-line: #4d3020;
  --ok: #4cc265;
  --ok-bg: #16281b;
  --ok-ink: #8fdb9f;
  --danger: #f97066;
  --danger-bg: #351816;
  --info-bg: #1c2140;
  --info-ink: #aab5f2;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

/* Temaskift: siden toner blødt over (View Transitions). Kun farve – intet flytter sig. */
::view-transition-old(root),
::view-transition-new(root) { animation-duration: 220ms; animation-timing-function: ease; }

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

/* Klasser med display må ikke vinde over hidden-attributten */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* Top */
.top {
  display: flex; align-items: center; justify-content: space-between;
  max-width: 860px; margin: 0 auto;
  padding: max(14px, env(safe-area-inset-top)) 16px 6px;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; letter-spacing: -0.01em; }
.brand-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }

main {
  max-width: 860px; margin: 0 auto;
  padding: 8px 16px max(40px, env(safe-area-inset-bottom));
  display: grid; gap: 16px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px 18px;
}

h1, h2 { margin: 0 0 6px; letter-spacing: -0.02em; line-height: 1.2; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.2rem; margin-bottom: 16px; }
.hint { margin: 0 0 4px; color: var(--muted); font-size: 0.92rem; }

/* Knapper */
button {
  font: inherit; cursor: pointer; border: 0; border-radius: 10px;
  min-height: 44px; padding: 0 18px;
  transition: transform 160ms var(--ease-out), background-color 160ms ease, opacity 160ms ease;
  -webkit-tap-highlight-color: transparent;
}
button:active:not(:disabled) { transform: scale(0.97); }
button:disabled { opacity: 0.55; cursor: default; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.primary { background: var(--ink); color: var(--on-ink); font-weight: 600; }
.primary.big { width: 100%; min-height: 52px; font-size: 1.05rem; background: var(--accent); color: var(--accent-ink); }
.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.small { min-height: 36px; padding: 0 12px; font-size: 0.9rem; }
@media (hover: hover) {
  .primary:hover:not(:disabled) { background: var(--ink-hover); }
  .primary.big:hover:not(:disabled) { background: var(--accent-hover); }
  .ghost:hover { background: var(--field); }
}

.row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }
.row.end { justify-content: flex-end; }

/* Mikrofon */
.mic-wrap { display: grid; justify-items: center; gap: 8px; margin: 22px 0 18px; }
.mic {
  position: relative;
  width: 96px; height: 96px; border-radius: 50%; padding: 0;
  background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center;
  box-shadow: 0 6px 20px rgba(232, 89, 12, 0.28);
}
.mic::after {
  content: ""; position: absolute; inset: -8px; border-radius: 50%;
  border: 2px solid var(--accent); opacity: 0;
}
.mic[aria-pressed="true"] { background: var(--ink); color: var(--on-ink); box-shadow: 0 6px 20px rgba(0, 0, 0, 0.22); }
.mic[aria-pressed="true"]::after { animation: pulse 1.4s var(--ease-out) infinite; }
@keyframes pulse {
  from { opacity: 0.7; transform: scale(0.92); }
  to { opacity: 0; transform: scale(1.25); }
}
.status { margin: 0; max-width: 46ch; font-size: 0.92rem; color: var(--muted); min-height: 1.5em; text-align: center; text-wrap: pretty; }

/* Felter */
.field { display: grid; gap: 4px; font-size: 0.85rem; color: var(--muted); }
.field em { font-style: normal; opacity: 0.8; }
input, textarea, select {
  font: inherit; font-size: 16px; color: var(--ink);
  width: 100%; min-height: 44px; padding: 10px 12px;
  background: var(--field); border: 1px solid var(--line); border-radius: 10px;
}
textarea { resize: vertical; line-height: 1.45; }
textarea[readonly] { background: var(--accent-soft); }

.grid { display: grid; grid-template-columns: 1fr 1fr; grid-auto-flow: dense; gap: 12px; }
.span2, .span3 { grid-column: 1 / -1; }
@media (min-width: 640px) {
  .card { padding: 28px; }
  .grid { grid-template-columns: repeat(3, 1fr); }
  .span2 { grid-column: span 2; }
}

.error { margin: 12px 0 0; color: var(--danger); font-size: 0.92rem; }

/* Linjer */
.lines-head { display: none; }
.lines { list-style: none; margin: 22px 0 12px; padding: 0; display: grid; gap: 10px; }
.line {
  display: grid; gap: 8px;
  grid-template-columns: 1fr 1fr 1fr;
  padding: 12px; border: 1px solid var(--line); border-radius: 12px;
  animation: line-in 220ms var(--ease-out) both;
}
@keyframes line-in { from { opacity: 0; transform: translateY(4px); } }
.line .desc { grid-column: 1 / -1; }
.line .amount { grid-column: 1 / 3; align-self: center; font-weight: 600; font-variant-numeric: tabular-nums; }
.line .remove { justify-self: end; color: var(--muted); padding: 0 12px; }
.line input { min-height: 40px; padding: 8px 10px; }
.line .num { text-align: right; font-variant-numeric: tabular-nums; }
.line .missing { border-color: var(--accent); background: var(--accent-soft); }
.line label { display: grid; gap: 2px; font-size: 0.75rem; color: var(--muted); }

@media (min-width: 640px) {
  .lines-head, .line {
    grid-template-columns: 1fr 56px 64px 96px 100px 36px;
    align-items: center; gap: 8px;
  }
  .lines-head {
    display: grid; margin-top: 24px; padding: 0 12px;
    font-size: 0.75rem; color: var(--muted);
  }
  .lines-head span:nth-child(2), .lines-head span:nth-child(4), .lines-head span:nth-child(5) { text-align: right; }
  .lines { margin-top: 6px; gap: 6px; }
  .line { padding: 6px 12px; }
  .line .desc, .line .amount { grid-column: auto; }
  .line .amount { text-align: right; font-weight: 500; }
  .line label > span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .line .remove { padding: 0; min-height: 36px; width: 36px; border: 0; }
}

/* Totaler */
.totals { margin: 22px 0 18px; display: grid; gap: 6px; font-variant-numeric: tabular-nums; }
.totals div { display: flex; justify-content: space-between; gap: 16px; }
.totals dt { color: var(--muted); }
.totals dd { margin: 0; }
.totals .grand { border-top: 1px solid var(--line); padding-top: 10px; margin-top: 4px; font-size: 1.15rem; font-weight: 700; }
.totals .grand dt { color: var(--ink); }

/* Dialog */
dialog {
  width: min(560px, calc(100% - 32px)); max-height: calc(100% - 32px);
  border: 0; border-radius: var(--radius); padding: 24px 20px;
  color: var(--ink); background: var(--card);
}
dialog::backdrop { background: rgba(28, 27, 25, 0.45); }
/* ::backdrop arver ikke variabler i ældre browsere, så det mørke tema får sin egen regel */
:root[data-theme="dark"] dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
dialog[open] { animation: dialog-in 200ms var(--ease-out); }
@keyframes dialog-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } }
dialog .grid { margin-top: 16px; }

/* Firmaoplysninger */
.section-title {
  margin: 22px 0 10px; font-size: 0.75rem; font-weight: 650;
  letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted);
}
.field-note { margin: 8px 0 0; font-size: 0.8rem; color: var(--muted); }
/* Profilfelterne står i fast rækkefølge, så fx postnr. og by altid følges ad */
.grid.ordered { grid-auto-flow: row; }
.wide-mobile { grid-column: 1 / -1; }
@media (min-width: 640px) {
  .wide-mobile { grid-column: auto; }
  .span2-desktop { grid-column: span 2; }
}
.logo-field { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.logo-drop {
  display: grid; place-items: center;
  width: 220px; max-width: 100%; height: 96px; padding: 12px;
  background: var(--field); color: var(--muted);
  border: 1.5px dashed var(--line); border-radius: 12px;
  transition: border-color 160ms ease, background-color 160ms ease, transform 160ms var(--ease-out);
}
.logo-drop.dragging { border-color: var(--accent); background: var(--accent-soft); }
@media (hover: hover) { .logo-drop:hover { border-color: var(--line-strong); } }
.logo-drop img { max-width: 100%; max-height: 100%; object-fit: contain; }
.logo-drop:has(img:not([hidden])) { background: var(--paper); border-style: solid; }
.logo-empty { display: grid; justify-items: center; gap: 4px; font-size: 0.9rem; }
.logo-empty strong { color: var(--ink); font-weight: 600; }
.logo-actions { display: flex; gap: 8px; }

/* Hent og send */
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.ghost.big { width: 100%; min-height: 52px; font-size: 1.05rem; font-weight: 600; background: var(--card); }
.primary.accent { background: var(--accent); color: var(--accent-ink); }
@media (hover: hover) { .primary.accent:hover:not(:disabled) { background: var(--accent-hover); } }
.sent {
  display: flex; align-items: center; gap: 8px;
  margin: 12px 0 0; font-size: 0.92rem; color: var(--muted);
}
.sent::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--ok); flex: none; }

/* Send-dialog */
.send-dialog { width: min(600px, calc(100% - 32px)); }
fieldset.bare { border: 0; margin: 0; padding: 0; min-width: 0; display: grid; gap: 12px; }
fieldset.bare:disabled { opacity: 0.7; }
#sendCompose h2 { margin-bottom: 14px; }
#sendMessage { field-sizing: content; min-height: 9lh; max-height: 55vh; }
.attachment {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--field);
}
.attachment svg { color: var(--accent); flex: none; }
.attachment-text { display: grid; min-width: 0; flex: 1; }
.attachment-text strong { font-weight: 600; font-size: 0.92rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachment-text span { font-size: 0.8rem; color: var(--muted); }
.attachment a { color: var(--ink); font-size: 0.9rem; font-weight: 600; padding: 10px 4px; }
.check { display: flex; align-items: center; gap: 10px; font-size: 0.92rem; color: var(--muted); cursor: pointer; }
.check input { width: 20px; height: 20px; min-height: 0; padding: 0; margin: 0; accent-color: var(--accent); flex: none; }
.vat-choice { gap: 8px; }
#onboardForm .vat-choice { margin-top: 16px; }
.vat-choice legend { padding: 0; margin-bottom: 4px; font-size: 0.85rem; color: var(--muted); }
.vat-choice .check { color: var(--ink); }
.send-done { display: grid; justify-items: center; text-align: center; gap: 6px; padding: 12px 0 4px; }
.send-done h2 { margin: 8px 0 0; }
.send-done p { margin: 0 0 16px; max-width: 40ch; }
.done-icon {
  width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center;
  background: var(--ok-bg); color: var(--ok);
  animation: done-in 320ms var(--ease-out) both;
}
@keyframes done-in { from { opacity: 0; transform: scale(0.6); } }

/* Start, login og onboarding */
.boot { margin: 40px 0; text-align: center; color: var(--muted); }
.auth { max-width: 440px; width: 100%; margin: 24px auto 0; }
.auth form { display: grid; gap: 12px; margin-top: 18px; }
.auth .primary.big { margin-top: 4px; }
.auth-links { display: flex; flex-wrap: wrap; gap: 4px 16px; justify-content: center; margin-top: 16px; }
.link {
  background: none; border: 0; padding: 0; min-height: 32px;
  color: var(--ink); text-decoration: underline; text-underline-offset: 3px; font-size: 0.92rem;
}
.info, .notice { margin: 0; padding: 10px 12px; border-radius: 10px; font-size: 0.92rem; }
.info { background: var(--ok-bg); color: var(--ok-ink); }
.notice { background: var(--accent-soft); color: var(--accent-soft-ink); margin: 10px 0 0; }
.notice-card { border-color: var(--notice-line); background: var(--notice-bg); }
.notice-card h2 { margin-bottom: 6px; }
#onboardView .grid { margin-top: 18px; }
#onboardView .primary.big { margin-top: 16px; }

/* Konto, tema og navigation */
.top-actions { display: flex; align-items: center; gap: 8px; }
.icon-btn { position: relative; width: 36px; padding: 0; display: grid; place-items: center; }
.icon-btn svg { grid-area: 1 / 1; transition: opacity 200ms ease, transform 250ms var(--ease-out); }
/* Månen vises i det lyse tema, solen i det mørke; den skjulte drejer lidt væk og toner ud */
.icon-sun, :root[data-theme="dark"] .icon-moon { opacity: 0; transform: rotate(-45deg) scale(0.85); }
:root[data-theme="dark"] .icon-sun { opacity: 1; transform: none; }
/* Fuld trykflade på touch uden at gøre knappen større */
@media (pointer: coarse) { .icon-btn::after { content: ""; position: absolute; inset: -4px; } }
.account { position: relative; }
.account-btn { display: inline-flex; align-items: center; gap: 8px; padding-left: 6px; }
.avatar {
  width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
  background: var(--ink); color: var(--on-ink); font-size: 0.8rem; font-weight: 650;
}
.menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 10; min-width: 220px;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 6px;
  box-shadow: var(--shadow);
  animation: dialog-in 160ms var(--ease-out);
}
.menu button { display: block; width: 100%; text-align: left; background: none; min-height: 40px; padding: 0 12px; border-radius: 8px; }
@media (hover: hover) { .menu button:hover { background: var(--field); } }
.menu-email { margin: 6px 12px 8px; font-size: 0.8rem; color: var(--muted); overflow-wrap: anywhere; }

.tabs {
  display: flex; gap: 4px; max-width: 860px; margin: 4px auto 0; padding: 0 16px;
  overflow-x: auto; scrollbar-width: none;
}
.tabs a {
  flex: none; padding: 9px 14px; border-radius: 999px; color: var(--muted);
  text-decoration: none; font-size: 0.95rem; font-weight: 550;
  transition: background-color 160ms ease, color 160ms ease;
}
.tabs a[aria-current="page"] { background: var(--ink); color: var(--on-ink); }
@media (hover: hover) { .tabs a:not([aria-current]):hover { background: var(--card); color: var(--ink); } }

/* Udkast */
fieldset.plain { border: 0; margin: 0; padding: 0; min-width: 0; }
fieldset.plain:disabled input, fieldset.plain:disabled textarea { background: transparent; border-style: dashed; color: var(--ink); }
fieldset.plain:disabled .remove, fieldset.plain:disabled #addLine { display: none; }
.readonly { display: flex; align-items: center; min-height: 44px; padding: 0 12px; border-radius: 10px; background: var(--bg); color: var(--ink); font-size: 0.95rem; }
.issued { margin: -6px 0 16px; padding: 10px 12px; border-radius: 10px; background: var(--ok-bg); color: var(--ok-ink); font-size: 0.92rem; }

/* Lister: fakturaer og kunder */
.view-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.view-head h1 { margin: 0; }
#invoicesTitle { margin-bottom: 14px; }
.toolbar { display: flex; gap: 10px; margin-bottom: 12px; }
.toolbar .grow { flex: 1; }
.toolbar select { min-width: 132px; }
.list { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 6px; }
.list-item {
  width: 100%; display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 4px 12px;
  padding: 12px 14px; min-height: 60px; text-align: left; font-weight: 400;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; color: var(--ink);
}
@media (hover: hover) { .list-item:hover { background: var(--field); } }
.list-item .chip { grid-column: 1 / -1; justify-self: start; }
@media (min-width: 640px) {
  .list-item { grid-template-columns: 1fr auto 104px; }
  .list-item .chip { grid-column: auto; justify-self: end; }
}
.li-main, .li-side { display: grid; gap: 2px; min-width: 0; }
.li-side { justify-items: end; text-align: right; }
.li-main strong { font-weight: 600; }
.li-sub { font-size: 0.85rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.li-amount { font-variant-numeric: tabular-nums; font-weight: 600; }
.empty { margin: 18px 0 4px; color: var(--muted); text-align: center; font-size: 0.95rem; }

.chip {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  font-size: 0.75rem; font-weight: 600; letter-spacing: 0.01em; white-space: nowrap;
  background: var(--bg); color: var(--muted);
}
.chip.sent { background: var(--ok-bg); color: var(--ok-ink); }
.chip.credited { background: var(--danger-bg); color: var(--danger); }
.chip.credit { background: var(--info-bg); color: var(--info-ink); }

/* Faktura-detalje */
.wide-dialog { width: min(680px, calc(100% - 32px)); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.dialog-head h2 { margin: 0; }
.meta { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0 0 18px; font-size: 0.92rem; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; overflow-wrap: anywhere; }
.meta .link { min-height: 0; font-size: inherit; }
.detail-lines { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.detail-lines li {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; padding: 10px 0;
  border-bottom: 1px solid var(--line); font-size: 0.92rem;
}
.dl-qty { grid-column: 1; color: var(--muted); font-size: 0.85rem; }
.dl-amount { grid-row: 1; grid-column: 2; font-variant-numeric: tabular-nums; }
.totals.compact { margin: 14px 0 6px; font-size: 0.95rem; }
.totals.compact .grand { font-size: 1.05rem; }
.email-log { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font-size: 0.9rem; }
.email-log li { padding: 8px 12px; border-radius: 10px; background: var(--field); }
.email-log li.sent { background: var(--ok-bg); color: var(--ok-ink); }
.email-log li.failed { background: var(--danger-bg); color: var(--danger); }
.email-log li.none { color: var(--muted); }
.dialog-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 20px; }
.dialog-actions .primary { margin-left: auto; }
.danger { color: var(--danger); }
.row.spread { justify-content: space-between; align-items: center; }
.row.tight { margin-top: 0; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition-duration: 0ms !important; }
}
