html { color-scheme: dark; font-family: Roboto, "Segoe UI", system-ui, sans-serif; }
html[data-theme="light"] { color-scheme: light; }

:root, html[data-theme="dark"] {
    --bg: #121212;
    --panel: #1e1e1e;
    --field: #2a2a2a;
    --line: #2e2e2e;
    --text: #e6e6e6;
    --muted: #9a9a9a;
    --accent: #7986cb;
    --accent-hover: #8e9ad6;
    --on-accent: #10121f;
    --danger: #ef5350;
    --today: #7986cb;
    --selected: #2a2d3e;
    --cell-hover: #181818;
    --outside: #555555;
    --field-line: #777777;
    --hover: rgba(255, 255, 255, 0.08);
    --nav-bg: #232a4d;
    --nav-text: #eef0ff;
    --nav-line: #7986cb;
    --nav-hover: rgba(255, 255, 255, 0.12);
    --shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
    --backdrop: rgba(0, 0, 0, 0.6);
}

html[data-theme="light"] {
    --bg: #f2f3f8;
    --panel: #ffffff;
    --field: #eff0f6;
    --line: #dcdfe9;
    --text: #1d1f2b;
    --muted: #666b80;
    --accent: #4a5bbf;
    --accent-hover: #3d4ca8;
    --on-accent: #ffffff;
    --danger: #c62828;
    --today: #4a5bbf;
    --selected: #e3e6fa;
    --cell-hover: #f7f8fc;
    --outside: #b3b7c6;
    --field-line: #8a8fa3;
    --hover: rgba(0, 0, 0, 0.07);
    --nav-bg: #3f51b5;
    --nav-text: #ffffff;
    --nav-line: #aab4f0;
    --nav-hover: rgba(255, 255, 255, 0.18);
    --shadow: 0 12px 40px rgba(30, 35, 70, 0.25);
    --backdrop: rgba(20, 22, 40, 0.45);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    min-height: 100vh;
}

button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.spacer { flex: 1; }

.topbar {
    display: flex;
    align-items: center;
    gap: 10px;
    height: 60px;
    padding: 0 24px;
    background: var(--nav-bg);
    color: var(--nav-text);
    border-bottom: 3px solid var(--nav-line);
}
.brand { font-size: 19px; font-weight: 600; letter-spacing: 0.02em; }
.nav-button {
    background: none;
    border: 1px solid transparent;
    border-radius: 999px;
    color: inherit;
    padding: 7px 16px;
    font-size: 14px;
}
.nav-button:hover { background: var(--nav-hover); border-color: var(--nav-line); }
.nav-button.round { width: 36px; height: 36px; padding: 0; font-size: 18px; line-height: 1; }

.content {
    max-width: 960px;
    margin: 16px auto;
    padding: 0 12px;
    display: grid;
    gap: 8px;
}
.panel { background: var(--panel); border-radius: 4px; padding: 12px 16px; }

.day-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.day-head h2 { margin: 0; font-size: 16px; font-weight: 500; flex: 1; min-width: 160px; }
.day-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.chip-button {
    background: color-mix(in srgb, var(--chip) 14%, transparent);
    border: 1px solid color-mix(in srgb, var(--chip) 45%, transparent);
    color: color-mix(in srgb, var(--chip) 65%, var(--text));
    border-radius: 3px;
    padding: 4px 10px;
    font-size: 12px;
}
.chip-button:hover { background: color-mix(in srgb, var(--chip) 26%, transparent); }

.day-group { margin-top: 10px; }
.day-group h3 { margin: 0 0 4px; font-size: 11px; font-weight: 400; color: var(--muted); }
.day-item {
    display: flex;
    gap: 12px;
    width: 100%;
    text-align: left;
    background: none;
    border: 0;
    padding: 4px 0;
    font-size: 12px;
    line-height: 1.5;
    color: var(--chip, var(--text));
}
.day-item:hover { background: var(--hover); }
.day-item .mark { width: 16px; text-align: center; flex: none; }
.day-item .away { color: var(--danger); }
.day-item .note { color: var(--muted); }
.empty { color: var(--muted); margin: 10px 0 0; font-size: 12px; }

.month-toolbar { display: flex; align-items: center; gap: 4px; margin-bottom: 8px; }
.month-toolbar h2 { margin: 0 0 0 8px; font-size: 14px; font-weight: 500; }
button.icon {
    width: 28px; height: 28px;
    background: none; border: 0; border-radius: 4px;
    font-size: 18px; line-height: 1;
}
button.icon:hover { background: var(--hover); }

.weekdays, .month-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.weekdays span { text-align: center; color: var(--muted); font-size: 12px; padding: 6px 0; }
.month-grid {
    border-top: 1px solid var(--line);
    border-left: 1px solid var(--line);
    user-select: none;
}

.cell {
    min-height: 84px;
    padding: 4px;
    text-align: left;
    background: var(--bg);
    border: 0;
    border-right: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
    border-radius: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.cell:hover { background: var(--cell-hover); }
.cell.outside .num { color: var(--outside); }
.cell.selected { background: var(--selected); }
.num {
    font-size: 11px;
    width: 18px; height: 18px;
    display: grid; place-items: center;
    border-radius: 50%;
}
.cell.today .num { background: var(--today); color: var(--on-accent); font-weight: 700; }

.entry-chip {
    font-size: 10px;
    padding: 0 4px;
    border-radius: 2px;
    background: var(--chip);
    color: #0d1a18;
    text-shadow: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.absence-label {
    font-size: 10px;
    color: var(--danger);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

dialog {
    background: var(--panel);
    color: var(--text);
    border: 0;
    border-radius: 6px;
    padding: 24px;
    width: min(440px, calc(100vw - 24px));
    box-shadow: var(--shadow);
}
dialog::backdrop { background: var(--backdrop); }
dialog h2 { margin: 0 0 16px; font-size: 22px; font-weight: 400; }
dialog form { display: grid; gap: 12px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

label {
    display: grid;
    gap: 2px;
    background: var(--field);
    border-bottom: 1px solid var(--field-line);
    border-radius: 4px 4px 0 0;
    padding: 8px 12px 4px;
    font-size: 12px;
    color: var(--muted);
}
label:focus-within { border-bottom-color: var(--accent); }
input, select, textarea {
    font: inherit;
    font-size: 15px;
    color: var(--text);
    background: transparent;
    border: 0;
    padding: 2px 0 4px;
    width: 100%;
    resize: vertical;
}
input:focus, select:focus, textarea:focus { outline: none; }
select option { background: var(--panel); }
input[type="color"] { height: 32px; padding: 0; }

fieldset { border: 1px solid var(--line); border-radius: 4px; margin: 0; padding: 6px 12px 10px; }
legend { font-size: 12px; color: var(--muted); padding: 0 4px; }
fieldset label {
    display: flex; align-items: center; gap: 8px;
    background: none; border: 0; padding: 3px 0;
    font-size: 14px; color: var(--text);
}
fieldset input { width: auto; }
fieldset .none { color: var(--muted); font-size: 12px; }

.actions { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.actions button, button.primary {
    background: none; border: 0; border-radius: 4px; padding: 8px 14px;
}
.actions button:hover { background: var(--hover); }
button.primary, .actions button.primary { background: var(--accent); color: var(--on-accent); font-weight: 500; }
button.primary:hover, .actions button.primary:hover { background: var(--accent-hover); }
button.primary:disabled { opacity: 0.6; cursor: wait; }
.actions button.danger { color: var(--danger); padding-left: 0; }
.message { margin: 0; min-height: 1em; color: var(--danger); font-size: 12px; }

.category-list { list-style: none; margin: 0 0 16px; padding: 0; display: grid; gap: 6px; }
.category-list li { display: grid; grid-template-columns: 36px 1fr auto auto; align-items: center; gap: 8px; }
.category-list input[type="color"] { height: 30px; padding: 0; border-radius: 4px; }
.category-list input:not([type="color"]) {
    background: var(--field);
    border-bottom: 1px solid var(--field-line);
    border-radius: 4px 4px 0 0;
    padding: 8px 10px;
}
.category-list button {
    background: none; border: 0; border-radius: 4px; padding: 6px 10px;
}
.category-list button:hover:not(:disabled) { background: var(--hover); }
.category-list button.danger { color: var(--danger); }
.category-list button:disabled { opacity: 0.35; cursor: not-allowed; }
.hint { margin: 0; color: var(--muted); font-size: 12px; }
.hint:empty { display: none; }
input:disabled, select:disabled, textarea:disabled { opacity: 0.75; cursor: default; }

dialog.wide { width: min(760px, calc(100vw - 24px)); }
.expense-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.expense-table th, .expense-table td {
    padding: 6px 8px;
    text-align: left;
    border-bottom: 1px solid var(--line);
}
.expense-table thead th { color: var(--muted); font-size: 12px; font-weight: 400; }
.expense-table tfoot th { font-weight: 500; border-bottom: 0; }
.expense-table .amount { text-align: right; white-space: nowrap; }
.expense-table tbody tr { cursor: pointer; }
.expense-table tbody tr:hover { background: var(--hover); }
.participant { display: grid; grid-template-columns: 1fr auto 110px; align-items: center; gap: 8px; }
.participant .share { text-align: right; color: var(--muted); font-size: 12px; }

.sign-in {
    max-width: 320px;
    margin: 20vh auto 0;
    display: grid;
    gap: 12px;
    padding: 24px;
    background: var(--panel);
    border-radius: 6px;
}
.sign-in h1 { margin: 0 0 8px; font-size: 22px; font-weight: 400; }

@media (max-width: 640px) {
    .cell { min-height: 64px; padding: 2px; }
    .entry-chip { font-size: 9px; }
    .row { grid-template-columns: 1fr; }
}