:root,
:root[data-theme-family="standard"][data-theme-mode="light"] {
    color-scheme: light;
    --bg: #f5f7fa;
    --panel: #ffffff;
    --card: #ffffff;
    --text: #18212f;
    --muted: #667085;
    --line: #d9e0e8;
    --accent: #1769aa;
    --accent-strong: #0f4f82;
    --good: #0d7a4f;
    --warn: #a85316;
    --badge: #eef3f7;
}

@media (prefers-color-scheme: dark) {
    :root[data-theme-family="standard"][data-theme-mode="system"] {
        color-scheme: dark;
        --bg: #11151b;
        --panel: #171d25;
        --card: #1d2530;
        --text: #edf2f7;
        --muted: #a8b3c2;
        --line: #303b49;
        --accent: #6cb6ff;
        --accent-strong: #9dccff;
        --badge: #243141;
    }
}

:root[data-theme-family="standard"][data-theme-mode="dark"] {
    color-scheme: dark;
    --bg: #11151b;
    --panel: #171d25;
    --card: #1d2530;
    --text: #edf2f7;
    --muted: #a8b3c2;
    --line: #303b49;
    --accent: #6cb6ff;
    --accent-strong: #9dccff;
    --badge: #243141;
}

:root[data-theme-family="field"][data-theme-mode="light"] {
    color-scheme: light;
    --bg: #f3f6f1;
    --panel: #ffffff;
    --card: #fbfcf9;
    --text: #1d271f;
    --muted: #62705f;
    --line: #d6dfd1;
    --accent: #2d6f5b;
    --accent-strong: #184b3d;
    --badge: #edf4ea;
}

@media (prefers-color-scheme: dark) {
    :root[data-theme-family="field"][data-theme-mode="system"] {
        color-scheme: dark;
        --bg: #101711;
        --panel: #172018;
        --card: #1d291f;
        --text: #edf5ea;
        --muted: #adbea8;
        --line: #31402e;
        --accent: #8ccf9d;
        --accent-strong: #b7e4c1;
        --badge: #263426;
    }
}

:root[data-theme-family="field"][data-theme-mode="dark"] {
    color-scheme: dark;
    --bg: #101711;
    --panel: #172018;
    --card: #1d291f;
    --text: #edf5ea;
    --muted: #adbea8;
    --line: #31402e;
    --accent: #8ccf9d;
    --accent-strong: #b7e4c1;
    --badge: #263426;
}

:root[data-theme-family="terminal"][data-theme-mode="light"] {
    color-scheme: light;
    --bg: #f8f8f2;
    --panel: #ffffff;
    --card: #fbfbf5;
    --text: #202020;
    --muted: #5d6359;
    --line: #d8dacd;
    --accent: #405f7d;
    --accent-strong: #253b54;
    --badge: #efefe6;
}

@media (prefers-color-scheme: dark) {
    :root[data-theme-family="terminal"][data-theme-mode="system"] {
        color-scheme: dark;
        --bg: #090b0a;
        --panel: #101412;
        --card: #151b18;
        --text: #d8f3dc;
        --muted: #91a99b;
        --line: #27332d;
        --accent: #73d17c;
        --accent-strong: #a2f5a8;
        --badge: #1d2a22;
    }
}

:root[data-theme-family="terminal"][data-theme-mode="dark"] {
    color-scheme: dark;
    --bg: #090b0a;
    --panel: #101412;
    --card: #151b18;
    --text: #d8f3dc;
    --muted: #91a99b;
    --line: #27332d;
    --accent: #73d17c;
    --accent-strong: #a2f5a8;
    --badge: #1d2a22;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: Arial, Helvetica, sans-serif;
    line-height: 1.45;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 6px;
    padding: 6px 8px;
    border-bottom: 1px solid var(--line);
    background: color-mix(in srgb, var(--panel) 94%, transparent);
}

.topbar h1,
.panel h2,
.compact-form h3,
.table-shell summary span:first-child {
    margin: 0;
    letter-spacing: 0;
}

.topbar h1 {
    flex: 0 0 auto;
    font-size: 17px;
    line-height: 1.1;
}

.panel h2 {
    font-size: 19px;
    line-height: 1.2;
}

nav {
    position: relative;
    display: flex;
    align-items: center;
    flex: 1 1 auto;
    justify-content: flex-end;
    gap: 4px;
    min-width: 0;
    overflow-x: auto;
    white-space: nowrap;
}

a,
nav a {
    color: var(--accent);
    text-decoration: none;
    font-weight: 600;
}

nav a {
    padding: 6px 3px;
    font-size: 13px;
}

.history-log-link {
    display: none;
}

body[data-view="history"] .history-log-link {
    display: inline;
}

body[data-view="history"] [data-view-history] {
    display: none;
}

body[data-view="history"] .timer-panel,
body[data-view="history"] .entry-panel {
    display: none;
}

body[data-view="log"] #recent {
    display: none;
}

body[data-view="history"] #recent {
    display: block;
}

main {
    width: 100%;
    margin: 8px auto 32px;
    padding: 0 8px;
}

.panel {
    margin-bottom: 10px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
}

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

.badge {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    padding: 3px 9px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--badge);
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}

.notice {
    margin-bottom: 16px;
    padding: 10px 12px;
    border: 1px solid color-mix(in srgb, var(--good) 45%, var(--line));
    border-radius: 8px;
    background: color-mix(in srgb, var(--good) 10%, var(--panel));
    transition: opacity 0.45s ease, transform 0.45s ease, margin 0.45s ease;
}

.notice.is-dismissing {
    margin-bottom: 0;
    opacity: 0;
    transform: translateY(-4px);
}

.notice-error {
    border-color: color-mix(in srgb, var(--warn) 50%, var(--line));
    background: color-mix(in srgb, var(--warn) 10%, var(--panel));
}

.entry-form,
.admin-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
}

.login-panel {
    max-width: 440px;
    margin: 12px auto;
}

.login-form button,
.secondary-form {
    grid-column: 1;
}

.secondary-form {
    margin-top: 10px;
}

label,
.compact-form {
    display: flex;
    flex-direction: column;
    gap: 6px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 600;
}

input,
select,
textarea,
button {
    width: 100%;
    min-height: 44px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: var(--card);
    color: var(--text);
    font: inherit;
}

input,
select,
textarea {
    padding: 9px 10px;
}

textarea {
    resize: vertical;
}

button {
    border-color: color-mix(in srgb, var(--accent) 55%, var(--line));
    background: color-mix(in srgb, var(--accent) 12%, var(--card));
    color: var(--accent-strong);
    font-weight: 650;
    cursor: pointer;
}

.theme-menu {
    position: relative;
}

.theme-menu summary {
    display: grid;
    place-items: center;
    width: 32px;
    min-height: 32px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: var(--card);
    color: var(--muted);
    cursor: pointer;
    list-style: none;
}

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

.theme-menu > div {
    position: fixed;
    right: 8px;
    top: 44px;
    z-index: 5;
    display: grid;
    gap: 8px;
    min-width: 180px;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: 0 12px 30px color-mix(in srgb, black 14%, transparent);
}

.section-details > summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-height: 36px;
    cursor: pointer;
    color: var(--text);
    font-weight: 650;
}

.section-details > summary span:first-child {
    font-size: 19px;
    line-height: 1.2;
}

.section-details > summary::-webkit-details-marker {
    display: none;
}

.section-details[open] > summary {
    margin-bottom: 10px;
}

.wide,
.check-row {
    grid-column: 1;
}

.check-row {
    flex-direction: row;
    align-items: center;
    min-height: 44px;
}

.check-row input {
    width: 18px;
    min-height: 18px;
}

.entry-form button {
    grid-column: 1;
    align-self: end;
}

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

.timer-actions > form {
    grid-column: 1;
    grid-row: 1;
}

.custom-timer-start {
    display: grid;
    grid-column: 1 / -1;
    grid-row: 1;
    gap: 8px;
    pointer-events: none;
}

.custom-timer-start summary {
    display: grid;
    place-items: center;
    width: calc((100% - 8px) / 2);
    margin-left: auto;
    min-height: 44px;
    padding: 1px 6px;
    border: 1px solid color-mix(in srgb, var(--accent) 55%, var(--line));
    border-radius: 7px;
    background: color-mix(in srgb, var(--accent) 12%, var(--card));
    color: var(--accent-strong);
    cursor: pointer;
    font-weight: 650;
    list-style: none;
    pointer-events: auto;
}

.custom-timer-start summary::-webkit-details-marker {
    display: none;
}

.custom-timer-start form {
    display: grid;
    gap: 8px;
    margin-top: 8px;
    pointer-events: auto;
}

.active-timer {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
}

.active-timer > div {
    display: grid;
    gap: 2px;
}

.active-timer span {
    color: var(--muted);
    font-size: 13px;
    font-weight: 600;
}

.inline-form {
    margin: 0;
}

.inline-form button {
    min-height: 30px;
    padding: 4px 8px;
    font-size: 13px;
}

.duration-edit {
    display: grid;
    grid-template-columns: 104px 54px;
    gap: 6px;
    min-width: 164px;
}

.duration-edit select,
.duration-edit button {
    min-height: 32px;
}

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

.admin-data-grid {
    align-items: start;
}

.table-shell {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--card);
    overflow: hidden;
}

.table-shell summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 44px;
    padding: 10px 12px;
    cursor: pointer;
    color: var(--text);
    font-weight: 650;
}

.table-scroll {
    max-height: 360px;
    overflow: auto;
    border-top: 1px solid var(--line);
}

table {
    width: 100%;
    min-width: 520px;
    border-collapse: collapse;
}

th,
td {
    padding: 9px 10px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: top;
}

th {
    position: sticky;
    top: 0;
    background: var(--card);
    color: var(--muted);
    font-size: 13px;
    cursor: pointer;
}

th[data-direction="asc"]::after {
    content: " ^";
}

th[data-direction="desc"]::after {
    content: " v";
}

.recent-list {
    display: grid;
    gap: 10px;
}

.entry-card {
    display: grid;
    gap: 8px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--card);
}

.entry-card > div {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.entry-card span,
.empty {
    color: var(--muted);
}

.notes-editor {
    border-top: 1px solid var(--line);
    padding-top: 8px;
}

.notes-editor summary {
    min-height: 34px;
    cursor: pointer;
    color: var(--accent);
    font-weight: 600;
    list-style: none;
}

.notes-editor summary::-webkit-details-marker {
    display: none;
}

.notes-editor form {
    display: grid;
    gap: 10px;
}

.compact-form {
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--card);
}

@media (min-width: 720px) {
    .topbar {
        gap: 12px;
        padding: 10px 16px;
    }

    .topbar h1 {
        font-size: 20px;
    }

    nav {
        gap: 8px;
    }

    nav a {
        padding: 7px 6px;
        font-size: 14px;
    }

    main {
        width: min(1220px, calc(100% - 24px));
        margin-top: 12px;
        padding: 0;
    }

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

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

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

    .admin-data-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .wide,
    .check-row,
    .entry-form button {
        grid-column: span 2;
    }

    .timer-actions {
        grid-template-columns: repeat(2, minmax(0, 220px));
    }

    .custom-timer-start {
        grid-column: 1 / -1;
    }

    .custom-timer-start form {
        grid-template-columns: minmax(0, 220px) minmax(0, 220px);
    }

    .active-timer {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        align-items: end;
    }
}

@media (min-width: 1080px) {
    .entry-form,
    .admin-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }

    .wide,
    .check-row,
    .entry-form button {
        grid-column: span 2;
    }

    .admin-data-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }

    .admin-entries {
        grid-column: span 4;
    }

    .admin-categories,
    .admin-users {
        grid-column: span 2;
    }
}
