:root {
    color-scheme: light dark;
    --bg: #f4f5f7;
    --panel: #ffffff;
    --raised: #f0f1f4;
    --line: #d9dce3;
    --text: #1c1f26;
    --muted: #626978;
    --accent: #4752c4;
    --accent-text: #ffffff;
    --danger: #b3261e;
    --warn-bg: #fff4d6;
    --warn-text: #5c4300;
    --own-bg: #eceefd;
    --amber: #9a6200;
    --green: #1f7a3d;
    --blue: #1f5fb8;
    --teal: #0f7068;
    --red: #b3261e;
    --purple: #7a3fb5;
    --grey: #626978;
    --issue-bg: #fff0db;
    --issue-text: #804600;
    --issue-line: #d29a51;
    --suggestion-bg: #e1f3f4;
    --suggestion-text: #075c65;
    --suggestion-line: #5aa0a8;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #16181d;
        --panel: #1e2128;
        --raised: #272b34;
        --line: #343944;
        --text: #e6e8ee;
        --muted: #9aa1b1;
        --accent: #7c87f5;
        --accent-text: #10121a;
        --danger: #ff8a80;
        --warn-bg: #3d3212;
        --warn-text: #ffe08a;
        --own-bg: #272b45;
        --amber: #f0b84a;
        --green: #6fd08c;
        --blue: #7fb2ff;
        --teal: #5fd0c5;
        --red: #ff8a80;
        --purple: #c79bf5;
        --grey: #9aa1b1;
        --issue-bg: #3b2d1d;
        --issue-text: #ffd099;
        --issue-line: #9a7141;
        --suggestion-bg: #18363b;
        --suggestion-text: #97e0e7;
        --suggestion-line: #478b94;
    }
}

* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

html,
body {
    height: 100%;
    margin: 0;
}

body {
    height: 100vh;
    height: 100dvh;
    min-width: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg);
    color: var(--text);
    font: 14px/1.45 "Segoe UI", system-ui, sans-serif;
}

button,
input,
select,
textarea {
    font: inherit;
    color: inherit;
}

input,
select,
textarea {
    min-width: 0;
    max-width: 100%;
    min-height: 44px;
    width: 100%;
    padding: 9px 10px;
    font-size: 16px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--panel);
}

textarea {
    min-height: 96px;
    resize: vertical;
}

input[type="checkbox"] {
    flex: none;
    width: auto;
    min-height: 20px;
    min-width: 20px;
    margin: 0;
    accent-color: var(--accent);
}

button {
    min-height: 44px;
    min-width: 44px;
    max-width: 100%;
    padding: 6px 12px;
    border: 1px solid transparent;
    border-radius: 6px;
    background: var(--accent);
    color: var(--accent-text);
    font-weight: 600;
    cursor: pointer;
    touch-action: manipulation;
    overflow-wrap: anywhere;
}

button.quiet,
a.button {
    border-color: var(--line);
    background: var(--panel);
    color: var(--text);
    font-weight: 500;
}

a.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    max-width: 100%;
    padding: 6px 12px;
    border: 1px solid var(--line);
    border-radius: 6px;
    text-decoration: none;
}

button.small {
    padding: 6px 10px;
    font-size: 13px;
}

button:disabled {
    opacity: 0.5;
    cursor: default;
}

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

a {
    color: var(--accent);
}

.top {
    flex: none;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 16px;
    padding: calc(8px + env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) 8px max(16px, env(safe-area-inset-left, 0px));
    border-bottom: 1px solid var(--line);
    background: var(--panel);
}

.top h1 {
    margin: 0;
    font-size: 16px;
}

.brand {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    gap: 0 12px;
    flex: 1 1 260px;
    min-width: 0;
}

.header-tools {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.mobile-only {
    display: none;
}

.connection {
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    color: var(--muted);
}

.connection::before {
    content: "";
    display: inline-block;
    width: 8px;
    height: 8px;
    margin-right: 6px;
    border-radius: 50%;
    background: var(--grey);
}

.connection.ok::before {
    background: var(--green);
}

.connection.bad::before {
    background: var(--red);
}

.poll-status {
    grid-column: 2;
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    color: var(--muted);
    font-size: 12px;
}

.top form {
    margin: 0;
}

body.login-page {
    min-height: 100vh;
    min-height: 100dvh;
    height: auto;
    display: grid;
    place-items: center;
    overflow: auto;
    padding: max(24px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) max(24px, env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
}

.login-card {
    display: block;
    width: min(440px, 100%);
    padding: 28px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--panel);
    box-shadow: 0 8px 28px rgb(0 0 0 / 0.12);
    overflow-wrap: anywhere;
}

.login-card h1 {
    margin: 0 0 12px;
    font-size: 24px;
}

.login-card form {
    display: grid;
    gap: 12px;
    margin-top: 20px;
}

.login-card label {
    display: grid;
    gap: 4px;
}

.login-error {
    padding: 10px 12px;
    border-left: 3px solid var(--danger);
    border-radius: 4px;
    background: var(--warn-bg);
    color: var(--danger);
}

.account-form {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    min-width: 0;
}

.account-name {
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--muted);
    font-size: 12px;
}

.account-form button {
    border-color: var(--line);
    background: var(--panel);
    color: var(--text);
    font-weight: 500;
}

#banner {
    flex: none;
    min-width: 0;
    max-height: 30vh;
    max-height: 30dvh;
    overflow-y: auto;
    overflow-wrap: anywhere;
}

.notice {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 16px;
    border-bottom: 1px solid var(--line);
    background: var(--warn-bg);
    color: var(--warn-text);
}

.notice p {
    flex: 1;
    min-width: 0;
    margin: 0;
}

.workspace {
    flex: 1;
    display: grid;
    grid-template-columns: minmax(288px, 360px) minmax(0, 1fr);
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    padding-left: env(safe-area-inset-left, 0px);
    padding-right: env(safe-area-inset-right, 0px);
}

.list-pane {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    border-right: 1px solid var(--line);
    background: var(--panel);
}

.tabs {
    flex: none;
    display: flex;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    border-bottom: 1px solid var(--line);
}

.tabs button {
    flex: 1 0 auto;
    padding: 10px 6px;
    border: 0;
    border-bottom: 2px solid transparent;
    border-radius: 0;
    background: none;
    color: var(--muted);
    font-weight: 500;
    white-space: nowrap;
}

.tabs button[aria-pressed="true"] {
    border-bottom-color: var(--accent);
    color: var(--text);
    font-weight: 600;
}

.count {
    margin-left: 4px;
    padding: 0 6px;
    border-radius: 9px;
    background: var(--raised);
    font-size: 12px;
}

.filters {
    flex: 0 1 auto;
    min-height: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 10px 8px;
    padding: 8px;
    border-bottom: 1px solid var(--line);
    max-height: 50vh;
    max-height: 50dvh;
    overflow-y: auto;
    overscroll-behavior-y: contain;
}

.searchbar {
    flex: none;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px;
    border-bottom: 1px solid var(--line);
}

.searchbar input {
    flex: 1;
    width: 0;
}

.searchbar button {
    flex: none;
}

.filters .field {
    margin: 0;
    min-width: 0;
}

.filters > button {
    grid-column: 1 / -1;
}

.sort-filter {
    grid-column: 1 / -1;
}

.list {
    flex: 1;
    min-height: 0;
    min-width: 0;
    margin: 0;
    padding: 0;
    overflow-y: auto;
    overscroll-behavior-y: contain;
    -webkit-overflow-scrolling: touch;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    list-style: none;
}

.list .empty {
    padding: 24px 16px;
    color: var(--muted);
    text-align: center;
}

.row {
    display: block;
    width: 100%;
    padding: 10px 12px;
    border: 0;
    border-bottom: 1px solid var(--line);
    border-left: 3px solid transparent;
    border-radius: 0;
    background: none;
    color: var(--text);
    font-weight: 400;
    text-align: left;
}

.row:hover {
    background: var(--raised);
}

.row[aria-current="true"] {
    border-left-color: var(--accent);
    background: var(--raised);
}

.row-head {
    display: flex;
    align-items: baseline;
    gap: 8px;
}

.row-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    font-weight: 600;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.row-sub,
.row-meta {
    overflow: hidden;
    color: var(--muted);
    font-size: 12px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.row-sub {
    font-size: 13px;
}

.dot {
    flex: none;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent);
}

.badge {
    flex: none;
    max-width: 100%;
    padding: 1px 8px;
    border: 1px solid currentColor;
    border-radius: 10px;
    font-size: 12px;
    overflow-wrap: anywhere;
}

.badge.forum {
    border-color: var(--line);
    color: var(--muted);
}

.row-tags {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
    margin: 3px 0;
}

.badge.forum-issue {
    background: var(--issue-bg);
    border-color: var(--issue-line);
    color: var(--issue-text);
}

.badge.forum-suggestion {
    background: var(--suggestion-bg);
    border-color: var(--suggestion-line);
    color: var(--suggestion-text);
}

.tone-0 { color: var(--amber); }
.tone-1 { color: var(--green); }
.tone-2 { color: var(--blue); }
.tone-3 { color: var(--teal); }
.tone-4 { color: var(--red); }
.tone-5 { color: var(--purple); }
.tone-6 { color: var(--grey); }

.detail {
    min-height: 0;
    min-width: 0;
    padding: 20px 24px max(40px, env(safe-area-inset-bottom, 0px));
    overflow-y: auto;
    overscroll-behavior-y: contain;
    -webkit-overflow-scrolling: touch;
    overflow-wrap: anywhere;
}

.detail-nav {
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
}

.detail-jumps {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.detail-jumps button {
    min-height: 44px;
    padding: 6px 10px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--panel);
    color: var(--text);
}

.detail [id] {
    scroll-margin-top: 16px;
}

.detail > .empty {
    margin-top: 80px;
    color: var(--muted);
    text-align: center;
}

.detail h2 {
    margin: 0 0 6px;
    font-size: 20px;
    overflow-wrap: anywhere;
}

.detail h3 {
    margin: 0 0 8px;
    font-size: 13px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--muted);
}

.kennung {
    margin-bottom: 2px;
    color: var(--accent);
    font-weight: 600;
}

.meta-line {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    color: var(--muted);
}

.actions-line {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 12px 0 16px;
}

.actions-line > * {
    min-width: 0;
}

.block {
    min-width: 0;
    margin-bottom: 16px;
    padding: 14px 16px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
}

.notice.block {
    border-color: transparent;
    background: var(--warn-bg);
}

.text {
    overflow-wrap: anywhere;
    white-space: pre-wrap;
}

.muted {
    color: var(--muted);
}

.attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}

.attachments a {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    min-width: 0;
    max-width: 100%;
    overflow-wrap: anywhere;
}

.attachments img {
    display: block;
    max-width: min(220px, 100%);
    max-height: 160px;
    border: 1px solid var(--line);
    border-radius: 6px;
}

.reply {
    min-width: 0;
    padding: 8px 10px;
    border-radius: 6px;
}

.reply + .reply {
    margin-top: 6px;
}

.reply.own {
    background: var(--own-bg);
}

.reply-head {
    overflow-wrap: anywhere;
    margin-bottom: 2px;
    font-size: 12px;
    color: var(--muted);
}

.reply-head strong {
    color: var(--text);
}

.cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr));
    gap: 16px;
    margin-bottom: 16px;
}

.cards .block {
    margin: 0;
}

.field {
    display: block;
    margin-bottom: 8px;
    min-width: 0;
}

.field > span {
    display: block;
    margin-bottom: 2px;
    font-size: 12px;
    color: var(--muted);
}

.check {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 44px;
    margin-bottom: 6px;
}

.preview {
    margin: 0 0 8px;
    padding: 6px 8px;
    border-left: 3px solid var(--line);
    font-size: 13px;
    color: var(--muted);
    overflow-wrap: anywhere;
    white-space: pre-wrap;
}

.link-list,
.history,
.results {
    margin: 0 0 8px;
    padding: 0;
    list-style: none;
}

.link-list li,
.results li {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    min-width: 0;
    padding: 4px 0;
}

.link-list .grow,
.results .grow {
    flex: 1 1 140px;
    min-width: 0;
    overflow: hidden;
    overflow-wrap: anywhere;
}

.linklike {
    padding: 4px 0;
    border: 0;
    background: none;
    color: var(--accent);
    font-weight: 500;
    text-align: left;
}

.history li {
    padding: 4px 0;
    border-top: 1px solid var(--line);
}

.history li:first-child {
    border-top: 0;
}

.history time {
    margin-right: 8px;
    font-size: 12px;
    color: var(--muted);
}

.toasts {
    position: fixed;
    right: max(16px, env(safe-area-inset-right, 0px));
    bottom: max(16px, env(safe-area-inset-bottom, 0px));
    z-index: 10;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: min(420px, calc(100vw - 32px));
    max-height: 40vh;
    max-height: 40dvh;
    overflow-y: auto;
    overflow-wrap: anywhere;
}

.toast {
    padding: 10px 14px;
    border: 1px solid var(--line);
    border-left: 4px solid var(--green);
    border-radius: 6px;
    background: var(--panel);
    box-shadow: 0 4px 16px rgb(0 0 0 / 0.2);
}

.toast.error {
    border-left-color: var(--red);
}

.toast.warn {
    border-left-color: var(--amber);
}

.due-label {
    color: var(--amber);
    font-weight: 600;
}

.duplicate-suggestions {
    margin-top: 14px;
    padding-top: 10px;
    border-top: 1px solid var(--line);
}

.duplicate-suggestions h4,
.duplicate-suggestions p {
    margin: 0 0 8px;
}

.duplicate-suggestions .results li {
    flex-wrap: wrap;
}

.modal {
    width: min(680px, calc(100% - 32px));
    min-width: 0;
    max-height: calc(100vh - 48px);
    max-height: calc(100dvh - max(24px, env(safe-area-inset-top, 0px)) - max(24px, env(safe-area-inset-bottom, 0px)));
    padding: 20px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--panel);
    color: var(--text);
    box-shadow: 0 10px 40px rgb(0 0 0 / 0.25);
    overflow-y: auto;
    overscroll-behavior-y: contain;
    overflow-wrap: anywhere;
}

.modal::backdrop {
    background: rgb(0 0 0 / 0.4);
}

.modal-head {
    position: sticky;
    top: -20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin: -20px -20px 0;
    padding: 16px 20px;
    border-bottom: 1px solid var(--line);
    background: var(--panel);
    z-index: 1;
}

.modal h2 {
    margin: 0;
    font-size: 20px;
    min-width: 0;
}

.modal-body {
    margin-top: 16px;
    min-width: 0;
}

.release-notes {
    min-height: 250px;
    margin-bottom: 12px;
}

.backup-list {
    list-style: none;
    padding: 0;
    margin: 16px 0 0;
}

.backup-list li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    padding: 12px 0;
    border-top: 1px solid var(--line);
}

.backup-list .grow {
    flex: 1 1 180px;
    min-width: 0;
}

@media (max-width: 760px), (max-height: 480px) and (max-width: 1024px) {
    .top {
        gap: 6px 8px;
        padding: calc(6px + env(safe-area-inset-top, 0px)) max(12px, env(safe-area-inset-right, 0px)) 6px max(12px, env(safe-area-inset-left, 0px));
    }

    .brand {
        flex: 1 1 0;
        grid-template-columns: minmax(0, 1fr);
        gap: 0;
    }

    .connection,
    .poll-status {
        grid-column: 1;
        font-size: 12px;
    }

    .top h1 {
        font-size: 15px;
    }

    .mobile-only {
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    body:not(.tools-open) .header-tools {
        display: none;
    }

    .header-tools {
        flex: 1 1 100%;
        display: grid;
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
        gap: 8px;
        max-height: 45vh;
        max-height: 45dvh;
        overflow-y: auto;
        padding-top: 6px;
    }

    #sync,
    .header-tools .account-form {
        grid-column: 1 / -1;
    }

    .account-form {
        justify-content: space-between;
    }

    .account-name {
        flex: 1;
        max-width: none;
        min-width: 0;
    }

    .notice {
        flex-wrap: wrap;
        gap: 8px;
        padding: 8px 12px;
    }

    .notice p {
        flex-basis: 180px;
    }

    .workspace {
        display: flex;
        flex-direction: column;
    }

    .list-pane {
        flex: 1;
        border-right: 0;
    }

    body.detail-open .list-pane,
    body:not(.detail-open) .detail {
        display: none;
    }

    .tabs button {
        padding: 9px 10px;
    }

    .row {
        padding: 12px;
    }

    .row-name,
    .row-sub {
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
        white-space: normal;
        overflow-wrap: anywhere;
    }

    .detail {
        flex: 1;
        padding: 0 12px max(24px, env(safe-area-inset-bottom, 0px));
    }

    .detail-nav {
        position: sticky;
        top: 0;
        z-index: 2;
        display: flex;
        align-items: stretch;
        justify-content: flex-start;
        margin: 0 -12px 12px;
        padding: 8px 12px;
        border-bottom: 1px solid var(--line);
        background: var(--panel);
    }

    .detail-jumps {
        flex: 1 1 100%;
        display: flex;
        gap: 6px;
        justify-content: flex-start;
    }

    .detail-jumps button {
        flex: 1;
    }

    .detail [id] {
        scroll-margin-top: 128px;
    }

    .detail h2 {
        font-size: 19px;
    }

    .block {
        padding: 12px;
        margin-bottom: 12px;
    }

    .cards {
        grid-template-columns: minmax(0, 1fr);
        gap: 12px;
    }

    .reply {
        padding: 8px 4px;
    }

    .reply.own {
        padding: 8px;
    }

    .actions-line > * {
        flex: 1 1 140px;
    }

    .modal {
        width: calc(100% - 24px);
        padding: 16px;
    }

    .modal-head {
        top: -16px;
        margin: -16px -16px 0;
        padding: 12px 16px;
        gap: 8px;
    }

    .modal h2 {
        font-size: 18px;
    }

    .modal-head button {
        flex: none;
    }

    .release-notes {
        min-height: 180px;
    }

    .login-card {
        padding: 20px;
    }
}

@media (max-width: 1024px) and (max-height: 480px) {
    .brand {
        grid-template-columns: auto minmax(0, 1fr);
        column-gap: 8px;
    }

    .connection,
    .poll-status {
        grid-column: 2;
    }

    .filters {
        max-height: 45vh;
        max-height: 45dvh;
    }

    .detail-jumps {
        flex: 1;
    }

    .detail [id] {
        scroll-margin-top: 76px;
    }
}

@media (max-width: 380px) {
    .tabs button {
        flex: 1 1 0;
        min-width: 0;
        white-space: normal;
        padding: 8px 4px;
        font-size: 13px;
    }

    .tabs .count {
        margin-left: 2px;
        padding: 0 4px;
    }
}

.login-card label.remember {
    display: flex;
    align-items: center;
    gap: 8px;
}
