:root {
    --bg: #f3f4f7;
    --surface: #ffffff;
    --text: #1d2026;
    --muted: #5d6573;
    --border: #e0e3e9;
    --accent: #3456d1;
    --accent-text: #ffffff;
    --accent-soft: #e6ebfb;
    --danger: #c0262d;
    --warning-soft: #fff1d6;
    --warning-text: #7a4b00;
    --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 6px 18px rgb(16 24 40 / 6%);
    --radius: 14px;
    color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #111318;
        --surface: #1a1d24;
        --text: #e7e9ee;
        --muted: #9ba2ae;
        --border: #2a2e37;
        --accent: #7b96ff;
        --accent-text: #0c0f16;
        --accent-soft: #232b45;
        --danger: #ff7a7a;
        --warning-soft: #3a2e14;
        --warning-text: #ffd27a;
        --shadow: none;
    }
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
}

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

body {
    min-height: 100vh;
    min-height: 100dvh;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    font-size: 16px;
    line-height: 1.5;
    overflow-wrap: anywhere;
}

h1 {
    margin: 0;
    font-size: 1.4rem;
    line-height: 1.25;
}

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

/* Top bar */

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 4px 16px 4px 24px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.brand {
    min-width: 0;
    overflow: hidden;
    color: var(--text);
    font-weight: 700;
    font-size: 1.1rem;
    text-decoration: none;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.session {
    display: flex;
    flex-shrink: 0;
    align-items: center;
    gap: 6px;
}

.session form {
    margin: 0;
}

.account-chip {
    padding: 2px 10px;
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent);
    font-size: 0.85rem;
    font-weight: 600;
    max-width: 14ch;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Settings link (gear) in the top bar */

.icon-link {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
    border-radius: 8px;
    color: var(--muted);
    font-size: 1.15rem;
    text-decoration: none;
}

.icon-link:hover,
.icon-link:focus-visible {
    background: var(--accent-soft);
    color: var(--text);
}

/* Settings page */

/* Tabs: General + one per app with settings (Timon, 2026-10-18). Scrolls sideways on a phone. */
.settings-tabs {
    display: flex;
    gap: 4px;
    margin: 0 0 16px;
    padding-bottom: 2px;
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    scrollbar-width: thin;
}

.settings-tab {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    padding: 8px 14px;
    border-bottom: 3px solid transparent;
    color: var(--muted);
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
}

.settings-tab:hover,
.settings-tab:focus-visible {
    color: var(--text);
}

.settings-tab[aria-current="page"] {
    border-bottom-color: var(--accent);
    color: var(--accent);
}

.settings-section {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 20px;
}

.settings-section h2 {
    margin: 0;
    font-size: 1.15rem;
}

.settings-section h3 {
    margin: 4px 0 0;
    font-size: 1rem;
}

.settings-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.settings-field {
    display: grid;
    grid-template-columns: minmax(120px, 200px) minmax(0, 1fr);
    align-items: center;
    gap: 12px;
}

.settings-field input {
    min-height: 44px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--bg);
    color: var(--text);
    font: inherit;
}

.settings-field input:focus {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

.settings-button {
    align-self: flex-start;
    min-height: 44px;
    padding: 10px 20px;
    border: 0;
    border-radius: 10px;
    background: var(--accent);
    color: var(--accent-text);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}

.settings-flash {
    margin: 0 0 16px;
    padding: 10px 14px;
    border-radius: 10px;
    background: var(--accent-soft);
    color: var(--text);
}

.settings-apps {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.settings-apps a {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 44px;
    color: var(--accent);
    text-decoration: none;
}

.settings-apps a:hover,
.settings-apps a:focus-visible {
    text-decoration: underline;
}

@media (max-width: 560px) {
    .settings-field {
        grid-template-columns: 1fr;
        gap: 6px;
    }

    .settings-button {
        align-self: stretch;
    }
}

/* Language selector (top right, every page). A <details> menu: no script needed. */

.lang-menu {
    position: relative;
}

.lang-menu summary {
    display: flex;
    align-items: center;
    gap: 4px;
    min-height: 44px;
    padding: 0 10px;
    border-radius: 8px;
    color: var(--muted);
    font-size: 0.9rem;
    font-weight: 650;
    cursor: pointer;
    list-style: none;
    user-select: none;
}

.lang-menu summary::-webkit-details-marker {
    display: none;
}

.lang-menu summary::after {
    content: "▾";
    font-size: 0.75rem;
}

.lang-menu summary:hover,
.lang-menu summary:focus-visible,
.lang-menu[open] summary {
    background: var(--accent-soft);
    color: var(--text);
}

.lang-menu ul {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    z-index: 20;
    min-width: 170px;
    margin: 0;
    padding: 6px;
    list-style: none;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 8px 28px rgb(16 24 40 / 18%);
}

.lang-menu a {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    min-height: 44px;
    padding: 0 12px;
    border-radius: 8px;
    color: var(--text);
    text-decoration: none;
}

.lang-menu a:hover,
.lang-menu a:focus-visible {
    background: var(--accent-soft);
}

.lang-menu a[aria-current="true"] {
    color: var(--accent);
    font-weight: 700;
}

.lang-code {
    color: var(--muted);
    font-size: 0.8rem;
    font-weight: 600;
}

.link-button {
    min-height: 44px;
    padding: 0 8px;
    border: 0;
    background: none;
    color: var(--muted);
    font: inherit;
    cursor: pointer;
}

.link-button:hover,
.link-button:focus-visible {
    color: var(--text);
    text-decoration: underline;
}

/* Page frames */

main.content {
    max-width: 1000px;
    margin: 0 auto;
    padding: 32px 24px;
}

main.centered {
    display: grid;
    place-items: center;
    /* The top bar (with the language selector) is about 53px high. */
    min-height: calc(100vh - 53px);
    min-height: calc(100dvh - 53px);
    padding: 24px 16px;
}

.page-title {
    margin-bottom: 20px;
}

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

.app-icon {
    font-size: 2.2rem;
    line-height: 1;
}

/* Overview tiles */

.tiles {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
    gap: 16px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.tile {
    display: flex;
    flex-direction: column;
    gap: 6px;
    height: 100%;
    padding: 22px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    color: inherit;
    text-decoration: none;
    transition: transform 0.12s ease, border-color 0.12s ease;
}

.tile:hover,
.tile:focus-visible {
    transform: translateY(-2px);
    border-color: var(--accent);
}

.tile .app-icon {
    margin-bottom: 6px;
}

.tile-name {
    font-weight: 650;
    font-size: 1.05rem;
}

.tile-description {
    color: var(--muted);
    font-size: 0.92rem;
}

/* Login */

.login {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
    max-width: 360px;
}

.login .app-icon,
.login h1 {
    text-align: center;
}

.login h1 {
    margin-bottom: 10px;
}

label {
    font-size: 0.9rem;
    font-weight: 600;
}

input[type="password"] {
    min-height: 44px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--bg);
    color: var(--text);
    font: inherit;
}

input[type="password"]:focus {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

.login button {
    min-height: 44px;
    margin-top: 6px;
    padding: 10px 12px;
    border: 0;
    border-radius: 10px;
    background: var(--accent);
    color: var(--accent-text);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}

.login button:hover,
.login button:focus-visible {
    filter: brightness(1.08);
}

.error {
    margin: 0;
    color: var(--danger);
    font-size: 0.92rem;
}

/* App placeholder, no access, error */

.notice {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    max-width: 480px;
    margin: 40px auto;
    text-align: center;
}

.construction {
    margin: 4px 0;
    padding: 6px 16px;
    border-radius: 999px;
    background: var(--warning-soft);
    color: var(--warning-text);
    font-weight: 600;
}

.back {
    color: var(--accent);
    text-decoration: none;
}

.back:hover,
.back:focus-visible {
    text-decoration: underline;
}

/* Phones: tiles become compact rows (icon left, text right), one per line. */
@media (max-width: 560px) {
    .topbar {
        padding: 4px 8px 4px 16px;
    }

    main.content {
        padding: 20px 16px;
    }

    .page-title {
        margin-bottom: 14px;
    }

    .card {
        padding: 24px 20px;
    }

    .tiles {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .tile {
        display: grid;
        grid-template-columns: auto 1fr;
        grid-template-areas:
            "icon name"
            "icon description";
        column-gap: 14px;
        row-gap: 2px;
        align-items: center;
        padding: 14px 16px;
    }

    .tile .app-icon {
        grid-area: icon;
        margin-bottom: 0;
        font-size: 1.9rem;
    }

    .tile-name {
        grid-area: name;
    }

    .tile-description {
        grid-area: description;
    }

    .notice {
        margin: 16px auto;
    }
}

@media (prefers-reduced-motion: reduce) {
    .tile {
        transition: none;
    }
}
