:root {
  --bg: #111515;
  --panel: #23242d;
  --panel-2: #181b21;
  --text: #edf1f5;
  --muted: #aab3c0;
  --line: #353946;
  --accent: #ff5263;
  --green: #00a13a;
  --yellow: #c69c24;
  --red: #d53b3b;
  --blue: #3b7ddd;
  --xml-tag: #8ab4f8;
  --xml-attr: #ffd166;
  --xml-attr-value: #d7b6ff;
  --xml-comment: #8b96a8;
  --xml-punc: #c7d0dd;
  --error-line-bg: rgba(213, 59, 59, 0.22);
  --error-line-border: #d53b3b;
  --search-hit-bg: rgba(198, 156, 36, 0.22);
  --shadow: rgba(0,0,0,.35);
}
html[data-theme="light"] {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --panel-2: #f0f2f5;
  --text: #1f2530;
  --muted: #5d6675;
  --line: #d9dde5;
  --accent: #c8374a;
  --green: #007a32;
  --yellow: #946f00;
  --red: #b00020;
  --blue: #245bb8;
  --xml-tag: #005f9e;
  --xml-attr: #8a5a00;
  --xml-attr-value: #6f3fa0;
  --xml-comment: #667085;
  --xml-punc: #344054;
  --error-line-bg: rgba(176, 0, 32, 0.12);
  --error-line-border: #b00020;
  --search-hit-bg: rgba(148, 111, 0, 0.16);
  --shadow: rgba(0,0,0,.08);
}
* { box-sizing: border-box; }
body { margin: 0; padding: 28px; font-family: Arial, Helvetica, sans-serif; background: var(--bg); color: var(--text); }
h1 { margin: 0; font-size: 30px; }
h2 { margin: 0 0 16px; font-size: 20px; }
h3 { margin: 0 0 8px; }
.muted { color: var(--muted); font-size: 13px; }
.topbar { display: flex; justify-content: space-between; gap: 24px; align-items: flex-start; margin-bottom: 28px; }
.actions { display: flex; align-items: flex-start; gap: 14px; }
button, .button-link { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 7px; padding: 10px 16px; cursor: pointer; text-decoration: none; font-weight: 700; }
button:hover, .button-link:hover { border-color: var(--accent); }
.upload-form { margin: 0; }
.upload-box { position: relative; display: grid; grid-template-columns: 1fr auto; grid-template-rows: auto auto; gap: 3px 18px; min-width: 430px; padding: 14px 16px; border: 1px solid var(--line); background: var(--panel); border-radius: 9px; box-shadow: 0 1px 3px var(--shadow); cursor: pointer; }
.upload-title { font-weight: 700; }
.upload-box input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.browse { grid-row: 1 / span 2; grid-column: 2; align-self: center; background: var(--panel-2); border: 1px solid var(--line); padding: 9px 12px; border-radius: 7px; font-weight: 700; }
.empty-state { border: 1px dashed var(--line); border-radius: 12px; padding: 45px; text-align: center; background: var(--panel-2); }
.file-strip, .meta-grid, .cards, .tabs, .panel, .table-wrap, .issue, .ok-box { border: 1px solid var(--line); background: var(--panel); border-radius: 8px; box-shadow: 0 1px 3px var(--shadow); }
.file-strip { padding: 13px 16px; margin-bottom: 18px; display: flex; gap: 12px; align-items: center; }
.spacer { flex: 1; }
.meta-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 0; overflow: hidden; margin-bottom: 18px; }
.meta-grid div { padding: 14px; border-right: 1px solid var(--line); }
.meta-grid div:last-child { border-right: none; }
.meta-grid span, .card span { display: block; color: var(--muted); font-size: 12px; font-weight: 700; text-transform: uppercase; margin-bottom: 8px; }
.meta-grid strong { font-size: 14px; }
.cards { display: grid; grid-template-columns: repeat(6, 1fr); gap: 0; overflow: hidden; margin-bottom: 20px; }
.card { padding: 18px; border-right: 1px solid var(--line); text-align: center; }
.card:last-child { border-right: none; }
.card strong { font-size: 27px; }
.status-ok strong { color: var(--green); }
.status-warning strong { color: var(--yellow); }
.status-error strong { color: var(--red); }
.tabs { display: flex; gap: 4px; padding: 0 0 0 0; background: transparent; border-width: 0 0 1px 0; border-radius: 0; box-shadow: none; margin-bottom: 16px; }
.tab { border: none; border-bottom: 3px solid transparent; border-radius: 0; background: transparent; padding: 12px 14px; }
.tab.active { border-bottom-color: var(--accent); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.panel { padding: 18px; }
.simple-table { width: 100%; border-collapse: collapse; }
.simple-table th, .simple-table td { padding: 10px; border-bottom: 1px solid var(--line); text-align: left; }
.simple-table th { color: var(--muted); width: 35%; }
.filters { display: flex; gap: 12px; align-items: center; margin: 0 0 12px; }
.filters label { display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: 13px; }
select, input[type="search"] { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 7px; padding: 10px 12px; min-width: 190px; }
input[type="search"] { min-width: 300px; }
.table-wrap { overflow: auto; max-height: 68vh; }
.data-table { width: 100%; border-collapse: collapse; min-width: 920px; }
.data-table th, .data-table td { padding: 10px 12px; border-bottom: 1px solid var(--line); border-right: 1px solid var(--line); text-align: left; font-size: 13px; white-space: nowrap; }
.data-table th { position: sticky; top: 0; z-index: 1; background: var(--panel); color: var(--muted); cursor: pointer; user-select: none; }
.data-table tr:hover td { background: var(--panel-2); }
.issue { padding: 16px; margin-bottom: 12px; border-left: 5px solid var(--line); }
.issue-error { border-left-color: var(--red); }
.issue-warning { border-left-color: var(--yellow); }
.issue-information { border-left-color: var(--blue); }
.ok-box { padding: 18px; color: var(--green); font-weight: 700; }
pre { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 18px; overflow: auto; max-height: 70vh; white-space: pre-wrap; }
@media (max-width: 1000px) {
  body { padding: 18px; }
  .topbar, .actions { flex-direction: column; width: 100%; }
  .upload-box { min-width: 100%; width: 100%; }
  .meta-grid, .cards, .two-col { grid-template-columns: 1fr; }
  .card, .meta-grid div { border-right: none; border-bottom: 1px solid var(--line); }
}


/* Raw XML viewer */
#rawXml {
  max-height: 68vh;
  overflow: auto;
  padding: 0;
  margin: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-family: Consolas, "Courier New", monospace;
  font-size: 13px;
  line-height: 1.55;
  white-space: pre;
}

.xml-line {
  display: flex;
  min-width: max-content;
  border-left: 4px solid transparent;
}

.xml-line:hover {
  background: var(--panel-2);
}

.line-number {
  flex: 0 0 72px;
  padding: 0 12px 0 8px;
  text-align: right;
  color: var(--muted);
  user-select: none;
  border-right: 1px solid var(--line);
  background: var(--panel-2);
}

.line-content {
  padding: 0 12px;
  white-space: pre;
}

.xml-tag { color: var(--xml-tag); font-weight: 700; }
.xml-attr { color: var(--xml-attr); }
.xml-attr-value { color: var(--xml-attr-value); }
.xml-comment { color: var(--xml-comment); font-style: italic; }
.xml-punc { color: var(--xml-punc); }

.xml-line.error-line {
  background: var(--error-line-bg);
  border-left-color: var(--error-line-border);
}

.xml-line.search-hit {
  background: var(--search-hit-bg);
}

.xml-line.active-search-hit {
  outline: 1px solid var(--yellow);
  outline-offset: -1px;
}

.go-to-error {
  margin-top: 6px;
}

/* Validation v1.2 */
.validation-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.validation-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 22px;
}

.summary-item {
  border: 1px solid var(--line);
  border-left-width: 5px;
  border-radius: 8px;
  background: var(--panel);
  padding: 12px 14px;
}

.summary-item p {
  margin: 6px 0 0;
  color: var(--muted);
}

.summary-status {
  display: inline-block;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: 6px;
}

.summary-pass { border-left-color: var(--blue); }
.summary-fail { border-left-color: var(--red); }
.summary-warning { border-left-color: var(--yellow); }
.summary-info { border-left-color: var(--blue); }

.issue-critical { border-left-color: var(--red); }
.issue-info { border-left-color: var(--blue); }

.card.status-critical strong,
.card.status-error strong { color: var(--red); }

.card.status-warning strong { color: var(--yellow); }

.card.status-ok strong,
.card.status-info strong { color: var(--blue); }

@media (max-width: 1000px) {
  .validation-summary { grid-template-columns: 1fr; }
}

.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 9px 14px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--panel);
  color: var(--text);
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}

.button-link:hover {
  border-color: var(--accent);
  text-decoration: none;
}

/* Help and rule catalog */
.help-actions { align-items: center; }
.language-picker { display: flex; align-items: center; gap: 7px; padding: 6px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
.language-picker > span { padding: 0 6px; color: var(--muted); font-size: 13px; font-weight: 700; }
.language-option { padding: 7px 9px; border-radius: 6px; color: var(--text); text-decoration: none; font-size: 13px; font-weight: 700; }
.language-option:hover, .language-option.active { background: var(--panel-2); outline: 1px solid var(--accent); }
.help-page { display: grid; gap: 18px; max-width: 1400px; margin: 0 auto; }
.help-intro p, .catalog-heading p { max-width: 950px; line-height: 1.6; }
.help-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.help-list { margin: 0; padding-left: 22px; line-height: 1.65; }
.help-list li + li { margin-top: 7px; }
.disclaimer-box { margin-top: 18px; padding: 14px 16px; border-left: 5px solid var(--yellow); background: var(--panel-2); border-radius: 6px; font-weight: 700; line-height: 1.5; }
.meaning { margin-top: 9px; padding: 11px 13px; border-left: 5px solid var(--line); background: var(--panel-2); border-radius: 6px; }
.meaning-error { border-left-color: var(--red); }
.meaning-warning { border-left-color: var(--yellow); }
.meaning-info { border-left-color: var(--blue); }
.meaning-unknown { border-left-color: var(--muted); }
.catalog-heading { margin-top: 8px; }
.rule-category { border: 1px solid var(--line); background: var(--panel); border-radius: 9px; overflow: hidden; box-shadow: 0 1px 3px var(--shadow); }
.rule-category > summary { display: flex; justify-content: space-between; align-items: center; padding: 16px 18px; cursor: pointer; font-size: 18px; font-weight: 800; }
.rule-category[open] > summary { border-bottom: 1px solid var(--line); }
.rule-list { padding: 14px; display: grid; gap: 12px; }
.rule-card { padding: 16px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); }
.rule-card-header { display: flex; justify-content: space-between; gap: 18px; align-items: flex-start; }
.rule-card h3 { margin: 7px 0 0; }
.rule-card code { color: var(--accent); font-weight: 800; }
.rule-badges { display: flex; gap: 7px; flex-wrap: wrap; justify-content: flex-end; }
.badge { display: inline-block; padding: 5px 8px; border: 1px solid var(--line); border-radius: 999px; font-size: 12px; font-weight: 800; }
.badge.status-verified, .badge.status-verifierad, .badge.status-verifisert, .badge.status-vahvistettu { border-color: var(--green); color: var(--green); }
.badge.status-draft, .badge.status-utkast, .badge.status-luonnos { border-color: var(--yellow); color: var(--yellow); }
.rule-details { display: grid; grid-template-columns: 170px 1fr; gap: 8px 16px; margin: 18px 0 0; }
.rule-details dt { color: var(--muted); font-weight: 800; }
.rule-details dd { margin: 0; line-height: 1.5; }
@media (max-width: 1000px) {
  .help-grid { grid-template-columns: 1fr; }
  .help-actions, .language-picker { width: 100%; flex-wrap: wrap; }
  .rule-card-header { flex-direction: column; }
  .rule-details { grid-template-columns: 1fr; }
  .rule-details dd { margin-bottom: 8px; }
}

/* Persistent analysis help dialog */
.help-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: none;
  padding: 24px;
  background: rgba(0, 0, 0, .66);
}
.help-overlay.open { display: flex; }
.help-dialog {
  width: min(1500px, 100%);
  height: min(92vh, 1100px);
  margin: auto;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
  box-shadow: 0 24px 80px rgba(0, 0, 0, .45);
}
.help-dialog-bar {
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px 8px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.help-dialog-bar button {
  width: 38px;
  height: 38px;
  padding: 0;
  font-size: 28px;
  line-height: 1;
}
.help-dialog iframe {
  width: 100%;
  height: 100%;
  border: 0;
  background: var(--bg);
}
body.help-open { overflow: hidden; }
body.embedded-help { padding-top: 0; }
.embedded-help-toolbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  justify-content: flex-end;
  padding: 10px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}
body.embedded-help .help-page { padding-top: 18px; }
@media (max-width: 700px) {
  .help-overlay { padding: 0; }
  .help-dialog { width: 100%; height: 100%; border-radius: 0; }
}

/* Test Verification */
.verification-header, .verification-case-title, .verification-save-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}
.verification-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.verification-overview {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1px;
  margin: 18px 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: var(--line);
}
.verification-overview > div { padding: 16px; background: var(--panel); min-width: 0; }
.verification-overview span { display: block; color: var(--muted); font-size: 12px; margin-bottom: 5px; }
.verification-overview strong, .verification-overview code { display: block; overflow-wrap: anywhere; }
.metadata-form {
  display: grid;
  grid-template-columns: repeat(5, minmax(150px, 1fr));
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
}
.metadata-form label, .manual-evidence label { display: grid; gap: 6px; font-size: 12px; font-weight: 700; }
.metadata-form input, .manual-evidence input, .manual-evidence select, .manual-evidence textarea {
  width: 100%;
  box-sizing: border-box;
}
.verification-legend { display: flex; gap: 18px; flex-wrap: wrap; margin: 16px 0; color: var(--muted); font-size: 13px; }
.verification-list { display: grid; gap: 14px; }
.verification-case { border: 1px solid var(--line); border-left-width: 5px; border-radius: 10px; background: var(--panel); overflow: hidden; }
.verification-case-title { padding: 14px 16px; border-bottom: 1px solid var(--line); background: var(--panel-2); }
.verification-case-title > div { display: flex; align-items: baseline; gap: 10px; }
.verification-case-title h3 { margin: 0; font-size: 16px; }
.test-id { font-family: monospace; color: var(--accent); font-weight: 800; }
.result-badge { padding: 6px 10px; border-radius: 999px; border: 1px solid currentColor; font-size: 12px; font-weight: 800; white-space: nowrap; }
.result-passed { border-left-color: var(--green); }
.result-failed { border-left-color: var(--red); }
.result-conflict, .result-incomplete { border-left-color: var(--yellow); }
.result-blocked { border-left-color: #8b5cf6; }
.verification-grid { display: grid; grid-template-columns: 1fr 1fr; }
.xml-evidence, .manual-evidence { padding: 16px; min-width: 0; }
.xml-evidence { border-right: 1px solid var(--line); }
.xml-evidence h4, .manual-evidence h4 { margin-top: 0; }
.manual-evidence { display: grid; gap: 10px; }
.evidence-table { margin-top: 10px; font-size: 12px; }
.verification-save-bar { position: sticky; bottom: 0; margin-top: 18px; padding: 14px 16px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); box-shadow: 0 -8px 22px rgba(0,0,0,.12); }
.verification-save-bar p { margin: 0; }
.status-passed { border-color: var(--green); }
.status-failed { border-color: var(--red); }
.status-incomplete { border-color: var(--yellow); }
@media (max-width: 1100px) {
  .verification-overview { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metadata-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
  .verification-header, .verification-case-title, .verification-save-bar { align-items: flex-start; flex-direction: column; }
  .verification-grid { grid-template-columns: 1fr; }
  .xml-evidence { border-right: 0; border-bottom: 1px solid var(--line); }
  .metadata-form, .verification-overview { grid-template-columns: 1fr; }
}
.email-draft-panel { margin-top: 22px; padding: 18px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); }
.email-draft-panel h3 { margin-top: 0; }
.email-draft-form { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.email-draft-form label { display: grid; gap: 6px; font-size: 12px; font-weight: 700; }
.email-draft-form input, .email-draft-form textarea { width: 100%; box-sizing: border-box; }
.email-wide { grid-column: 1 / -1; }
@media (max-width: 760px) { .email-draft-form { grid-template-columns: 1fr; } .email-wide { grid-column: auto; } }

/* Email sign-in */
.auth-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card { width: min(460px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 8px 28px var(--shadow); padding: 30px; }
.auth-intro { margin: 10px 0 24px; }
.auth-form { display: grid; gap: 16px; }
.auth-form label { display: grid; gap: 7px; font-weight: 700; }
.auth-form input { width: 100%; background: var(--panel-2); color: var(--text); border: 1px solid var(--line); border-radius: 7px; padding: 12px; font-size: 16px; }
.auth-form input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.auth-form button { margin-top: 4px; }
.auth-message { border-radius: 7px; padding: 11px 12px; margin-bottom: 16px; }
.auth-error { border: 1px solid var(--red); background: rgba(213,59,59,.14); }
.auth-success { border: 1px solid var(--green); background: rgba(0,161,58,.12); }
.auth-secondary-form { margin-top: 14px; }
.auth-secondary-form button { width: 100%; }
.auth-link { display: block; margin-top: 16px; color: var(--text); text-align: center; }
.auth-note { margin: 18px 0 0; text-align: center; }
.user-menu { display: flex; align-items: center; gap: 10px; }
.user-email { color: var(--muted); font-size: 13px; }
