@font-face { font-family: "Fredoka"; src: url("fonts/Fredoka-Variable.ttf") format("truetype"); font-weight: 300 700; font-display: swap; }
@font-face { font-family: "Scheherazade New"; src: url("fonts/ScheherazadeNew-Regular.ttf") format("truetype"); font-display: swap; }

/* iBønn-pastellene (SPEC: Design) */
:root {
  --mint: #E1F4EA; --mint-ink: #1E7A55;
  --gold: #F6EBD3; --gold-ink: #B07A1A;
  --blue: #E3EDF8; --blue-ink: #2C5C9A;
  --rose: #F7E4E8; --rose-ink: #B2455F;
  --navy: #0E3A44;
  --paper: #FBFAF6; --card: #FFFFFF; --ink: #1F3238; --muted: #6B7B80; --line: #E6E8E3; --soft: #F3F4EF;
  --danger: #B2455F; --ok: #1E7A55;
  --radius: 14px;
  --shadow: 0 8px 30px rgba(14, 58, 68, .06);
  --sans: "Fredoka", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --body: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --arabic: "Scheherazade New", "Geeza Pro", serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--paper); color: var(--ink); font: 14px/1.45 var(--body); -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
h1, h2, h3, h4 { font-family: var(--sans); font-weight: 600; margin: 0; color: var(--navy); }
h1 { font-size: 26px; } h2 { font-size: 20px; } h3 { font-size: 16px; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--blue-ink); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
:focus-visible { outline: 3px solid #9CCFB5; outline-offset: 2px; }

/* ---------- Knapper ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 8px 16px; cursor: pointer; font-family: var(--sans); font-weight: 500; white-space: nowrap; }
.btn:hover { background: var(--soft); }
.btn.primary { background: var(--mint-ink); border-color: var(--mint-ink); color: #fff; }
.btn.primary:hover { background: #17664A; }
.btn.danger { color: var(--danger); border-color: #EBC3CC; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { border: 0; background: transparent; cursor: pointer; padding: 4px 6px; border-radius: 8px; color: var(--muted); }
.icon-btn:hover { background: var(--soft); color: var(--ink); }

/* ---------- Innlogging ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: linear-gradient(160deg, var(--mint), var(--blue)); }
.login-card { width: min(380px, 100%); background: var(--card); border-radius: 22px; padding: 32px; box-shadow: var(--shadow); display: grid; gap: 14px; }
.login-card .brand-mark { font-size: 40px; }
.login-card label { display: grid; gap: 6px; font-weight: 500; }
.login-card input { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.form-error { color: var(--danger); margin: 0; min-height: 1em; }

/* ---------- Ramme ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar { width: 220px; flex: none; background: var(--navy); color: #E6F0EE; display: flex; flex-direction: column; gap: 2px; padding: 22px 12px; position: sticky; top: 0; height: 100vh; }
.brand { font-family: var(--sans); font-size: 20px; font-weight: 600; padding: 0 10px 18px; }
.brand small { font-size: 12px; opacity: .6; font-weight: 400; }
.sidebar a { color: inherit; text-decoration: none; padding: 9px 12px; border-radius: 10px; display: flex; gap: 10px; align-items: center; font-family: var(--sans); }
.sidebar a span { width: 20px; text-align: center; }
.sidebar a:hover { background: rgba(255, 255, 255, .07); }
.sidebar a.active { background: rgba(225, 244, 234, .16); color: #fff; }
.sidebar-foot { margin-top: auto; display: grid; gap: 8px; padding: 10px; font-size: 13px; opacity: .85; }
.sidebar-foot .btn { color: #E6F0EE; justify-self: start; padding-left: 0; }
.main { flex: 1; min-width: 0; padding: 28px 32px 60px; outline: none; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head h1 { margin-right: auto; }

/* ---------- Kort og oversikt ---------- */
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
a.card { text-decoration: none; color: inherit; transition: transform .15s ease; }
a.card:hover { transform: translateY(-2px); }
.card h3 { margin-bottom: 6px; }
.card .big { font-family: var(--sans); font-size: 30px; font-weight: 600; color: var(--navy); }
.card.mint { background: var(--mint); border-color: transparent; }
.card.gold { background: var(--gold); border-color: transparent; }
.card.blue { background: var(--blue); border-color: transparent; }
.card.rose { background: var(--rose); border-color: transparent; }
.section { margin-top: 28px; }
.section > h2 { margin-bottom: 12px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin: 8px 0 0; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; }
.notice { border-radius: var(--radius); padding: 12px 16px; background: var(--gold); color: #6B4A0E; margin-bottom: 16px; }
.notice.error { background: var(--rose); color: #7A2438; }
.notice.ok { background: var(--mint); color: #155C40; }
.notice ul { margin: 6px 0 0; padding-left: 20px; max-height: 260px; overflow: auto; }

.badge { display: inline-block; border-radius: 999px; padding: 1px 8px; font-size: 11px; font-weight: 600; background: var(--soft); color: var(--muted); white-space: nowrap; }
.badge.mint { background: var(--mint); color: var(--mint-ink); }
.badge.gold { background: var(--gold); color: var(--gold-ink); }
.badge.blue { background: var(--blue); color: var(--blue-ink); }
.badge.rose { background: var(--rose); color: var(--rose-ink); }

/* ---------- Redigering ---------- */
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.dirty-pill { background: var(--gold); color: var(--gold-ink); border-radius: 999px; padding: 4px 12px; font-weight: 600; font-family: var(--sans); }
.tabs { display: flex; gap: 6px; margin-bottom: 14px; }
.tabs button { border: 1px solid var(--line); background: var(--card); padding: 6px 14px; border-radius: 999px; cursor: pointer; font-family: var(--sans); }
.tabs button.active { background: var(--navy); border-color: var(--navy); color: #fff; }
.editor { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 18px; align-items: start; }
.list { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; position: sticky; top: 16px; max-height: calc(100vh - 32px); display: flex; flex-direction: column; }
.list-head { padding: 10px; border-bottom: 1px solid var(--line); display: flex; gap: 6px; }
.list-head input { flex: 1; min-width: 0; border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; }
.list-items { overflow: auto; }
.list-item { display: flex; gap: 10px; align-items: center; width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--soft); background: transparent; padding: 10px 12px; cursor: pointer; }
.list-item:hover { background: var(--soft); }
.list-item.active { background: var(--mint); }
.list-item .li-icon { width: 30px; text-align: center; font-size: 20px; flex: none; }
.list-item .li-icon.ar { font-family: var(--arabic); font-size: 24px; }
.list-item .li-main { flex: 1; min-width: 0; }
.list-item .li-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item .li-sub { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 2px; }
.list-item .changed { width: 8px; height: 8px; border-radius: 50%; background: var(--gold-ink); flex: none; }

.form { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; display: grid; gap: 14px; }
.form-head { display: flex; gap: 10px; align-items: center; }
.form-head h2 { margin-right: auto; }
.field { display: grid; gap: 5px; }
.field > label, .field > .label { font-weight: 600; font-size: 13px; color: var(--navy); }
.field .hint { font-size: 12px; color: var(--muted); }
.field input[type=text], .field input[type=number], .field input[type=url], .field select, .field textarea {
  border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; background: #fff; width: 100%;
}
.field textarea { min-height: 70px; resize: vertical; }
.field.changed > label, .field.changed > .label { color: var(--gold-ink); }
.field.changed > label::after, .field.changed > .label::after { content: " •"; }
.ar-input { font-family: var(--arabic) !important; font-size: 26px !important; line-height: 1.6; direction: rtl; text-align: right; }
.row { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); align-items: start; }
.field { align-content: start; }
.group { border: 1px solid var(--line); border-radius: 12px; padding: 14px; display: grid; gap: 12px; background: var(--soft); }
.group > .label { font-family: var(--sans); font-weight: 600; color: var(--navy); }
.sub-items { display: grid; gap: 10px; }
.sub-item { border: 1px solid var(--line); border-radius: 12px; background: #fff; }
/* Lange titler (nowrap) skal kuttes, ikke gjøre skjemaet bredere. */
.form, .group, .field, .sub-items, .sub-body, .string-list { grid-template-columns: minmax(0, 1fr); min-width: 0; }
.sub-item { min-width: 0; }
.sub-item > summary { list-style: none; cursor: pointer; padding: 10px 12px; display: flex; gap: 8px; align-items: center; }
.sub-item > summary::-webkit-details-marker { display: none; }
.sub-item > summary .si-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sub-item > summary .si-title.ar { font-family: var(--arabic); font-size: 22px; direction: rtl; text-align: right; }
.sub-item > .sub-body { padding: 0 12px 12px; display: grid; gap: 12px; }
.sub-item[open] > summary { border-bottom: 1px solid var(--soft); margin-bottom: 10px; }
.string-list { display: grid; gap: 6px; }
.string-row { display: flex; gap: 6px; align-items: start; }
.string-row > input, .string-row > textarea { flex: 1; }
.audio-field { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.audio-field input { flex: 1; min-width: 200px; }
.audio-field .target { font-family: ui-monospace, Menlo, monospace; font-size: 11px; color: var(--muted); width: 100%; }
.raw { width: 100%; min-height: 70vh; font: 12px/1.5 ui-monospace, Menlo, monospace; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.empty { padding: 40px; text-align: center; color: var(--muted); }

/* ---------- Tabeller ---------- */
.table-wrap { overflow: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--soft); vertical-align: top; }
th { font-family: var(--sans); font-weight: 600; color: var(--navy); background: var(--soft); position: sticky; top: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.mono { font-family: ui-monospace, Menlo, monospace; font-size: 12px; }
.meter { height: 8px; border-radius: 999px; background: var(--soft); overflow: hidden; min-width: 120px; }
.meter > i { display: block; height: 100%; background: var(--mint-ink); border-radius: 999px; }

/* ---------- Diagram ---------- */
.chart { width: 100%; height: 220px; display: block; }
.chart .bar-asked { fill: var(--mint-ink); }
.chart .bar-blocked { fill: var(--gold-ink); }
.chart .bar-limited { fill: var(--rose-ink); }
.chart .axis { stroke: var(--line); }
.chart text { fill: var(--muted); font-size: 10px; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px; vertical-align: -1px; }
.legend .l-asked { background: var(--mint-ink); } .legend .l-blocked { background: var(--gold-ink); } .legend .l-limited { background: var(--rose-ink); }

/* ---------- Dialog og toast ---------- */
.dialog { border: 0; border-radius: 18px; padding: 0; width: min(560px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgba(14, 58, 68, .25); }
.dialog::backdrop { background: rgba(14, 58, 68, .35); }
.dialog-body { padding: 22px; display: grid; gap: 14px; max-height: 80vh; overflow: auto; }
.dialog-actions { display: flex; gap: 8px; justify-content: flex-end; }
.dialog textarea { border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; width: 100%; min-height: 70px; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--navy); color: #fff; padding: 10px 18px; border-radius: 999px; box-shadow: var(--shadow); z-index: 100; max-width: calc(100vw - 32px); }
.toast.error { background: var(--danger); }
.drop { border: 2px dashed #B9D9C8; border-radius: var(--radius); padding: 28px; text-align: center; background: var(--mint); display: grid; gap: 10px; justify-items: center; }
.drop.over { background: #CDEBDB; }

@media (max-width: 980px) {
  .editor { grid-template-columns: 1fr; }
  .list { position: static; max-height: 320px; }
}
@media (max-width: 720px) {
  .shell { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; flex-wrap: wrap; padding: 10px; }
  .brand { width: 100%; padding-bottom: 6px; }
  .sidebar a { padding: 6px 10px; }
  .sidebar-foot { margin: 0; width: 100%; grid-auto-flow: column; justify-content: space-between; }
  .main { padding: 18px 16px 40px; }
}

/* Innlogging med Firebase */
.login-google { justify-content: center; padding: 10px 16px; }
.login-divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; }
.login-divider::before, .login-divider::after { content: ""; flex: 1; border-top: 1px solid var(--line); }
.login-note:empty { display: none; }
#forgotPassword { justify-self: center; }
.tr-chips { display: flex; gap: 4px; flex-wrap: wrap; margin: 2px 0; }

/* AiBønn Kids: prøv prompten og samtalelogg */
.ai-test { display: grid; gap: 12px; margin-top: 8px; }
.ai-test-row { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; }
.ai-result { display: grid; gap: 8px; margin-top: 14px; }
.ai-result:empty { display: none; }
.ai-bubble { background: var(--mint); border-radius: 16px; padding: 12px 14px; font-size: 16px; }
.ai-raw { white-space: pre-wrap; background: var(--soft); border-radius: 10px; padding: 10px; font-size: 12px; max-height: 320px; overflow: auto; }
.ai-log { display: grid; gap: 10px; margin: 10px 0; }
.ai-entry { border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; display: grid; gap: 6px; }
.ai-entry-head { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.ai-q { margin: 0; font-weight: 600; color: var(--navy); }
.ai-a { margin: 0; color: var(--ink); }

/* Opplesning på andre språk */
details.narration { border: 1px solid var(--line); border-radius: 12px; padding: 6px 10px; margin-top: 6px; }
details.narration summary { cursor: pointer; font-weight: 600; display: flex; gap: 8px; align-items: center; }
.narration-row { display: grid; grid-template-columns: minmax(110px, 160px) 1fr auto auto; gap: 8px; align-items: center; margin: 6px 0; }
.narration-row input[type=url] { border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; min-width: 0; }
@media (max-width: 700px) { .narration-row { grid-template-columns: 1fr auto auto; } .narration-label { grid-column: 1 / -1; } }

/* Film */
.video-list { display: grid; gap: 10px; }
.video-row { border: 1px solid var(--line); border-radius: 12px; padding: 10px; display: grid; gap: 8px; min-width: 0; }
.video-head { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: baseline; }
.video-head .target { font-family: ui-monospace, Menlo, monospace; font-size: 11px; color: var(--muted); }
.video-row input[type=url] { border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; }
.video-progress { display: flex; gap: 8px; align-items: center; }
.video-progress progress { flex: 1; max-width: 320px; }
.video-progress:has(progress[hidden]) { display: none; }
.video-preview { width: 100%; max-width: 360px; aspect-ratio: 16 / 9; background: #000; border-radius: 10px; }
.video-sub { font-size: 13px; margin-top: 4px; }
.video-list select { border: 1px solid var(--line); border-radius: 8px; padding: 4px 8px; }
