/* Design tokens — change here, change everywhere. */
:root {
    --bg: #f3f4f6;
    --bg-soft: #ffffff;
    --surface: #ffffff;
    --surface-glass: rgba(255, 255, 255, 0.72);
    --border: #e5e7eb;
    --text: #111827;
    --muted: #6b7280;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --danger: #dc2626;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 1px 3px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.12), 0 4px 10px rgba(0, 0, 0, 0.08);
    --radius: 8px;
    --radius-tile: 18px;
    --topbar-height: 56px;
}

:root[data-theme="dark"] {
    --bg: #0b0d12;
    --bg-soft: #14171f;
    --surface: #1a1d26;
    --surface-glass: rgba(20, 23, 31, 0.62);
    --border: #2a2f3a;
    --text: #f3f4f6;
    --muted: #9ca3af;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 1px 3px rgba(0, 0, 0, 0.45);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.55), 0 4px 10px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 16px;
    line-height: 1.5;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* --- Topbar (shell) --- */

.topbar {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--topbar-height);
    padding: 0 16px;
    background: var(--surface-glass);
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    border-bottom: 1px solid var(--border);
}

.topbar-brand { display: flex; align-items: baseline; gap: 8px; }
.topbar-logo {
    font-weight: 700;
    font-size: 18px;
    color: var(--text);
}
.topbar-logo:hover { text-decoration: none; }
.topbar-module {
    font-weight: 500;
    color: var(--muted);
}

.topbar-actions { display: flex; align-items: center; gap: 8px; }

.topbar-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 8px;
    color: var(--text);
    cursor: pointer;
}
.topbar-btn:hover { background: var(--border); }

.app-grid-icon {
    display: grid;
    grid-template-columns: repeat(3, 4px);
    grid-template-rows: repeat(3, 4px);
    gap: 3px;
}
.app-grid-icon span {
    width: 4px;
    height: 4px;
    background: currentColor;
    border-radius: 1px;
}

/* --- App-switcher (topbar grid menu, available on every page) --- */

.app-switcher { position: relative; }
.app-switcher-panel {
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    width: 320px;
    max-width: 86vw;
    padding: 12px;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: var(--shadow-lg);
    z-index: 200;
}
.app-switcher-head {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
    margin: 2px 4px 10px;
}
.app-switcher-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}
.app-switcher-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 10px 6px;
    border-radius: 12px;
    color: var(--text);
    text-decoration: none;
    text-align: center;
}
.app-switcher-item:hover { background: var(--bg); text-decoration: none; }
.app-switcher-icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    line-height: 1;
    overflow: hidden;
}
.app-switcher-icon img { width: 100%; height: 100%; object-fit: cover; border-radius: inherit; }

.app-switcher-label {
    font-size: 12px;
    line-height: 1.2;
    max-width: 84px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.app-switcher-empty { padding: 16px; text-align: center; grid-column: 1 / -1; }

.topbar-profile { position: relative; }
.topbar-profile > summary {
    list-style: none;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    font-weight: 600;
}
.topbar-profile > summary::-webkit-details-marker { display: none; }
.profile-initial { line-height: 1; }
/* Profilbilde i topbar — round, fyller hele summary-sirkelen. Faller
   tilbake til initial-spanet hvis brukeren ikke har lastet opp bilde. */
.profile-avatar {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
    display: block;
}
.profile-menu-link {
    text-align: center;
    text-decoration: none;
}
.profile-menu {
    position: absolute;
    right: 0;
    top: calc(100% + 4px);
    min-width: 220px;
    padding: 12px;
    background: var(--surface);
    /* Explicit color: shells (.dashboard-page) set body color to white over
       photo backgrounds; pop-up surfaces with their own --surface MUST set
       their own text color, or the white bleeds through. See design.md. */
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    gap: 8px;
    text-shadow: none;
}
.profile-name { font-weight: 600; color: var(--text); }
.profile-role { color: var(--muted); font-size: 13px; }

/* --- Theme toggle (in profile dropdown) --- */

.theme-toggle {
    display: inline-flex;
    align-self: stretch;
    margin-top: 4px;
    padding: 3px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 999px;
    gap: 2px;
}
.theme-btn {
    flex: 1;
    padding: 5px 0;
    background: transparent;
    border: none;
    border-radius: 999px;
    cursor: pointer;
    color: var(--muted);
    font-size: 14px;
    line-height: 1;
    text-align: center;
}
.theme-btn:hover { color: var(--text); }
.theme-btn.is-active {
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow);
}

/* --- Content --- */

.content {
    padding: 16px;
}

/* --- Buttons --- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 14px;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
}
.btn:hover { background: var(--bg-soft); text-decoration: none; }
.btn.primary {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}
.btn.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.small { padding: 4px 10px; font-size: 13px; }

/* --- Forms --- */

/* :where(...) gjør at hele selektoren har 0 specificity, slik at en hvilken
   som helst klasse-overstyring vinner (uten å måtte ty til !important). Uten
   :where() har denne :not()-kjeden specificity (0,7,1) — høyere enn vanlige
   klasser — og overstyringer som .pj-cell ble silent ignorert. */
:where(
    input:not([type=checkbox]):not([type=radio]):not([type=submit]):not([type=button]):not([type=file]):not([type=image]):not([type=reset]),
    select,
    textarea
) {
    width: 100%;
    padding: 8px 10px;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font: inherit;
}
:where(input, select, textarea):focus {
    outline: 2px solid var(--primary);
    outline-offset: -1px;
}

label { display: flex; flex-direction: column; gap: 4px; }
label > span { font-size: 13px; color: var(--muted); }

/* File inputs: native "Choose file" button styled to match .btn. */
input[type="file"] { font: inherit; color: var(--muted); }
input[type="file"]::file-selector-button {
    margin-right: 10px;
    padding: 8px 14px;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font: inherit;
    font-weight: 500;
    cursor: pointer;
}
input[type="file"]::file-selector-button:hover { background: var(--bg-soft); }

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 16px;
}

/* --- Cards --- */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
}

.narrow-page {
    max-width: 720px;
    margin: 0 auto;
    padding: 16px;
}

/* --- Text helpers --- */

.muted { color: var(--muted); }
.small { font-size: 13px; }
.sub   { font-size: 13px; color: var(--muted); }

/* --- App-icon colours (shared: dashboard tiles, app-switcher, library, search) ---
   Emoji/letter icons get a full-bleed coloured squircle instead of a glyph on a
   neutral square. Two-class selectors (.is-color.ic-N) so they override each
   container's own background/border regardless of stylesheet order. Colour is
   chosen deterministically (icon_color filter / app-switcher.js) so the same app
   looks identical everywhere. */
.is-color { color: #fff; }
.is-letter { font-weight: 700; }
.is-color.ic-0 { background: linear-gradient(135deg, #3b82f6, #2563eb); border-color: transparent; }
.is-color.ic-1 { background: linear-gradient(135deg, #8b5cf6, #6d28d9); border-color: transparent; }
.is-color.ic-2 { background: linear-gradient(135deg, #ec4899, #db2777); border-color: transparent; }
.is-color.ic-3 { background: linear-gradient(135deg, #14b8a6, #0d9488); border-color: transparent; }
.is-color.ic-4 { background: linear-gradient(135deg, #22c55e, #16a34a); border-color: transparent; }
.is-color.ic-5 { background: linear-gradient(135deg, #f59e0b, #d97706); border-color: transparent; }
.is-color.ic-6 { background: linear-gradient(135deg, #f43f5e, #e11d48); border-color: transparent; }
.is-color.ic-7 { background: linear-gradient(135deg, #6366f1, #4f46e5); border-color: transparent; }

/* --- Login page --- */

.login-page {
    display: grid;
    place-items: center;
    min-height: 100vh;
    margin: 0;
    background:
        radial-gradient(circle at 20% 30%, rgba(37, 99, 235, 0.18), transparent 60%),
        radial-gradient(circle at 80% 70%, rgba(220, 38, 38, 0.12), transparent 55%),
        var(--bg);
}
.login-card {
    width: 100%;
    max-width: 380px;
    padding: 32px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
}
.login-title {
    margin: 0 0 4px;
    font-size: 28px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 12px;
}
.login-logo { width: 1.1em; height: 1.1em; flex-shrink: 0; }
.login-sub   { margin: 0 0 20px; color: var(--muted); }
.login-error {
    margin-bottom: 16px;
    padding: 10px 12px;
    background: rgba(220, 38, 38, 0.1);
    color: var(--danger);
    border: 1px solid rgba(220, 38, 38, 0.3);
    border-radius: var(--radius);
}
.login-form { display: flex; flex-direction: column; gap: 14px; }
.login-form .btn.primary { margin-top: 6px; }

.login-recovery {
    margin-top: 18px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
    font-size: 14px;
}
.login-recovery summary {
    cursor: pointer;
    color: var(--muted);
    list-style: none;
}
.login-recovery summary::-webkit-details-marker { display: none; }
.login-recovery summary:hover { color: var(--text); }
.login-recovery[open] summary {
    color: var(--text);
    margin-bottom: 12px;
}
.login-recovery .login-form { gap: 10px; }
