:root {
  color-scheme: light;
  --desktop: #008080;
  --face: #c0c0c0;
  --face-2: #d4d0c8;
  --field: #fff;
  --ink: #000;
  --muted: #4b4b4b;
  --light: #fff;
  --mid-light: #dfdfdf;
  --shadow: #808080;
  --dark-shadow: #404040;
  --title: #000080;
  --title-end: #1084d0;
  --title-text: #fff;
  --link: #000080;
  --danger: #800000;
  --focus: #000;
  --raised: inset 1px 1px var(--light), inset -1px -1px var(--dark-shadow), inset 2px 2px var(--mid-light), inset -2px -2px var(--shadow);
  --sunken: inset 1px 1px var(--dark-shadow), inset -1px -1px var(--light), inset 2px 2px var(--shadow), inset -2px -2px var(--mid-light);
}

[data-theme="dark"] {
  color-scheme: dark;
  --desktop: #192526;
  --face: #30343a;
  --face-2: #3b4047;
  --field: #181b1f;
  --ink: #f2f2f2;
  --muted: #c0c4c8;
  --light: #646b73;
  --mid-light: #4c5259;
  --shadow: #202328;
  --dark-shadow: #090a0c;
  --title: #182c61;
  --title-end: #315b94;
  --title-text: #fff;
  --link: #9abfff;
  --danger: #ff9b9b;
  --focus: #fff;
}

[data-theme="nt"] {
  color-scheme: light;
  --desktop: #3f5368;
  --face: #d5d2c9;
  --face-2: #e7e5df;
  --field: #fff;
  --ink: #101820;
  --muted: #4e5861;
  --light: #fff;
  --mid-light: #eceae4;
  --shadow: #8b8b86;
  --dark-shadow: #343b42;
  --title: #24364f;
  --title-end: #58728f;
  --title-text: #fff;
  --link: #173d70;
  --danger: #8a1f1f;
  --focus: #101820;
}

[data-theme="ce"] {
  color-scheme: light;
  --desktop: #6f9fc4;
  --face: #e7edf2;
  --face-2: #d4e1eb;
  --field: #fff;
  --ink: #102335;
  --muted: #53697a;
  --light: #fff;
  --mid-light: #edf5fa;
  --shadow: #879baa;
  --dark-shadow: #39546a;
  --title: #17659c;
  --title-end: #55a7d6;
  --title-text: #fff;
  --link: #064f85;
  --danger: #9c2525;
  --focus: #102335;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    color-scheme: dark;
    --desktop: #192526;
    --face: #30343a;
    --face-2: #3b4047;
    --field: #181b1f;
    --ink: #f2f2f2;
    --muted: #c0c4c8;
    --light: #646b73;
    --mid-light: #4c5259;
    --shadow: #202328;
    --dark-shadow: #090a0c;
    --title: #182c61;
    --title-end: #315b94;
    --title-text: #fff;
    --link: #9abfff;
    --danger: #ff9b9b;
    --focus: #fff;
  }
}

* { box-sizing: border-box; }
html { min-height: 100%; font: 13px/1.35 Tahoma, "MS Sans Serif", Arial, sans-serif; background: var(--desktop); color: var(--ink); }
body { margin: 0; min-width: 320px; background: var(--desktop); }
button, input, select, textarea { font: inherit; }
button, .button { cursor: default; }
a { color: var(--link); }
.skip-link { position: fixed; z-index: 60; left: 6px; top: -50px; padding: 7px 10px; background: var(--field); color: var(--ink); border: 2px solid var(--focus); }
.skip-link:focus { top: 6px; }

.masthead { max-width: 1220px; margin: 10px auto 0; padding: 3px; background: var(--face); box-shadow: var(--raised); }
.service-bar { min-height: 26px; padding: 5px 7px; color: var(--title-text); background: linear-gradient(90deg, var(--title), var(--title-end)); font-weight: 700; letter-spacing: 0; }
.service-bar::before { content: "▣"; margin-right: 6px; }
.brand-row { min-height: 70px; display: flex; align-items: center; justify-content: space-between; gap: 15px; padding: 8px 10px; border-bottom: 1px solid var(--shadow); }
.brand { display: flex; gap: 9px; align-items: center; color: var(--ink); text-decoration: none; }
.brand-mark { display: grid; place-items: center; width: 42px; height: 42px; color: #fff; background: linear-gradient(135deg, #000080 0 49%, #008080 50%); border: 1px solid var(--dark-shadow); box-shadow: 1px 1px var(--light); font: 700 24px Tahoma, sans-serif; }
.brand strong { display: block; font-size: 23px; line-height: 1; letter-spacing: -.5px; }
.brand small { display: block; margin-top: 5px; color: var(--muted); font-size: 11px; }
.header-tools { display: flex; align-items: end; justify-content: flex-end; gap: 7px; color: var(--muted); font-size: 11px; }
.company-picker { min-width: 165px; }
.company-picker select { padding: 4px 23px 4px 6px; }

nav { display: flex; gap: 2px; padding: 4px 5px 5px; border-top: 1px solid var(--light); overflow-x: auto; }
nav a { flex: 0 0 auto; padding: 5px 9px; color: var(--ink); text-decoration: none; border: 1px solid transparent; }
nav a:hover { border-color: var(--light) var(--shadow) var(--shadow) var(--light); }
nav a.active { border-color: var(--shadow) var(--light) var(--light) var(--shadow); background: var(--face-2); }
nav a::first-letter { text-decoration: underline; }

main { max-width: 1220px; min-height: calc(100vh - 205px); margin: 0 auto; padding: 18px 16px 45px; background: var(--face); border: 3px solid var(--face); box-shadow: var(--raised); }
.page { display: none; }
.page.active { display: block; }
.page-heading { display: flex; justify-content: space-between; align-items: end; gap: 16px; margin-bottom: 12px; padding: 5px 7px; color: var(--title-text); background: linear-gradient(90deg, var(--title), var(--title-end)); }
h1, h2 { margin: 0; font-family: Tahoma, "MS Sans Serif", Arial, sans-serif; }
h1 { font-size: 16px; line-height: 25px; }
h2 { font-size: 13px; }
.eyebrow { margin: 0; color: color-mix(in srgb, var(--title-text) 80%, transparent); font-size: 10px; font-weight: 400; }

.primary, .secondary, .button, .icon-button, .quiet-button {
  display: inline-block;
  min-height: 27px;
  padding: 5px 12px;
  border: 0;
  border-radius: 0;
  color: var(--ink);
  background: var(--face);
  box-shadow: var(--raised);
  text-decoration: none;
  font-weight: 400;
  font-size: 12px;
}
.primary { font-weight: 700; }
.primary:active, .secondary:active, .button:active, .icon-button:active, .quiet-button:active { padding: 6px 11px 4px 13px; box-shadow: var(--sunken); }
.compact { min-height: 24px; padding: 4px 8px; }
.icon-button { width: 29px; height: 27px; padding: 2px; font-size: 16px; line-height: 20px; }
.page-heading .primary { color: var(--ink); }

button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 1px dotted var(--focus);
  outline-offset: -4px;
}

.summary-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 12px; }
.summary-grid article { min-width: 0; padding: 12px; background: var(--face-2); box-shadow: var(--raised); }
.summary-grid span, .summary-grid small { display: block; color: var(--muted); font-size: 11px; }
.summary-grid strong { display: block; margin: 7px 0 5px; font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.two-columns { display: grid; grid-template-columns: 1.65fr 1fr; gap: 10px; }
.panel { min-width: 0; padding: 3px; background: var(--face); box-shadow: var(--raised); }
.panel-head, .subheading { display: flex; align-items: center; justify-content: space-between; min-height: 29px; padding: 5px 7px; background: var(--face-2); border-bottom: 1px solid var(--shadow); }
.panel-head h2::before { content: "▦ "; color: var(--title); }
.panel-head a { font-size: 11px; }
.settings-section { margin-top: 12px; }

.table-scroll { overflow-x: auto; background: var(--field); box-shadow: var(--sunken); }
table { width: 100%; border-collapse: collapse; background: var(--field); font-size: 12px; }
th { color: var(--ink); background: var(--face); text-align: left; font-size: 11px; font-weight: 400; box-shadow: inset -1px -1px var(--shadow), inset 1px 1px var(--light); }
th, td { padding: 7px 8px; border-right: 1px solid var(--face-2); border-bottom: 1px solid var(--face-2); vertical-align: top; }
tbody tr:hover { background: color-mix(in srgb, var(--title-end) 18%, var(--field)); }
.number { text-align: right; font-variant-numeric: tabular-nums; }
.empty { padding: 35px 18px; color: var(--muted); text-align: center; background: var(--field); box-shadow: var(--sunken); }
.status { display: inline-block; min-width: 64px; padding: 2px 5px; color: var(--ink); background: var(--face); border: 1px solid var(--shadow); text-align: center; font-size: 11px; }
.status.paid { color: #006400; }
[data-theme="dark"] .status.paid { color: #86dc86; }
.status.overdue, .danger { color: var(--danger); }
.danger-border { color: var(--danger); }
.task-list { min-height: 120px; margin: 0; padding: 12px 20px 12px 31px; background: var(--field); box-shadow: var(--sunken); list-style: square; }
.task-list li { padding: 3px 0; }

.form-panel { padding: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px 14px; }
.form-grid .wide { grid-column: 1 / -1; }
label { display: flex; flex-direction: column; gap: 4px; color: var(--ink); font-size: 11px; font-weight: 400; }
.checkbox { flex-direction: row; align-items: center; align-self: end; min-height: 28px; }
.checkbox input, .row-check { width: auto; min-height: auto; }
input, select, textarea {
  width: 100%;
  min-height: 27px;
  padding: 5px 7px;
  color: var(--ink);
  background: var(--field);
  border: 0;
  border-radius: 0;
  box-shadow: var(--sunken);
}
select { padding-right: 24px; }
input:focus, select:focus, textarea:focus { outline: 1px dotted var(--focus); outline-offset: -4px; }
.form-actions { display: flex; justify-content: flex-end; gap: 7px; margin-top: 15px; padding-top: 10px; border-top: 1px solid var(--shadow); box-shadow: inset 0 1px var(--light); }
.subheading { margin: 16px -14px 10px; border-top: 1px solid var(--light); }
.invoice-line { display: grid; grid-template-columns: 1.3fr 2fr .6fr .7fr 1fr .7fr .7fr 30px; gap: 7px; margin-bottom: 8px; align-items: end; }
.invoice-line .icon-button { height: 27px; }

.registry-tools { display: flex; gap: 6px; align-items: center; padding: 7px; background: var(--face); border-bottom: 1px solid var(--shadow); box-shadow: inset 0 1px var(--light); }
.registry-search { display: flex; align-items: center; flex: 1; min-width: 190px; max-width: 360px; color: var(--muted); background: var(--field); box-shadow: var(--sunken); }
.registry-search span { padding-left: 7px; }
.registry-search input { min-width: 0; padding-left: 6px; background: transparent; box-shadow: none; }
.registry-filters, .registry-bulk { display: flex; align-items: center; gap: 5px; }
.registry-bulk { margin-left: auto; padding-left: 7px; border-left: 1px solid var(--shadow); box-shadow: inset 1px 0 var(--light); }
.registry-tools select { width: auto; max-width: 170px; min-height: 27px; font-size: 11px; }
.quiet-button { min-height: 27px; padding: 5px 8px; }

.drop-zone { padding: 18px; text-align: center; background: var(--field); border: 1px dotted var(--ink); box-shadow: var(--sunken); }
.drop-zone.dragging { color: var(--title-text); background: var(--title); }
.notice { margin-bottom: 12px; padding: 9px 11px; color: var(--ink); background: #ffffe1; border: 1px solid var(--dark-shadow); box-shadow: var(--raised); }
[data-theme="dark"] .notice { background: #504b24; }
.notice.error { color: var(--danger); background: #ffd5d5; }
[data-theme="dark"] .notice.error { background: #4e2727; }

dialog { width: min(650px, calc(100% - 24px)); padding: 3px; color: var(--ink); background: var(--face); border: 0; box-shadow: var(--raised), 8px 8px 0 rgb(0 0 0 / 35%); }
dialog::backdrop { background: rgb(0 0 0 / 45%); }
dialog form { padding: 12px; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; min-height: 27px; margin: -9px -9px 12px; padding: 3px 4px 3px 7px; color: var(--title-text); background: linear-gradient(90deg, var(--title), var(--title-end)); }
.dialog-head .icon-button { width: 22px; height: 20px; min-height: 20px; padding: 0; color: var(--ink); font: 700 14px/16px Arial, sans-serif; }
#invoice-dialog { width: min(900px, calc(100% - 24px)); }
.invoice-sheet { padding: 38px; color: #111; background: #fff; font-family: Arial, sans-serif; }
.invoice-sheet .invoice-top { display: flex; justify-content: space-between; gap: 25px; margin-bottom: 25px; padding-bottom: 25px; border-bottom: 2px solid #111; }
.invoice-sheet h2 { font: 700 30px Arial, sans-serif; }
.invoice-sheet address { font-style: normal; white-space: pre-line; }
.invoice-actions { display: flex; justify-content: flex-end; gap: 7px; padding: 9px; background: var(--face); border-top: 1px solid var(--shadow); }
.link-button { min-height: 0; padding: 0; border: 0; background: none; color: var(--link); text-decoration: underline; cursor: pointer; }

.backup-tools { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; padding: 14px; }
.backup-tools > div { padding: 10px; background: var(--face-2); box-shadow: var(--sunken); }
.backup-tools p { color: var(--muted); font-size: 11px; }
.backup-tools input { margin-bottom: 7px; }
.login-screen { position: fixed; z-index: 20; inset: 0; display: grid; place-items: center; padding: 16px; background: var(--desktop); }
.login-screen[hidden] { display: none; }
.login-card { width: min(410px, 100%); display: grid; gap: 12px; padding: 32px 18px 18px; background: var(--face); box-shadow: var(--raised), 10px 10px 0 rgb(0 0 0 / 30%); position: relative; }
.login-card::before { content: "BILLtopia – Pålogging"; position: absolute; inset: 3px 3px auto; height: 25px; padding: 4px 6px; color: var(--title-text); background: linear-gradient(90deg, var(--title), var(--title-end)); font-weight: 700; }
.login-card h1 { font-size: 16px; }
.login-card p { margin: -5px 0 2px; color: var(--muted); font-size: 11px; }
.login-brand { margin-bottom: 3px; }
.report-summary { grid-template-columns: repeat(3, 1fr); margin: 0; padding: 10px; }

footer { display: flex; justify-content: space-between; gap: 15px; max-width: 1220px; margin: 0 auto 10px; padding: 6px 8px; color: var(--ink); background: var(--face); box-shadow: var(--raised); font-size: 11px; }
footer span { padding: 3px 6px; box-shadow: var(--sunken); }

/* NT Workstation: strammere administrativ arbeidsflate */
[data-theme="nt"] .masthead,
[data-theme="nt"] main,
[data-theme="nt"] footer { max-width: 1320px; }
[data-theme="nt"] .masthead { margin-top: 6px; }
[data-theme="nt"] .brand-row { min-height: 58px; }
[data-theme="nt"] .brand-mark { width: 35px; height: 35px; background: var(--title); font-size: 20px; }
[data-theme="nt"] .brand strong { font-size: 19px; }
[data-theme="nt"] nav { padding: 2px 4px 4px; }
[data-theme="nt"] nav a { padding: 4px 10px; border-right: 1px solid var(--shadow); }
[data-theme="nt"] main { padding-top: 11px; }
[data-theme="nt"] .page-heading { background: var(--title); }
[data-theme="nt"] .summary-grid { gap: 5px; }
[data-theme="nt"] .summary-grid article { padding: 9px 11px; box-shadow: var(--sunken); }
[data-theme="nt"] .summary-grid strong { font-size: 18px; }
[data-theme="nt"] .panel { box-shadow: 1px 1px 0 var(--dark-shadow); }
[data-theme="nt"] .panel-head { background: var(--title); color: var(--title-text); }
[data-theme="nt"] .panel-head h2::before { color: var(--title-text); }

/* Windows CE: lettere, mer kompakt og berøringsvennlig */
[data-theme="ce"] { font-size: 14px; }
[data-theme="ce"] .masthead { max-width: none; margin: 0; padding: 0; box-shadow: none; }
[data-theme="ce"] .service-bar { min-height: 30px; background: var(--title); }
[data-theme="ce"] .brand-row { min-height: 62px; padding-inline: max(12px, calc((100% - 1180px) / 2)); }
[data-theme="ce"] .brand-mark { border-radius: 5px; box-shadow: 0 2px 5px rgb(20 55 80 / 25%); }
[data-theme="ce"] nav { justify-content: center; gap: 5px; padding: 6px; background: var(--face-2); border-block: 1px solid var(--shadow); }
[data-theme="ce"] nav a { padding: 6px 10px; border: 1px solid transparent; border-radius: 4px; }
[data-theme="ce"] nav a:hover,
[data-theme="ce"] nav a.active { border-color: var(--shadow); background: var(--field); box-shadow: 0 1px 3px rgb(20 55 80 / 18%); }
[data-theme="ce"] main { margin-top: 10px; border-radius: 5px; box-shadow: 0 5px 18px rgb(20 55 80 / 28%); }
[data-theme="ce"] .page-heading { border-radius: 3px; background: linear-gradient(90deg, var(--title), var(--title-end)); }
[data-theme="ce"] .panel,
[data-theme="ce"] .summary-grid article,
[data-theme="ce"] .primary,
[data-theme="ce"] .secondary,
[data-theme="ce"] .button,
[data-theme="ce"] .icon-button,
[data-theme="ce"] .quiet-button { border-radius: 4px; box-shadow: 0 1px 4px rgb(20 55 80 / 24%); }
[data-theme="ce"] .summary-grid article { border-left: 4px solid var(--title); }
[data-theme="ce"] input,
[data-theme="ce"] select,
[data-theme="ce"] textarea { border: 1px solid var(--shadow); border-radius: 3px; box-shadow: inset 0 1px 2px rgb(20 55 80 / 14%); }
[data-theme="ce"] .table-scroll,
[data-theme="ce"] .empty { box-shadow: inset 0 0 0 1px var(--shadow); }
[data-theme="ce"] th { color: var(--title-text); background: var(--title); box-shadow: none; }
[data-theme="ce"] dialog { border-radius: 5px; box-shadow: 0 14px 35px rgb(20 40 55 / 45%); }
[data-theme="ce"] .dialog-head { border-radius: 3px 3px 0 0; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation: none !important; transition: none !important; }
}

@media (max-width: 800px) {
  .masthead { margin-top: 0; }
  .brand-row { align-items: flex-start; flex-direction: column; }
  .header-tools { width: 100%; flex-wrap: wrap; justify-content: flex-start; }
  .company-picker { flex: 1; }
  .summary-grid { grid-template-columns: repeat(2, 1fr); }
  .two-columns { grid-template-columns: 1fr; }
  .invoice-line { grid-template-columns: 2fr 1fr 1fr; padding-bottom: 10px; border-bottom: 1px solid var(--shadow); }
  .header-tools #today { display: none; }
  .backup-tools { grid-template-columns: 1fr; }
  main { min-height: calc(100vh - 250px); }
}

@media (max-width: 520px) {
  main { padding: 10px 7px 28px; }
  .brand small { display: none; }
  .page-heading { align-items: stretch; flex-direction: column; }
  .summary-grid, .form-grid, .report-summary { grid-template-columns: 1fr; }
  .registry-tools { align-items: stretch; flex-direction: column; }
  .registry-search { width: 100%; max-width: none; }
  .registry-filters, .registry-bulk { width: 100%; }
  .registry-bulk { margin-left: 0; padding: 6px 0 0; border-top: 1px solid var(--shadow); border-left: 0; box-shadow: inset 0 1px var(--light); }
  .registry-tools select { flex: 1; max-width: none; }
  footer { align-items: stretch; flex-direction: column; margin-bottom: 0; }
  dialog { width: calc(100% - 8px); max-height: 98vh; overflow: auto; }
}

@media print {
  body * { visibility: hidden; }
  #invoice-dialog[open], #invoice-dialog[open] * { visibility: visible; }
  #invoice-dialog { position: absolute; inset: 0; width: 100%; padding: 0; box-shadow: none; }
  .invoice-actions { display: none; }
}
