:root {
    color-scheme: light dark;
    --bg: #f5f5f4;
    --fg: #1c1917;
    --accent: #0d9488;
    --error: #b91c1c;
    --border: #d6d3d1;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
    background: var(--bg);
    color: var(--fg);
}

.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}

.login-box {
    background: white;
    padding: 2rem;
    border-radius: 12px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
    width: min(90vw, 320px);
}

.login-box h1 {
    font-size: 1.25rem;
    margin-top: 0;
    text-align: center;
}

.login-box form {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.login-box input[type="password"] {
    font-size: 1.5rem;
    text-align: center;
    letter-spacing: 0.3em;
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: 8px;
}

.login-box button {
    padding: 0.75rem;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    cursor: pointer;
}

.login-box .error {
    color: var(--error);
    font-size: 0.9rem;
    text-align: center;
}

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem;
    background: white;
    border-bottom: 1px solid var(--border);
}

.app-header h1 {
    font-size: 1.1rem;
    margin: 0;
}

.logout-link {
    color: var(--accent);
    text-decoration: none;
    font-size: 0.9rem;
}

main {
    padding: 1rem;
    max-width: 640px;
    margin: 0 auto;
}

.page-nav {
    display: flex;
    gap: 1rem;
    padding: 0.5rem 1rem;
    background: white;
    border-bottom: 1px solid var(--border);
}

.page-nav a {
    color: var(--fg);
    text-decoration: none;
    font-size: 0.9rem;
    padding: 0.3rem 0;
    border-bottom: 2px solid transparent;
}

.page-nav a.active {
    color: var(--accent);
    font-weight: 600;
    border-bottom-color: var(--accent);
}

.tabs {
    display: flex;
    gap: 0.25rem;
    padding: 0.5rem 1rem 0;
    background: white;
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
}

.tab-btn {
    flex: 1;
    padding: 0.6rem 0.5rem;
    border: none;
    background: transparent;
    color: var(--fg);
    font-size: 0.95rem;
    border-bottom: 3px solid transparent;
    cursor: pointer;
    white-space: nowrap;
}

.tab-btn.active {
    border-bottom-color: var(--accent);
    font-weight: 600;
    color: var(--accent);
}

.entry-form {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    background: white;
    padding: 1rem;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.entry-form[hidden] {
    display: none;
}

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

.entry-form input[type="text"],
.entry-form input[type="datetime-local"],
.entry-form select,
.entry-form textarea {
    padding: 0.6rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
    font-family: inherit;
    width: 100%;
}

.entry-form button[type="submit"] {
    padding: 0.75rem;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    cursor: pointer;
}

.entry-form button[type="submit"]:disabled {
    opacity: 0.6;
    cursor: default;
}

.voice-btn {
    padding: 0.6rem;
    background: #ede9fe;
    color: #6d28d9;
    border: 1px solid #ddd6fe;
    border-radius: 8px;
    font-size: 0.92rem;
    cursor: pointer;
}

.voice-btn:disabled {
    opacity: 0.5;
    cursor: default;
}

.voice-btn.recording {
    background: #fee2e2;
    color: #b91c1c;
    border-color: #fecaca;
}

.voice-status {
    font-size: 0.85rem;
    color: #57534e;
    margin: -0.4rem 0 0;
}

.bristol-fieldset {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.5rem 0.75rem 0.75rem;
}

.bristol-fieldset legend {
    font-weight: 600;
    padding: 0 0.25rem;
}

.bristol-option {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    font-weight: normal;
    font-size: 0.9rem;
    padding: 0.35rem 0;
    cursor: pointer;
}

.bristol-option input {
    margin-top: 0.2rem;
}

.flash {
    padding: 0.75rem 1rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    font-size: 0.9rem;
    white-space: pre-line;
}

.flash-success {
    background: #d1fae5;
    color: #065f46;
}

.flash-error {
    background: #fee2e2;
    color: #991b1b;
}

.empty-state {
    text-align: center;
    color: #78716c;
    padding: 2rem 0;
}

.type-filter {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem 1rem;
    background: white;
    padding: 0.75rem 1rem;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    margin-bottom: 1rem;
    font-size: 0.85rem;
}

.type-filter label {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    cursor: pointer;
}

.day-group {
    margin-bottom: 1rem;
    background: white;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    padding: 0 1rem;
}

.day-group[open] {
    padding-bottom: 1rem;
}

.day-heading {
    font-size: 1rem;
    font-weight: 600;
    color: #57534e;
    padding: 0.9rem 0;
    cursor: pointer;
    list-style: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.day-heading::-webkit-details-marker {
    display: none;
}

.day-heading::after {
    content: '▸';
    color: var(--accent);
    font-size: 0.8rem;
    transition: transform 0.15s ease;
}

.day-group[open] .day-heading::after {
    transform: rotate(90deg);
}

.day-group:not([open]) .day-heading {
    padding-bottom: 0.9rem;
}

.day-group[open] .day-heading {
    border-bottom: 1px solid var(--border);
    margin-bottom: 0.75rem;
}

.entry-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.entry-item {
    background: white;
    padding: 0.6rem 0.75rem;
    border-radius: 8px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
    border-left: 4px solid var(--border);
}

.entry-view {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
}

.entry-item .entry-body {
    flex: 1;
}

.entry-item[hidden] {
    display: none;
}

.entry-edit[hidden] {
    display: none;
}

.edit-entry-btn {
    border: none;
    background: transparent;
    color: #a8a29e;
    font-size: 0.95rem;
    line-height: 1;
    padding: 0.25rem;
    cursor: pointer;
    border-radius: 6px;
    flex-shrink: 0;
}

.edit-entry-btn:hover {
    color: var(--accent);
    background: #ccfbf1;
}

.inline-edit-form {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    padding-top: 0.75rem;
    margin-top: 0.6rem;
    border-top: 1px solid var(--border);
}

.inline-edit-form label {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    font-size: 0.82rem;
    font-weight: 600;
    color: #57534e;
}

.inline-edit-form input[type="text"],
.inline-edit-form input[type="datetime-local"],
.inline-edit-form select,
.inline-edit-form textarea {
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.9rem;
    font-family: inherit;
    font-weight: normal;
}

.inline-edit-form .bristol-fieldset {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.4rem 0.6rem 0.6rem;
    margin: 0;
}

.inline-edit-actions {
    display: flex;
    gap: 0.5rem;
}

.save-edit-btn {
    padding: 0.5rem 1rem;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 0.88rem;
    cursor: pointer;
}

.cancel-edit-btn {
    padding: 0.5rem 1rem;
    background: transparent;
    color: #78716c;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.88rem;
    cursor: pointer;
}

.delete-entry-btn {
    border: none;
    background: transparent;
    color: #a8a29e;
    font-size: 1rem;
    line-height: 1;
    padding: 0.25rem;
    cursor: pointer;
    border-radius: 6px;
    flex-shrink: 0;
}

.delete-entry-btn:hover {
    color: var(--error);
    background: #fee2e2;
}

.delete-entry-btn:disabled {
    opacity: 0.5;
    cursor: default;
}

.entry-item--stuhlgang {
    border-left-color: #b45309;
}

.entry-item--essen {
    border-left-color: #16a34a;
}

.entry-item--getraenk {
    border-left-color: #2563eb;
}

.entry-item--notiz {
    border-left-color: #7c3aed;
}

.entry-time {
    font-variant-numeric: tabular-nums;
    color: #57534e;
    font-size: 0.9rem;
    min-width: 3rem;
}

.entry-body {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    font-size: 0.92rem;
}

.entry-type-label {
    font-weight: 600;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: #78716c;
}

.entry-tag {
    color: #78716c;
    font-size: 0.85rem;
}

.entry-note {
    color: #57534e;
    font-size: 0.88rem;
    font-style: italic;
}

.ai-summary-label {
    display: block;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #7c3aed;
    margin-bottom: 0.15rem;
}

.ai-summary-text {
    font-size: 0.92rem;
    color: var(--fg);
}

.original-note {
    margin-top: 0.5rem;
}

.original-note summary {
    font-size: 0.78rem;
    color: #78716c;
    cursor: pointer;
    user-select: none;
}

.original-note summary:hover {
    color: var(--accent);
}

.original-note-text {
    margin-top: 0.35rem;
    font-size: 0.85rem;
    color: #57534e;
    font-style: italic;
}

.range-select {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.range-select a {
    flex: 1;
    text-align: center;
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    text-decoration: none;
    color: var(--fg);
    font-size: 0.85rem;
    background: white;
}

.range-select a.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.stat-summary {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.summary-box {
    flex: 1;
    background: white;
    border-radius: 12px;
    padding: 1rem;
    text-align: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.summary-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--accent);
}

.summary-label {
    font-size: 0.8rem;
    color: #78716c;
}

.stat-chart {
    background: white;
    border-radius: 12px;
    padding: 1rem;
    margin-bottom: 1.5rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.stat-chart h2 {
    font-size: 0.95rem;
    margin: 0 0 1rem;
}

.chart-bars {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    height: 160px;
}

.chart-bars--daily {
    overflow-x: auto;
    justify-content: flex-start;
}

.chart-bar-col {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    height: 100%;
    min-width: 2rem;
}

.chart-bar-col--daily {
    min-width: 1.75rem;
    flex: 0 0 auto;
}

.bar-value {
    font-size: 0.75rem;
    color: #57534e;
    min-height: 1em;
}

.bar-track {
    flex: 1;
    width: 100%;
    display: flex;
    align-items: flex-end;
    justify-content: center;
}

.bar {
    width: 60%;
    border-radius: 4px 4px 0 0;
    min-height: 2px;
    transition: height 0.2s ease;
}

.bar-bristol {
    background: #b45309;
    width: 80%;
}

.bar-normal {
    background: #16a34a;
    width: 50%;
}

.bar-draengend {
    background: #d97706;
    width: 50%;
}

.bar-notfall {
    background: #dc2626;
    width: 50%;
}

.bar-daily {
    background: var(--accent);
    width: 70%;
}

.bar-label {
    font-size: 0.72rem;
    color: #78716c;
    margin-top: 0.35rem;
    text-align: center;
}

.bar-label--daily {
    writing-mode: vertical-rl;
    transform: rotate(180deg);
    white-space: nowrap;
}
