:root {
    color-scheme: light dark;
    --bg: #f4f6f5;
    --surface: #ffffff;
    --surface-2: #eef2f0;
    --text: #14201b;
    --muted: #5c6a64;
    --border: #e1e7e4;
    --accent: #0f7a5c;
    --accent-hover: #0b664c;
    --accent-text: #ffffff;
    --accent-soft: #dff2ea;
    --positive: #0b7355;
    --error: #b3261e;
    --income: #2a78d6;
    --expense: #eb6834;
    --shadow: 0 1px 2px rgb(20 32 27 / 5%), 0 6px 20px rgb(20 32 27 / 5%);
    --radius: 16px;
    --tabs-height: 68px;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #101513;
        --surface: #1a201d;
        --surface-2: #242c28;
        --text: #eaf0ed;
        --muted: #9dabA4;
        --border: #2c3531;
        --accent: #4fcba4;
        --accent-hover: #6fdab8;
        --accent-text: #08201a;
        --accent-soft: #1d3a30;
        --positive: #6fdab8;
        --error: #f2b8b5;
        --income: #3987e5;
        --expense: #d95926;
        --shadow: none;
    }
}

* {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 16px/1.5 Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    -webkit-tap-highlight-color: transparent;
}

a {
    color: var(--accent);
}

h1 {
    margin: 0;
    font-size: 28px;
    line-height: 1.2;
    letter-spacing: -0.02em;
}

h2 {
    margin: 0 0 12px;
    font-size: 16px;
    letter-spacing: -0.01em;
}

p {
    margin: 0 0 12px;
}

small {
    font-size: 13px;
}

[hidden] {
    display: none !important;
}

.muted {
    color: var(--muted);
}

.positive {
    color: var(--positive);
}

.error {
    margin: 0 0 12px;
    color: var(--error);
}

.icon {
    width: 22px;
    height: 22px;
    flex: none;
    fill: none;
    stroke: currentcolor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* Ramverk: nedre flikrad i mobilen, sidomeny på datorn */

main {
    width: 100%;
    max-width: 1120px;
    margin: 0 auto;
    padding: max(20px, env(safe-area-inset-top)) 16px calc(var(--tabs-height) + 32px + env(safe-area-inset-bottom));
}

.signed-out main {
    max-width: 420px;
    padding-top: 12vh;
    padding-bottom: 32px;
}

.sidebar {
    display: none;
}

.tabs {
    position: fixed;
    inset: auto 0 0;
    z-index: 10;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    align-items: center;
    height: calc(var(--tabs-height) + env(safe-area-inset-bottom));
    padding: 0 4px env(safe-area-inset-bottom);
    background: var(--surface);
    border-top: 1px solid var(--border);
}

.tabs a {
    position: relative;
    display: grid;
    justify-items: center;
    gap: 2px;
    padding: 6px 0;
    color: var(--muted);
    font-size: 11px;
    text-decoration: none;
}

.tabs a[aria-current] {
    color: var(--accent);
    font-weight: 600;
}

.tabs .tab-add {
    justify-self: center;
    width: 56px;
    height: 56px;
    place-items: center;
    padding: 0;
    margin-top: -18px;
    background: var(--accent);
    color: var(--accent-text);
    border-radius: 50%;
    box-shadow: 0 6px 16px rgb(15 122 92 / 35%);
}

.tabs .tab-add .icon {
    width: 28px;
    height: 28px;
    stroke-width: 2.2;
}

.badge {
    display: inline-block;
    min-width: 20px;
    padding: 0 6px;
    background: var(--accent);
    color: var(--accent-text);
    border-radius: 10px;
    font-size: 12px;
    font-weight: 600;
    line-height: 20px;
    text-align: center;
}

.tabs .badge {
    position: absolute;
    top: 0;
    left: calc(50% + 6px);
    min-width: 18px;
    padding: 0 5px;
    font-size: 11px;
    line-height: 18px;
}

@media (min-width: 900px) {
    body.signed-in {
        display: grid;
        grid-template-columns: 240px minmax(0, 1fr);
        min-height: 100vh;
    }

    .tabs {
        display: none;
    }

    .signed-in main {
        max-width: 1240px;
        margin: 0;
        padding: 32px 40px 48px;
    }

    .sidebar {
        position: sticky;
        top: 0;
        display: flex;
        flex-direction: column;
        gap: 20px;
        height: 100vh;
        padding: 24px 16px;
        background: var(--surface);
        border-right: 1px solid var(--border);
    }

    .brand {
        padding: 0 12px;
        color: var(--text);
        font-size: 20px;
        font-weight: 700;
        letter-spacing: -0.02em;
        text-decoration: none;
    }

    .sidebar .add {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 6px;
    }

    .sidebar nav {
        display: grid;
        gap: 2px;
        flex: 1;
        align-content: start;
    }

    .sidebar nav a {
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 10px 12px;
        color: var(--muted);
        border-radius: 10px;
        text-decoration: none;
    }

    .sidebar nav a span:not(.badge) {
        flex: 1;
    }

    .sidebar nav a:hover {
        background: var(--surface-2);
        color: var(--text);
    }

    .sidebar nav a[aria-current] {
        background: var(--accent-soft);
        color: var(--text);
        font-weight: 600;
    }
}

/* Knappar och fält */

button,
a.button {
    display: inline-block;
    padding: 12px 18px;
    background: var(--accent);
    color: var(--accent-text);
    border: 0;
    border-radius: 12px;
    font: inherit;
    font-weight: 600;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
}

button:hover,
a.button:hover {
    background: var(--accent-hover);
}

button.secondary,
a.button.secondary {
    background: var(--accent-soft);
    color: var(--text);
}

button.quiet {
    padding: 8px 12px;
    background: transparent;
    color: var(--muted);
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 14px;
    font-weight: 500;
}

button.quiet:hover {
    background: var(--surface-2);
    color: var(--text);
}

button.plain {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 10px 12px;
    background: transparent;
    color: var(--muted);
    font-weight: 400;
}

button.plain:hover {
    background: var(--surface-2);
    color: var(--text);
}

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

label,
.field > span {
    display: grid;
    gap: 6px;
    color: var(--muted);
    font-size: 14px;
    font-weight: 500;
}

input,
select {
    width: 100%;
    min-height: 46px;
    padding: 10px 12px;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 12px;
    font: inherit;
}

input:focus,
select:focus {
    border-color: var(--accent);
    outline: 2px solid var(--accent-soft);
}

summary {
    color: var(--muted);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
}

details[open] > summary {
    margin-bottom: 12px;
}

.details-body {
    display: grid;
    gap: 12px;
}

form.card,
fieldset.card,
.filter-panel {
    display: grid;
    gap: 12px;
    padding: 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

fieldset.card {
    margin: 0 0 12px;
}

.narrow {
    max-width: 640px;
}

.entry {
    display: grid;
    gap: 16px;
}

.field {
    display: grid;
    gap: 8px;
}

.choices {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 8px;
}

button.choice,
.pick span {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 48px;
    padding: 8px 10px;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 12px;
    font-size: 14px;
    font-weight: 500;
    line-height: 1.25;
    text-align: center;
    cursor: pointer;
}

button.choice:hover,
.pick span:hover {
    background: var(--surface-2);
}

button.choice.selected,
.pick input:checked + span {
    background: var(--accent);
    color: var(--accent-text);
    border-color: var(--accent);
}

.pick input,
.toggle input {
    position: absolute;
    width: 1px;
    min-height: 0;
    padding: 0;
    opacity: 0;
}

.pick,
.toggle label {
    position: relative;
    display: block;
}

.pick input:focus-visible + span,
.toggle input:focus-visible + span {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.toggle {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
    padding: 4px;
    background: var(--surface-2);
    border-radius: 14px;
}

.toggle span {
    display: block;
    padding: 10px;
    color: var(--muted);
    border-radius: 10px;
    font-size: 15px;
    font-weight: 600;
    text-align: center;
    cursor: pointer;
}

.toggle input:checked + span {
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow);
}

.amount-field span {
    display: flex;
    align-items: baseline;
    gap: 8px;
    color: var(--muted);
    font-size: 20px;
}

.amount-field input {
    min-height: 0;
    padding: 4px 0;
    background: transparent;
    border: 0;
    border-bottom: 2px solid var(--border);
    border-radius: 0;
    color: var(--text);
    font-size: 40px;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.amount-field input:focus {
    border-color: var(--accent);
    outline: 0;
}

.save {
    width: 100%;
    padding: 14px;
    font-size: 17px;
}

.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 16px;
    align-items: center;
    margin: 16px 0 0;
}

.suggestion {
    margin-bottom: 16px;
    background: var(--accent-soft);
    border-color: transparent;
    box-shadow: none;
}

.suggestion label {
    color: var(--text);
}

.receipt {
    display: grid;
    gap: 2px;
    margin-bottom: 20px;
    padding: 20px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow-wrap: anywhere;
}

.merchant {
    font-size: 18px;
}

.big {
    font-size: 32px;
    font-weight: 700;
    letter-spacing: -0.02em;
    font-variant-numeric: tabular-nums;
}

.current {
    display: grid;
    gap: 4px;
    margin-bottom: 16px;
    overflow-wrap: anywhere;
}

.empty {
    padding: 32px 16px;
    text-align: center;
}

/* Sidhuvud, val av intervall */

.page-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 16px;
}

.page-head p {
    margin: 0;
}

.desktop-only {
    display: none !important;
}

@media (min-width: 900px) {
    .desktop-only {
        display: inline-block !important;
    }
}

.notice {
    display: block;
    margin: 0 0 16px;
    padding: 12px 14px;
    background: var(--accent-soft);
    color: var(--text);
    border-radius: 12px;
    text-decoration: none;
}

.chips {
    display: flex;
    gap: 8px;
    margin: 0 -16px 8px;
    padding: 2px 16px;
    overflow-x: auto;
    scrollbar-width: none;
}

.chips::-webkit-scrollbar {
    display: none;
}

.chips a {
    flex: none;
    padding: 8px 14px;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 999px;
    font-size: 14px;
    font-weight: 500;
    text-decoration: none;
}

.chips a:hover {
    background: var(--surface-2);
}

.chips a[aria-current] {
    background: var(--text);
    color: var(--bg);
    border-color: var(--text);
}

.custom-range {
    margin-bottom: 16px;
}

.range-form {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    align-items: end;
}

.range-form button {
    grid-column: 1 / -1;
}

@media (min-width: 600px) {
    .range-form {
        grid-template-columns: 180px 180px auto;
        justify-content: start;
    }

    .range-form button {
        grid-column: auto;
    }
}

.segments {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 2px;
    margin-bottom: 12px;
    padding: 4px;
    background: var(--surface-2);
    border-radius: 14px;
}

.segments a {
    padding: 8px 2px;
    color: var(--muted);
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    text-align: center;
    text-decoration: none;
}

.segments a[aria-current] {
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow);
}

/* Översikt */

.stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 12px;
}

.stat {
    display: grid;
    align-content: start;
    gap: 2px;
    padding: 14px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.stat strong {
    font-size: 21px;
    letter-spacing: -0.02em;
    font-variant-numeric: tabular-nums;
}

.stat-main {
    grid-column: 1 / -1;
    background: var(--accent);
    color: var(--accent-text);
    border-color: var(--accent);
}

.stat-main strong {
    font-size: 34px;
}

.stat:last-child {
    grid-column: 1 / -1;
}

@media (min-width: 900px) {
    .stats {
        grid-template-columns: 1.4fr 1fr 1fr 1fr;
    }

    .stat-main,
    .stat:last-child {
        grid-column: auto;
    }
}

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

.panel .accounts {
    margin: 0;
    background: transparent;
    border: 0;
    box-shadow: none;
}

.panel .accounts li {
    padding: 10px 0;
}

.dashboard {
    display: grid;
    gap: 12px;
    margin-bottom: 12px;
}

.dashboard .panel,
.stack .panel:last-child {
    margin-bottom: 0;
}

.stack {
    display: grid;
    gap: 12px;
    align-content: start;
}

.stack .panel {
    margin-bottom: 0;
}

@media (min-width: 1100px) {
    .dashboard {
        grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
        align-items: start;
    }
}

.bars {
    display: grid;
    gap: 4px;
    margin: 0 -8px;
    padding: 0;
    list-style: none;
}

.bars a {
    display: grid;
    gap: 4px;
    padding: 8px;
    color: var(--text);
    border-radius: 10px;
    text-decoration: none;
}

.bars a:hover {
    background: var(--surface-2);
}

.bar-label {
    display: flex;
    justify-content: space-between;
    gap: 16px;
}

.bar-label strong {
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.bar {
    display: block;
}

.bar-track {
    fill: var(--surface-2);
}

.bar-fill {
    fill: var(--accent);
}

.legend {
    display: flex;
    gap: 16px;
    margin-bottom: 8px;
    color: var(--muted);
    font-size: 13px;
}

.legend span {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.key {
    width: 10px;
    height: 10px;
    border-radius: 3px;
}

.key.income {
    background: var(--income);
}

.key.expense {
    background: var(--expense);
}

.columns {
    display: flex;
    gap: 4px;
    height: 190px;
    overflow-x: auto;
    border-bottom: 0;
}

.columns a {
    display: grid;
    flex: 1 0 40px;
    grid-template-rows: 1fr auto;
    gap: 6px;
    justify-items: center;
    padding: 4px 2px 0;
    color: var(--muted);
    border-radius: 8px;
    font-size: 12px;
    text-decoration: none;
}

.columns a:hover {
    background: var(--surface-2);
}

.columns svg {
    display: block;
    width: 100%;
    max-width: 56px;
    height: 100%;
    min-height: 0;
    border-bottom: 1px solid var(--border);
}

.columns .income {
    fill: var(--income);
}

.columns .expense {
    fill: var(--expense);
}

.table-view {
    margin-top: 12px;
}

.tooltip {
    position: fixed;
    z-index: 20;
    padding: 8px 10px;
    background: var(--text);
    color: var(--bg);
    border-radius: 8px;
    font-size: 13px;
    white-space: pre-line;
    pointer-events: none;
}

.table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    padding: 8px;
    border-bottom: 1px solid var(--border);
    text-align: right;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

th:first-child,
td:first-child {
    text-align: left;
}

th {
    color: var(--muted);
    font-size: 13px;
    font-weight: 500;
}

.plain-list {
    display: grid;
    margin: 0 -8px;
    padding: 0;
    list-style: none;
}

.plain-list a {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    padding: 8px;
    color: var(--text);
    border-radius: 10px;
    text-decoration: none;
    overflow-wrap: anywhere;
}

.plain-list a:hover {
    background: var(--surface-2);
}

.plain-list small {
    display: block;
}

.plain-list strong {
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

/* Listor */

.accounts {
    margin: 0 0 16px;
    padding: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    list-style: none;
}

.accounts li {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 4px 16px;
    padding: 12px 16px;
}

.accounts li + li {
    border-top: 1px solid var(--border);
}

.accounts small {
    display: block;
    overflow-wrap: anywhere;
}

.value {
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.menu li {
    padding: 0;
}

.menu a {
    display: flex;
    flex: 1;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    color: var(--text);
    text-decoration: none;
}

.filter-panel {
    margin-bottom: 12px;
    padding: 12px 16px;
}

.filters {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.filters .wide,
.filter-actions {
    grid-column: 1 / -1;
}

.filter-actions {
    display: flex;
    align-items: center;
    gap: 16px;
}

@media (min-width: 900px) {
    .filters {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }
}

.result-line {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    margin: 16px 0 4px;
}

.result-line strong {
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.day {
    margin: 16px 0 6px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 600;
}

.transactions {
    margin: 0;
    padding: 0;
    overflow: hidden;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    list-style: none;
}

.transactions li + li {
    border-top: 1px solid var(--border);
}

.transactions a {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 12px 16px;
    color: var(--text);
    text-decoration: none;
}

.transactions a:hover {
    background: var(--surface-2);
}

.transactions .main {
    display: grid;
    min-width: 0;
    overflow-wrap: anywhere;
}

.transactions .name {
    font-weight: 500;
}

.transactions .amount {
    flex: none;
    font-variant-numeric: tabular-nums;
}

.transactions .dimmed .name,
.transactions .dimmed .amount {
    color: var(--muted);
    font-weight: 400;
}

.signed-out h1 {
    margin-bottom: 16px;
}

.codes {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 8px 24px;
    margin: 12px 0 0;
    padding-left: 24px;
}

.codes code {
    font: 600 17px/1.6 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    letter-spacing: 0.04em;
}

.signed-out details {
    margin: 4px 0;
}
