:root {
    --bg: #eef2f7;
    --bg-accent: #dfe8f5;
    --surface: #ffffff;
    --text: #0f172a;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --primary-soft: #eef2ff;
    --danger: #dc2626;
    --danger-soft: #fef2f2;
    --shadow: 0 10px 40px rgba(15, 23, 42, .08);
    --shadow-sm: 0 1px 3px rgba(15, 23, 42, .06);
    --radius: 12px;
    --radius-lg: 18px;
    --font: "DM Sans", system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}

[data-theme="dark"] {
    --bg: #0b1120;
    --bg-accent: #111827;
    --surface: #151f32;
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --border: #243044;
    --primary: #818cf8;
    --primary-hover: #a5b4fc;
    --primary-soft: #1e1b4b;
    --danger-soft: #450a0a;
    --shadow: 0 10px 40px rgba(0, 0, 0, .35);
}

@media (prefers-color-scheme: dark) {
    html:not([data-theme="light"]) {
        --bg: #0b1120;
        --bg-accent: #111827;
        --surface: #151f32;
        --text: #f1f5f9;
        --text-muted: #94a3b8;
        --border: #243044;
        --primary: #818cf8;
        --primary-hover: #a5b4fc;
        --primary-soft: #1e1b4b;
        --danger-soft: #450a0a;
        --shadow: 0 10px 40px rgba(0, 0, 0, .35);
    }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-font-smoothing: antialiased; }

body {
    margin: 0;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.55;
    font-size: 15px;
}

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

/* —— Auth / login —— */
.auth-page {
    min-height: 100vh;
    background:
        radial-gradient(ellipse 80% 60% at 10% 0%, rgba(79, 70, 229, .18), transparent 55%),
        radial-gradient(ellipse 60% 50% at 90% 100%, rgba(14, 165, 233, .12), transparent 50%),
        var(--bg);
}

.auth-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem 1rem;
}

.auth-card {
    width: 100%;
    max-width: 420px;
    padding: 2rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
}

.auth-card__brand {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.75rem;
}

.auth-card__logo {
    width: 48px;
    height: 48px;
    display: grid;
    place-items: center;
    border-radius: 14px;
    background: linear-gradient(135deg, var(--primary), #0ea5e9);
    color: #fff;
    font-size: 1.25rem;
    font-weight: 700;
    flex-shrink: 0;
}

.auth-card__eyebrow {
    margin: 0 0 .15rem;
    font-size: .8rem;
    font-weight: 600;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.auth-card h1 {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -.02em;
}

.form--auth .field { display: block; margin-bottom: 1rem; }

.field__label {
    display: block;
    margin-bottom: .4rem;
    font-size: .875rem;
    font-weight: 600;
    color: var(--text);
}

.form input, .form select, .form textarea {
    display: block;
    width: 100%;
    padding: .7rem .85rem;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--bg);
    color: var(--text);
    font: inherit;
    transition: border-color .15s, box-shadow .15s;
}

.form input:focus, .form select:focus, .form textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, .15);
}

.btn--block {
    width: 100%;
    justify-content: center;
    margin-top: .5rem;
    padding: .75rem 1rem;
    font-size: .95rem;
    font-weight: 600;
}

/* —— Topbar —— */
.topbar {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: .85rem 1.5rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
    position: sticky;
    top: 0;
    z-index: 50;
    backdrop-filter: blur(8px);
}

.topbar__brand {
    display: flex;
    align-items: center;
    gap: .5rem;
    font-weight: 700;
    font-size: 1rem;
    letter-spacing: -.01em;
}

.topbar__logo {
    color: var(--primary);
    font-size: .9rem;
}

.topbar__nav { display: flex; gap: .35rem; flex-wrap: wrap; flex: 1; align-items: center; }
.topbar__group { display: flex; gap: .25rem; align-items: center; }
.topbar__group + .topbar__group::before {
    content: '';
    width: 1px;
    height: 1.15rem;
    background: var(--border);
    margin: 0 .15rem;
    flex-shrink: 0;
}

.topbar__nav a {
    color: var(--text-muted);
    font-size: .875rem;
    font-weight: 500;
    padding: .4rem .65rem;
    border-radius: 8px;
    text-decoration: none;
}

.topbar__nav a:hover {
    color: var(--primary);
    background: var(--primary-soft);
    text-decoration: none;
}

.topbar__prefs { display: flex; align-items: center; gap: .5rem; margin-left: auto; }
.topbar__user { font-size: .85rem; color: var(--text-muted); }

.topbar select {
    padding: .35rem .5rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    font: inherit;
    font-size: .8rem;
}

.container { max-width: 1200px; margin: 0 auto; padding: 1.75rem 1.5rem 3rem; }

h1 { font-size: 1.65rem; font-weight: 700; margin: 0 0 1.25rem; letter-spacing: -.02em; }
h2 { font-size: 1.1rem; font-weight: 600; margin: 0 0 .75rem; }
h3 { font-size: 1rem; font-weight: 600; margin: 0 0 .5rem; }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.35rem;
    margin-bottom: 1rem;
    box-shadow: var(--shadow-sm);
}

.card--highlight {
    border-color: rgba(79, 70, 229, .35);
    background: linear-gradient(180deg, var(--primary-soft), var(--surface));
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .35rem;
    padding: .5rem 1rem;
    border-radius: 10px;
    border: 1px solid transparent;
    font-size: .875rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    background: var(--surface);
    color: var(--text);
    text-decoration: none;
    transition: background .15s, transform .1s;
}

.btn:hover { text-decoration: none; }
.btn:active { transform: scale(.98); }
.btn--primary { background: var(--primary); color: #fff; }
.btn--primary:hover { background: var(--primary-hover); color: #fff; }
.btn--ghost { border-color: var(--border); background: transparent; }
.btn--ghost:hover { background: var(--bg); }
.btn--danger { background: var(--danger); color: #fff; }
.btn--sm { padding: .3rem .6rem; font-size: .8rem; }

.form label { display: block; margin-bottom: .75rem; font-size: .875rem; }
.form--grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: .75rem;
}
.form--grid .full { grid-column: 1 / -1; }
.row--inactive { opacity: .55; }
.section-heading { margin-top: 1.5rem; margin-bottom: .75rem; font-size: 1rem; }
.table-scroll { overflow-x: auto; }
.row-type-form { display: contents; }
.table--row-types { min-width: 52rem; }
.table--row-types input,
.table--row-types select {
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
}
.table--row-types .input-rate { max-width: 5.5rem; }
.table--row-types .input-sort { max-width: 4.5rem; }
.table--row-types .cell-center { text-align: center; width: 3.5rem; }
.table--row-types .cell-center input { width: auto; }
.table--row-types .cell-actions {
    white-space: nowrap;
    width: 1%;
}
.table--row-types .cell-actions .btn { margin-right: .25rem; }
.table--row-types .cell-actions .btn:last-child { margin-right: 0; }
.row-type-add { background: rgba(79, 70, 229, .06); }
.row-type-add:hover { background: rgba(79, 70, 229, .09); }
.table--row-types .row-type-add input::placeholder { color: var(--text-muted); opacity: .7; }
.checkbox { display: flex; align-items: center; gap: .5rem; }
.checkbox input { width: auto; margin: 0; }
.row-type-picker { border: 1px solid var(--border); border-radius: 10px; padding: .75rem 1rem; margin: 0; }
.row-type-picker legend { font-weight: 600; font-size: .875rem; padding: 0 .25rem; }
.row-type-picker__grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: .35rem .75rem; margin-top: .5rem; }
.form-actions { margin-top: 1rem; display: flex; gap: .5rem; flex-wrap: wrap; }
.inline-form { display: inline-flex; align-items: center; gap: .35rem; flex-wrap: wrap; }
.inline-form.is-hidden { display: none !important; }

.table { width: 100%; border-collapse: collapse; font-size: .875rem; }
.table th, .table td { padding: .65rem .75rem; border-bottom: 1px solid var(--border); text-align: left; }
.table th { color: var(--text-muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; }
.table tbody tr:hover { background: rgba(79, 70, 229, .04); }
.table--compact input { width: 100%; max-width: 120px; }
.table--spec th:last-child, .table--spec td:last-child { text-align: right; }

.alert {
    padding: .8rem 1rem;
    border-radius: 10px;
    margin-bottom: 1rem;
    background: #fff7ed;
    border: 1px solid #fed7aa;
    color: #9a3412;
}
.alert--ok {
    background: #ecfdf5;
    border-color: #a7f3d0;
    color: #065f46;
    display: flex;
    align-items: center;
    gap: .75rem;
    flex-wrap: wrap;
}

.finance-subnav {
    display: flex;
    gap: .35rem;
    margin-bottom: 1.25rem;
    padding: .35rem;
    background: var(--bg);
    border-radius: 10px;
    width: fit-content;
}
.finance-subnav__link {
    padding: .45rem .85rem;
    border-radius: 8px;
    font-size: .875rem;
    font-weight: 500;
    color: var(--text-muted);
    text-decoration: none;
}
.finance-subnav__link:hover { color: var(--text); background: var(--surface); }
.finance-subnav__link--active {
    background: var(--surface);
    color: var(--primary);
    box-shadow: 0 1px 2px rgba(0,0,0,.06);
}
.finance-sub-link {
    display: inline-block;
    margin-left: .5rem;
    font-size: .8rem;
    font-weight: 500;
    color: var(--primary);
    text-decoration: none;
}
.finance-sub-link:hover { text-decoration: underline; }

.form--inline-upload {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: .75rem;
}
.form--inline-upload .file-input { margin: 0; }
.form--ccbill { margin-bottom: 1rem; }

.ccbill-summary {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: .75rem;
    margin: 1rem 0 1.25rem;
}
.ccbill-summary__item {
    background: var(--bg);
    border-radius: 10px;
    padding: .75rem .85rem;
}
.ccbill-summary__item--highlight {
    background: rgba(79, 70, 229, .08);
    border: 1px solid rgba(79, 70, 229, .15);
}
.ccbill-summary__label {
    display: block;
    font-size: .75rem;
    color: var(--text-muted);
    margin-bottom: .25rem;
}
.ccbill-source { margin-top: .75rem; font-size: .85rem; }
.ccbill-storage-list { margin: .5rem 0 0 1.1rem; font-size: .85rem; }
.ccbill-parsed-preview { margin: .5rem 0 0 1.1rem; font-size: .85rem; }

.table--ccbill .input-rate { max-width: 8rem; margin-left: auto; }
.table--ccbill .input-pct { width: 3.5rem; display: inline-block; }
.table--ccbill .row--emphasis td { background: rgba(79, 70, 229, .04); }

.alert--error { background: var(--danger-soft); color: var(--danger); border: 1px solid rgba(220, 38, 38, .2); }

.toolbar { display: flex; gap: .75rem; align-items: center; margin-bottom: 1.25rem; flex-wrap: wrap; }
.muted { color: var(--text-muted); }

.badge {
    display: inline-block;
    padding: .15rem .5rem;
    border-radius: 999px;
    font-size: .75rem;
    font-weight: 600;
    background: var(--primary-soft);
    color: var(--primary);
}
.badge.is-hidden,
[hidden].badge { display: none !important; }
.badge--mine {
    background: var(--primary-soft);
    color: var(--primary);
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: .25rem;
    padding: .2rem .55rem;
    border-radius: 999px;
    background: var(--bg);
    border: 1px solid var(--border);
    font-size: .8rem;
    margin: .15rem;
}
.chip__remove { background: none; border: none; cursor: pointer; color: var(--text-muted); padding: 0 .2rem; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 768px) { .grid-2 { grid-template-columns: 1fr; } }

.fx-rate-bar { font-size: .8rem; }
.fx-note { font-size: .8rem; margin-top: 1rem; }
.table--fx .num, .table--fx-summary .num, .table--finance .num { text-align: right; white-space: nowrap; }
.table--finance { min-width: 36rem; }
.table--finance input,
.table--finance select {
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
}
.finance-form { display: contents; }
.finance-add { background: rgba(79, 70, 229, .06); }
.finance-add:hover { background: rgba(79, 70, 229, .09); }
.finance-entered__row {
    display: flex;
    gap: .35rem;
    align-items: center;
    justify-content: flex-end;
}
.finance-entered__row input { flex: 1; min-width: 4.5rem; max-width: 7rem; }
.finance-entered__row select { width: 4.5rem; flex-shrink: 0; }
.finance-preview-cell { font-size: .85rem; }
.finance-empty td { text-align: center; padding: 1.25rem; }
.badge--finance {
    font-size: .75rem;
    font-weight: 600;
    text-transform: none;
    letter-spacing: 0;
}
.badge--inkomst { background: rgba(34, 197, 94, .14); color: #15803d; }
.badge--utgaende { background: rgba(239, 68, 68, .12); color: #b91c1c; }
.badge--sparande { background: rgba(59, 130, 246, .14); color: #1d4ed8; }
.badge--lon { background: rgba(139, 92, 246, .14); color: #6d28d9; }
[data-theme="dark"] .badge--inkomst { color: #86efac; }
[data-theme="dark"] .badge--utgaende { color: #fca5a5; }
[data-theme="dark"] .badge--sparande { color: #93c5fd; }
[data-theme="dark"] .badge--lon { color: #c4b5fd; }
.table--finance .cell-actions { white-space: nowrap; width: 1%; }
.table--fx-summary { margin-top: .5rem; }
.table__total-row td { border-top: 2px solid var(--border); padding-top: .75rem; }
.rate-list { list-style: none; padding: 0; margin: .5rem 0 0; }
.rate-list li { padding: .25rem 0; }
.fx-converter__input { width: 100%; max-width: 12rem; }
.fx-converter__results { margin-top: 1rem; display: grid; gap: .5rem; }
.fx-converter__row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: .5rem .75rem;
    background: var(--bg);
    border-radius: 8px;
    font-size: .95rem;
}
.fx-converter__row strong { font-size: 1.05rem; }

.schedule-summary { margin-bottom: 1.25rem; }
.schedule-summary__stats { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: 1rem; }
.schedule-summary__table { margin-top: .5rem; }
.schedule-summary__unassigned { margin-top: 1rem; font-size: .875rem; }
.schedule-summary__notes { margin-top: 1rem; font-size: .875rem; }
.schedule-note-link {
    background: none;
    border: none;
    padding: 0;
    color: var(--primary);
    font: inherit;
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 2px;
}
.schedule-note-link:hover { color: var(--primary-hover, var(--primary)); }
.schedule-week-note {
    margin: .75rem 0 1rem;
    padding: .6rem .75rem;
    background: var(--bg);
    border-radius: 10px;
    border: 1px solid var(--border);
}
.schedule-week-note__form { margin: 0; }
.schedule-week-note__label {
    display: block;
    font-size: .78rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: .35rem;
    letter-spacing: .01em;
}
.schedule-week-note__row {
    display: flex;
    align-items: flex-end;
    gap: .5rem;
}
.schedule-week-note__row textarea {
    flex: 1;
    min-height: 2.4rem;
    max-height: 5rem;
    resize: vertical;
    font-size: .85rem;
    line-height: 1.4;
    padding: .4rem .55rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface);
}
.schedule-week-note__row .btn { flex-shrink: 0; }
.schedule-week-note__flash {
    margin: 0 0 .5rem;
    font-size: .8rem;
    color: #15803d;
}

.lightbox {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.lightbox[hidden] { display: none !important; }
.lightbox__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, .55);
}
.lightbox__panel {
    position: relative;
    max-width: 32rem;
    width: 100%;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: 0 20px 40px rgba(0, 0, 0, .2);
}
.lightbox__title { margin: 0 0 .75rem; font-size: 1.1rem; }
.lightbox__body {
    margin: 0 0 1rem;
    white-space: pre-wrap;
    line-height: 1.5;
    max-height: 50vh;
    overflow-y: auto;
}
body.lightbox-open { overflow: hidden; }

.summary-dl { display: grid; grid-template-columns: 1fr auto; gap: .5rem .75rem; }
.summary-dl dt { color: var(--text-muted); }
.summary-dl dd { margin: 0; text-align: right; font-weight: 500; }

.worker-block { margin: 1.5rem 0; padding-top: 1.25rem; border-top: 1px solid var(--border); }

.tabs { display: flex; gap: .35rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.tab {
    padding: .55rem 1rem;
    border-radius: 10px;
    color: var(--text-muted);
    border: 1px solid var(--border);
    font-weight: 500;
    font-size: .9rem;
    text-decoration: none;
}
.tab:hover { background: var(--bg); text-decoration: none; }
.tab--active { background: var(--primary); color: #fff; border-color: var(--primary); }

.schedule-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1rem; }
.schedule-day { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; }
.schedule-slot { padding: .85rem 0; border-bottom: 1px solid var(--border); font-size: .875rem; }
.schedule-slot:last-child { border-bottom: none; }
.schedule-slot__head { display: flex; align-items: center; gap: .5rem; margin-bottom: .35rem; flex-wrap: wrap; }
.request-row { display: flex; align-items: center; gap: .35rem; margin: .25rem 0; flex-wrap: wrap; }

.spec__header { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 1rem; margin-bottom: 1rem; }
.spec__meta { text-align: right; font-size: .875rem; }
.spec__worker { padding: 1rem; background: var(--bg); border-radius: var(--radius); margin-bottom: 1rem; }
.spec__section { margin-bottom: 1rem; }
.spec__total { text-align: right; font-size: 1.15rem; font-weight: 700; padding-top: 1rem; border-top: 2px solid var(--border); }

.assignment-list { padding-left: 1.25rem; }
.schedule-slot--mine {
    background: var(--primary-soft);
    border-radius: 8px;
    padding: .5rem;
    margin: .25rem 0;
}
.schedule-slot--flash {
    animation: schedule-flash 1.2s ease;
}
@keyframes schedule-flash {
    0%, 100% { background: transparent; }
    30% { background: rgba(79, 70, 229, .15); }
}
.badge--pending {
    background: rgba(234, 179, 8, .2);
    color: #a16207;
}
.badge--ok {
    background: rgba(22, 163, 74, .15);
    color: #15803d;
}
.live-indicator {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    font-size: .8rem;
    color: var(--text-muted);
    padding: .35rem .65rem;
    border-radius: 999px;
    border: 1px solid var(--border);
}
.live-indicator__dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
}
.live-indicator--ok .live-indicator__dot {
    background: #16a34a;
    box-shadow: 0 0 0 0 rgba(22, 163, 74, .5);
    animation: live-pulse 2s infinite;
}
.live-indicator--err .live-indicator__dot { background: #dc2626; }
@keyframes live-pulse {
    70% { box-shadow: 0 0 0 6px rgba(22, 163, 74, 0); }
    100% { box-shadow: 0 0 0 0 rgba(22, 163, 74, 0); }
}
[x-cloak] { display: none !important; }

@media (max-width: 640px) {
    .topbar__nav { order: 3; width: 100%; }
    .auth-card { padding: 1.5rem; }
}
