:root {
    --bg: #f6f7fb;
    --surface: #ffffff;
    --text: #12131a;
    --muted: #666b7a;
    --border: #e1e4ee;
    --accent: #6e56cf;
    --accent-hover: #5b44b8;
    --accent-soft: #f1eefc;
    --danger-bg: #fef2f2;
    --danger-fg: #991b1b;
    --success-bg: #ecfdf5;
    --success-fg: #065f46;
    --warn-bg: #fef3c7;
    --warn-fg: #92400e;
    --radius: 12px;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0d0e14;
        --surface: #161823;
        --text: #eceef6;
        --muted: #9a9fb2;
        --border: #262938;
        --accent: #8b74f0;
        --accent-hover: #a08cf5;
        --accent-soft: #231f3d;
        --danger-bg: #450a0a;
        --danger-fg: #fecaca;
        --success-bg: #052e16;
        --success-fg: #bbf7d0;
        --warn-bg: #422006;
        --warn-fg: #fde68a;
        color-scheme: dark;
    }
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    line-height: 1.5;
}

body { min-height: 100vh; display: flex; flex-direction: column; }
main { flex: 1; padding-bottom: 3rem; }

a { color: var(--accent); }
h1 { font-size: 1.75rem; line-height: 1.2; margin: 1.5rem 0 .5rem; }
h2 { font-size: 1.15rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 1.25rem 0 .5rem; }
h1:focus { outline: none; }

.container { max-width: 1120px; margin: 0 auto; padding: 0 16px; }
.narrow { max-width: 520px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

/* Topbar */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; min-height: 60px; gap: 1rem; }
.brand { font-weight: 700; font-size: 1.15rem; color: var(--text); text-decoration: none; display: flex; gap: .5rem; align-items: center; }
.brand-mark { display: inline-grid; grid-template-columns: repeat(2, .55rem); gap: 2px; }
.brand-mark i { width: .55rem; height: .55rem; border-radius: 2px; }
.brand-mark i:nth-child(1) { background: #e5484d; }
.brand-mark i:nth-child(2) { background: #ffc53d; }
.brand-mark i:nth-child(3) { background: #12a594; }
.brand-mark i:nth-child(4) { background: #0090ff; }
.topnav { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.topnav a:not(.btn) { color: var(--text); text-decoration: none; font-size: .95rem; }
.topnav a:not(.btn):hover, .topnav a.active { color: var(--accent); }
.inline-form { display: inline; margin: 0; }

.footer { border-top: 1px solid var(--border); padding: 1.5rem 0; color: var(--muted); font-size: .85rem; }
.footer-inner { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.footer-links { display: flex; gap: 1rem; flex-wrap: wrap; }
.footer-links a { color: var(--muted); text-decoration: none; }
.footer-links a:hover { color: var(--accent); }

/* Buttons */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
    padding: .55rem 1rem; border-radius: 8px; border: 1px solid var(--border);
    background: var(--surface); color: var(--text); font: inherit; font-weight: 500;
    text-decoration: none; cursor: pointer; transition: background .15s, border-color .15s;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-danger { background: var(--danger-fg); border-color: var(--danger-fg); color: #fff; }
.btn-lg { padding: .75rem 1.4rem; font-size: 1.05rem; }
.btn-small { padding: .3rem .65rem; font-size: .85rem; }

/* Cards, forms */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; margin: 1rem 0; }
.card h1 { margin-top: 0; }
.card-link { display: flex; justify-content: space-between; align-items: center; gap: 1rem; color: var(--text); text-decoration: none; }
.card-link:hover { border-color: var(--accent); }
.list { list-style: none; padding: 0; margin: 0; }

label { display: flex; flex-direction: column; gap: .3rem; font-size: .9rem; font-weight: 500; }
label.checkbox { flex-direction: row; align-items: center; gap: .5rem; }
input, select {
    font: inherit; padding: .5rem .6rem; border: 1px solid var(--border); border-radius: 8px;
    background: var(--bg); color: var(--text); min-width: 0;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.stack { display: flex; flex-direction: column; gap: .75rem; }
.row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: end; }

.alert { padding: .75rem 1rem; border-radius: 8px; margin: 1rem 0; }
.alert-error { background: var(--danger-bg); color: var(--danger-fg); }
.alert-success { background: var(--success-bg); color: var(--success-fg); }
.alert-warn { background: var(--warn-bg); color: var(--warn-fg); }

.badge { font-size: .75rem; padding: .15rem .5rem; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-weight: 500; }

.page-header { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin: 1.5rem 0 1rem; }
.page-header h1 { margin: 0 0 .25rem; }
.page-header p { margin: 0; }

.divider { display: flex; align-items: center; gap: .75rem; color: var(--muted); font-size: .85rem; margin: .25rem 0; }
.divider::before, .divider::after { content: ""; flex: 1; border-top: 1px solid var(--border); }
.email-login { display: flex; flex-direction: column; gap: .5rem; }
.email-login p { margin: 0; }
.login-buttons { display: flex; flex-direction: column; gap: .6rem; margin-top: 1rem; }
.login-buttons form { margin: 0; }
.dev-login { display: flex; flex-direction: column; gap: .5rem; border-top: 1px dashed var(--border); padding-top: 1rem; margin-top: .5rem; }

/* Landing page */
.hero { background: linear-gradient(180deg, var(--accent-soft), var(--bg)); padding: 3rem 0 3.5rem; }
.hero-inner { display: grid; grid-template-columns: 1.2fr 1fr; gap: 3rem; align-items: center; }
.hero h1 { font-size: clamp(2rem, 5vw, 3.2rem); margin: .25rem 0 1rem; letter-spacing: -.02em; }
.eyebrow { color: var(--accent); font-weight: 600; margin: 0; }
.lead { font-size: 1.15rem; color: var(--muted); max-width: 36rem; }
.hero-actions { display: flex; gap: .75rem; flex-wrap: wrap; margin-top: 1.5rem; }
.hero-card { display: flex; justify-content: center; }
.mock-board {
    width: 100%; max-width: 320px; background: #0d0e14; border-radius: 20px; padding: 1rem;
    box-shadow: 0 20px 40px rgb(15 23 42 / .25); display: grid; grid-template-columns: repeat(4, 1fr); gap: .5rem;
}
.mock-pad {
    aspect-ratio: 1; border-radius: 10px; color: #fff; font-size: .7rem; font-weight: 700;
    display: grid; place-items: center; text-align: center; padding: .25rem;
}
.mock-pad.on { box-shadow: 0 0 0 3px #fff inset; }

.features { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 1rem; margin-top: 2.5rem; }
.feature { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; }
.feature p { color: var(--muted); margin: 0; }

.how { margin-top: 3rem; }
.steps { list-style: none; counter-reset: step; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 1rem; }
.steps li { counter-increment: step; display: flex; flex-direction: column; gap: .25rem; padding-left: 2.75rem; position: relative; }
.steps li::before {
    content: counter(step); position: absolute; left: 0; top: 0; width: 2rem; height: 2rem; border-radius: 50%;
    background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 700;
}
.steps span { color: var(--muted); }

.cta { margin-top: 3rem; text-align: center; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 2.5rem 16px; }
.cta p { color: var(--muted); }

@media (max-width: 800px) {
    .hero-inner { grid-template-columns: 1fr; gap: 2rem; }
    .hero { padding: 2rem 0; }
}

/* Laddningsindikator på knappar */
.spinner {
    display: inline-block; width: 1em; height: 1em; flex: none;
    border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%;
    animation: spin .7s linear infinite; vertical-align: -.15em;
}
.btn.is-loading { cursor: progress; opacity: .85; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 1.6s; } }

/* Blazor error UI */
#blazor-error-ui {
    background: lightyellow; color: #000; bottom: 0; box-shadow: 0 -1px 2px rgba(0, 0, 0, .2);
    display: none; left: 0; padding: .6rem 1.25rem .7rem; position: fixed; width: 100%; z-index: 1000;
}
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: .75rem; top: .5rem; }

/* Soundboard-editor */
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); margin: 1rem 0 0; overflow-x: auto; }
.tab {
    font: inherit; background: none; border: none; border-bottom: 2px solid transparent;
    padding: .6rem 1rem; color: var(--muted); cursor: pointer; white-space: nowrap;
}
.tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

.editor-grid { display: grid; gap: .5rem; }
.slot {
    aspect-ratio: 1.4; min-height: 64px; border: 0; border-radius: 12px; font: inherit; font-weight: 700;
    cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center;
    padding: .4rem; text-align: center; word-break: break-word; box-shadow: 0 3px 0 rgb(0 0 0 / .25);
}
.slot small { font-weight: 400; opacity: .8; font-size: .7rem; }
.slot.empty { background: transparent; color: var(--muted); border: 2px dashed var(--border); box-shadow: none; font-size: 1.5rem; }
.slot.empty:hover { border-color: var(--accent); color: var(--accent); }
.slot.selected { outline: 3px solid var(--accent); outline-offset: 2px; }

.swatches { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin-top: .3rem; }
.swatch { width: 2.25rem; height: 2.25rem; border-radius: 50%; border: 2px solid transparent; cursor: pointer; padding: 0; }
.swatch.on { border-color: var(--text); box-shadow: 0 0 0 2px var(--surface) inset; }
.swatches input[type=color] { width: 2.5rem; height: 2.25rem; padding: 0; background: none; border: 0; }
audio { width: 100%; max-width: 420px; }

/* Tabeller (bibliotek och användare) */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th { text-align: left; color: var(--muted); font-weight: 500; border-bottom: 1px solid var(--border); padding: .5rem; white-space: nowrap; }
.table td { border-bottom: 1px solid var(--border); padding: .5rem; vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table input { width: 100%; min-width: 10rem; }
.table audio { height: 2rem; max-width: 220px; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.badge-ok { background: var(--success-bg); color: var(--success-fg); }
.badge-danger { background: var(--danger-bg); color: var(--danger-fg); }
.usage { height: .4rem; width: 8rem; background: var(--border); border-radius: 99px; overflow: hidden; margin-top: .2rem; }
.usage > i { display: block; height: 100%; background: var(--accent); }

.link-button { background: none; border: 0; padding: 0; font: inherit; font-size: .85rem; color: var(--accent); cursor: pointer; text-decoration: underline; }
.table-nested { background: var(--bg); border-radius: 8px; }
.sub-row > td { padding: .25rem .5rem .75rem 1.5rem; }

/* Validering i formulär */
.label-text { font-size: .9rem; font-weight: 500; }
.field-hint { font-weight: 400; font-size: .8rem; color: var(--muted); align-self: flex-end; margin-top: -.15rem; }
.field-error {
    display: flex; gap: .4rem; align-items: flex-start; font-weight: 600; font-size: .9rem;
    color: var(--danger-fg); background: var(--danger-bg); border-radius: 8px; padding: .5rem .7rem;
}
.field-error::before { content: "!"; flex: none; width: 1.25rem; height: 1.25rem; border-radius: 50%; background: var(--danger-fg); color: var(--danger-bg); display: grid; place-items: center; font-size: .8rem; line-height: 1; }
input.invalid, select.invalid { border-color: var(--danger-fg); outline: 2px solid var(--danger-fg); outline-offset: -1px; }
.alert-inline { margin: 0; font-weight: 600; }
.alert-inline:focus { outline: 2px solid var(--danger-fg); outline-offset: 2px; }
.alert-sticky { position: sticky; top: .5rem; z-index: 5; box-shadow: 0 4px 14px rgb(0 0 0 / .18); font-weight: 600; }

/* Biblioteksväljare */
.picked { margin: 0; padding: .55rem .75rem; border-radius: 8px; background: var(--accent-soft); font-size: .92rem; }
.picked.none { background: var(--warn-bg); color: var(--warn-fg); }
.picker-search { width: 100%; }
.picker-list { list-style: none; margin: 0; padding: 0; max-height: 15rem; overflow-y: auto; border: 1px solid var(--border); border-radius: 10px; background: var(--bg); }
.picker-item { display: flex; align-items: stretch; border-bottom: 1px solid var(--border); }
.picker-item:last-child { border-bottom: 0; }
.picker-item.selected { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.picker-item .pick {
    flex: 1; min-width: 0; text-align: left; background: none; border: 0; padding: .6rem .75rem; font: inherit; color: inherit; cursor: pointer;
    display: flex; flex-direction: column; gap: .1rem;
}
.picker-item .pick:hover { background: rgb(127 127 127 / .08); }
.pick-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.picker-item small { color: var(--muted); }
.picker-item .play {
    flex: none; width: 3rem; border: 0; border-left: 1px solid var(--border); background: none; font-size: 1rem; color: var(--accent); cursor: pointer;
}
.picker-item .play:hover { background: rgb(127 127 127 / .12); }
.picker-item .play.on { background: var(--accent); color: #fff; }
.preview { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; padding: .5rem .75rem; border: 1px dashed var(--accent); border-radius: 10px; }
.preview audio { flex: 1; min-width: 12rem; height: 2.25rem; }
