/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root, [data-theme="dark"] {
    --bg: #505d73;
    --surface: #47536a;
    --surface2: #5c6d88;
    --accent: #e94560;
    --accent2: #7055c0;
    --text: #e0e0ec;
    --text-muted: #a0a8bc;
    --border: #657080;
    --success: #4caf50;
    --radius: 6px;
    /* BP chart series — lighter steps for the mid-tone dark surface */
    --bp-sys: #ff7a6e;
    --bp-dia: #5cb3ff;
}
[data-theme="light"] {
    --bg: #f5f5f7;
    --surface: #ffffff;
    --surface2: #e8e8f0;
    --accent: #e94560;
    --accent2: #533483;
    --text: #1a1a2e;
    --text-muted: #666;
    --border: #d0d0e0;
    --success: #4caf50;
    --radius: 6px;
    --bp-sys: #e53935;
    --bp-dia: #1e88e5;
}
body { font-family: 'Segoe UI', system-ui, sans-serif; background: var(--bg); color: var(--text); min-height: 100vh; }

/* ===== Login ===== */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-box { background: var(--surface); padding: 2rem; border-radius: var(--radius); width: 320px; }
.login-box h1 { margin-bottom: 1.5rem; color: var(--accent); }
.login-box input { width: 100%; padding: .6rem .8rem; margin-bottom: .8rem;
    background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius);
    color: var(--text); font-size: .95rem; }
.remember-label { display: flex; align-items: center; gap: .5rem; margin-bottom: .8rem;
    font-size: .9rem; color: var(--text-muted); cursor: pointer; }
.remember-label input[type=checkbox] { width: auto; margin: 0; accent-color: var(--accent); }
.login-box button { width: 100%; padding: .7rem; background: var(--accent);
    border: none; border-radius: var(--radius); color: #fff; cursor: pointer; font-size: 1rem; }
.error { color: var(--accent); margin-bottom: 1rem; font-size: .9rem; }

/* ===== App Shell ===== */
#app { display: flex; flex-direction: column; height: 100vh; }
.topbar { background: var(--surface); padding: .6rem 1rem; display: flex;
    align-items: center; justify-content: space-between; gap: .75rem;
    flex-wrap: wrap; border-bottom: 1px solid var(--border); }
.topbar h1 { font-size: 1.1rem; color: var(--accent); flex: none; }
.topbar .view-title { display: none; }
/* Desktop: links and tools are laid out as direct children of the top bar */
.topbar .mainnav { display: contents; }
.nav-links { display: flex; align-items: center; flex-wrap: wrap; gap: .15rem;
    flex: 1 1 0; min-width: 0; order: 1; }
.topbar .search-input { order: 2; }
.nav-tools { order: 3; }
@media (min-width: 641px) and (max-width: 1000px) {
    .topbar h1 { flex: 1; }
    .nav-links { flex-basis: 100%; order: 4; }
}
.nav-links a { color: var(--text-muted); text-decoration: none; font-size: .9rem;
    padding: .35rem .7rem; border-radius: 999px; transition: background .15s, color .15s; }
.nav-links a:hover { color: var(--text); background: var(--bg); }
.nav-links a.active { color: var(--text); background: var(--surface2); font-weight: 600; }
.nav-links .nav-ico { display: none; }
.nav-ico { width: 1.25rem; height: 1.25rem; flex: none; fill: none; stroke: currentColor;
    stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.nav-tools { display: flex; align-items: center; gap: .15rem; padding-left: .6rem;
    border-left: 1px solid var(--border); }
.nav-tool { display: inline-flex; align-items: center; justify-content: center;
    width: 2.25rem; height: 2.25rem; border-radius: 50%; border: none; background: none;
    color: var(--text-muted); cursor: pointer; text-decoration: none; font: inherit;
    transition: background .15s, color .15s; }
.nav-tool:hover { color: var(--text); background: var(--bg); }
.nav-tool.active { color: #fff; background: var(--accent2); }
.nav-tool-logout:hover { color: var(--accent); }
.nav-tool span { display: none; }
[data-theme="light"] .ico-sun, :root:not([data-theme="light"]) .ico-moon { display: none; }
.nav-links a:focus-visible, .nav-tool:focus-visible, .tabbar > :focus-visible {
    outline: 2px solid var(--accent2); outline-offset: 2px; }
.tabbar, .nav-backdrop { display: none; }
.search-input { padding: .35rem .7rem; background: var(--bg); border: 1px solid var(--border);
    border-radius: var(--radius); color: var(--text); font-size: .9rem;
    width: 200px; min-width: 7rem; flex: 0 1 auto;
    transition: border-color .15s, width .2s; }
.search-input:focus { outline: none; border-color: var(--accent2); width: 300px; }
.search-input::placeholder { color: var(--text-muted); }

/* ===== Main View ===== */
#view-main { gap: 1px; background: var(--border); overflow: hidden; }
.col { background: var(--bg); overflow-y: auto; padding: 1rem; flex: 1; transition: opacity .2s; }
.col-left { flex: 1.2; }
.col-right { flex: 0.8; }
#view-main.focus-left  #colRight { opacity: .4; }
#view-main.focus-right #colLeft  { opacity: .4; }

/* ===== Day Section ===== */
.day-section { margin-bottom: 1.2rem; }
.day-section + .day-section { margin-top: 1.8rem; }
.day-header { font-size: 1.1rem; text-transform: uppercase; letter-spacing: .1em;
    color: var(--text-muted); margin-bottom: .6rem; margin-top: .4rem; padding-bottom: .4rem;
    border-bottom: 2px solid var(--border); display: flex; align-items: center; flex-wrap: wrap; }
.day-header.today  { color: var(--accent);  border-color: var(--accent); }
.day-header.daily  { color: var(--accent2); border-color: var(--accent2); }
.day-header-extras { flex-basis: 100%; display: flex; align-items: center; gap: .6rem;
    margin-top: .5rem; flex-wrap: wrap; }
.day-progress { display: flex; align-items: center; gap: .4rem; margin-left: auto;
    font-size: .75rem; color: var(--text-muted); }
.day-header-extras .day-progress { flex: 1; min-width: 80px; margin-left: 0; }
.day-header-extras .weight-input-wrap,
.day-header-extras .habit-input-wrap { margin-left: 0; }
.day-progress-bar { width: 60px; height: 5px; background: var(--border); border-radius: 3px; overflow: hidden; display: inline-block; }
.day-header-extras .day-progress-bar { flex: 1; width: auto; }
.day-progress-fill { display: block; height: 100%; background: currentColor; border-radius: 3px; transition: width .3s, background .4s; }
.day-progress-fill.complete { background: var(--success); }
.day-header .day-label { font-weight: 700; }
.sort-btn { background: none; border: 1px solid var(--border); border-radius: var(--radius);
    color: var(--text-muted); font-size: .65rem; padding: .1rem .35rem; margin-left: .5rem;
    cursor: pointer; text-transform: none; letter-spacing: 0; line-height: 1.2; }
.sort-btn:hover { color: var(--text); border-color: var(--text-muted); }
.section-chevron { display: inline-block; margin-right: .4rem; font-size: .75rem;
    color: var(--text-muted); transition: transform .2s; }
.section-chevron.closed { transform: rotate(-90deg); }
.section-body.collapsed { display: none; }

/* ===== Drag & Drop ===== */
.task-item, .project-item { cursor: grab; }
.task-item.dragging, .project-item.dragging { opacity: .35; cursor: grabbing; }
body.is-dragging .task-item:not(.dragging),
body.is-dragging .project-item:not(.dragging) { pointer-events: none; }
.task-list.drag-over { outline: 2px dashed var(--accent); border-radius: var(--radius);
    background: rgba(233,69,96,.06); min-height: 2rem; }
.task-item.drop-before, .project-item.drop-before { border-top: 2px solid var(--accent); }
.task-item.drop-after,  .project-item.drop-after  { border-bottom: 2px solid var(--accent); }
.project-item.drop-into-project { outline: 2px solid var(--accent2); box-shadow: 0 0 0 4px rgba(112,85,192,.2); }

/* ===== Star ===== */
.star-btn { background: none; border: none; cursor: pointer; font-size: .95rem;
    color: var(--text-muted); padding: 0 2px; flex-shrink: 0; line-height: 1;
    transition: color .15s, transform .15s; }
.star-btn:hover  { color: #f5a623; transform: scale(1.2); }
.star-btn.starred { color: #f5a623; }
.task-item.starred  { border-color: #f5a62366; box-shadow: inset 3px 0 0 #f5a623; }
.project-item.starred { border-color: #f5a62366; box-shadow: inset 3px 0 0 #f5a623; }

/* ===== Inline Edit ===== */
.task-text, .project-name, .subtask-item > span { cursor: pointer; }
.task-text:hover, .project-name:hover, .subtask-item > span:hover { opacity: .8; }
.inline-edit { background: transparent; border: none; border-bottom: 1px solid var(--accent);
    color: inherit; font-size: inherit; font-family: inherit; outline: none;
    padding: 0; width: 100%; }

/* ===== Tasks ===== */
.task-list { display: flex; flex-direction: column; gap: .3rem; }
.task-item { background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: .5rem .7rem; display: flex;
    flex-wrap: wrap; align-items: flex-start; gap: .5rem; transition: border-color .15s; }
.task-item:hover { border-color: var(--accent2); }
.task-item:focus, .project-item:focus { outline: 2px solid var(--accent2); outline-offset: 1px; }
.task-item.completed, .project-item.completed { opacity: .45; }
.task-item.completed .task-text { text-decoration: line-through; color: var(--text-muted); }
.task-checkbox { width: 16px; height: 16px; flex-shrink: 0; margin-top: 2px;
    accent-color: var(--accent); cursor: pointer; }
.task-text { flex: 1; font-size: .9rem; line-height: 1.4; word-break: break-word; }
.task-text a { color: var(--accent); }
.task-actions { display: flex; gap: .3rem; opacity: 0; transition: opacity .15s; }
.task-item:hover .task-actions { opacity: 1; }
.task-actions button { background: none; border: none; color: var(--text-muted);
    cursor: pointer; font-size: .85rem; padding: 2px 4px; border-radius: 3px; }
.task-actions button:hover { background: var(--border); color: var(--text); }
/* Touch devices have no real :hover, so opacity-on-hover leaves these
   buttons invisible (and effectively untappable) on mobile even though the
   same CSS works fine with a mouse on desktop. Show them permanently and
   size them for a finger instead of a cursor. */
@media (hover: none) {
    .task-actions { opacity: 1; }
    .task-actions button { padding: 8px 9px; font-size: 1rem; }
}

/* ===== Note ===== */
.note-btn { color: var(--text-muted); }
.note-btn.has-note { color: var(--accent2); }
.task-note { flex-basis: 100%; display: none; margin-top: .1rem; }
.task-note.visible { display: block; }
.project-item > .task-note { display: none; padding: .3rem .7rem .4rem 1.5rem;
    border-top: 1px solid var(--border); }
.project-item > .task-note.visible { display: block; }
.task-note textarea { width: 100%; background: var(--surface2); border: 1px solid var(--border);
    border-radius: var(--radius); color: var(--text); font-size: .85rem; font-family: inherit;
    padding: .4rem .6rem; resize: vertical; outline: none; box-sizing: border-box; line-height: 1.4; }
.task-note textarea:focus { border-color: var(--accent2); }

/* ===== Attachments ===== */
.attach-btn { color: var(--text-muted); }
.attach-btn.has-attachment { color: var(--accent); }
.task-attachment { flex-basis: 100%; display: none; margin-top: .4rem; position: relative; }
.task-attachment.visible { display: block; }
.attachment-img { max-width: 100%; max-height: 200px; border-radius: var(--radius);
    cursor: pointer; display: block; }
.attachment-pdf { width: 100%; height: 300px; border: 1px solid var(--border);
    border-radius: var(--radius); display: block; }
.attachment-del { position: absolute; top: .25rem; right: .25rem;
    background: rgba(0,0,0,.5); color: #fff; border: none; border-radius: 50%;
    width: 1.4rem; height: 1.4rem; cursor: pointer; font-size: .75rem;
    display: flex; align-items: center; justify-content: center; }
.attachment-del:hover { background: rgba(0,0,0,.8); }

/* ===== Project ===== */
.project-item { background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); overflow: hidden; margin-bottom: .3rem; }
.project-header { padding: .5rem .7rem; display: flex; align-items: center; gap: .5rem; cursor: pointer; }
.project-header:hover { background: var(--surface2); }
.project-toggle { color: var(--text-muted); font-size: .8rem; transition: transform .2s; flex-shrink: 0; }
.project-toggle.open { transform: rotate(90deg); }
.project-name { flex: 1; font-size: .9rem; font-weight: 500; }
.project-progress-wrap { flex-shrink: 0; display: flex; align-items: center; gap: .4rem; font-size: .8rem; color: var(--text-muted); }
.progress-bar { width: 80px; height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--accent); border-radius: 3px; transition: width .3s, background .4s; }
.progress-fill.complete { background: var(--success); }
.project-subtasks { padding: .3rem .7rem .5rem 1.5rem; border-top: 1px solid var(--border);
    display: flex; flex-direction: column; gap: .25rem; }
.subtask-item { display: flex; align-items: center; flex-wrap: wrap; gap: .5rem; font-size: .85rem; padding: .2rem 0; cursor: grab; }
.subtask-item.dragging { opacity: .4; }
.subtask-item.completed { opacity: .45; }
.subtask-item.completed span { text-decoration: line-through; color: var(--text-muted); }
.subtask-del { margin-left: auto; background: none; border: none; color: var(--text-muted);
    cursor: pointer; font-size: .8rem; padding: 2px 4px; border-radius: 3px; }
.subtask-del:hover { background: var(--border); color: var(--text); }
.task-del { background: none; border: none; color: var(--text-muted);
    cursor: pointer; font-size: .8rem; padding: 2px 4px; border-radius: 3px; }
.task-del:hover { background: var(--border); color: var(--text); }

/* ===== Add Task ===== */
.add-task-form { display: flex; gap: .4rem; margin-bottom: .6rem; }
.add-task-form input { flex: 1; padding: .45rem .7rem; background: var(--surface);
    border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); font-size: .9rem; }
.add-task-form input:focus { outline: none; border-color: var(--accent2); }
.btn { padding: .4rem .8rem; border: none; border-radius: var(--radius); cursor: pointer; font-size: .85rem; }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-secondary { background: var(--surface2); color: var(--text); }
.btn-sm { padding: .25rem .5rem; font-size: .8rem; }

/* ===== Admin View ===== */
#view-admin { padding: 1.5rem; }
#view-admin h2 { margin-bottom: 1rem; color: var(--accent); }
.admin-section { background: var(--surface); border-radius: var(--radius); padding: 1rem; margin-bottom: 1.5rem; }
.admin-section h3 { margin-bottom: .8rem; font-size: .85rem; color: var(--text-muted);
    text-transform: uppercase; letter-spacing: .05em; }
.stats-group-title { font-size: .8rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; margin: 1rem 0 .4rem; }
.stats-group-title:first-child { margin-top: 0; }
.feature-row { display: flex; align-items: center; gap: .5rem; padding: .3rem 0; font-size: .95rem; cursor: pointer; }
.feature-row input[type="checkbox"] { width: auto; margin: 0; }
.feature-row small { margin-left: auto; color: var(--text-muted); font-size: .75rem; }
.feature-row.feature-locked span { color: var(--text-muted); text-decoration: line-through; }
.admin-actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .8rem; }
.stat-card .value { overflow-wrap: anywhere; }
.stat-card .value.small { font-size: 1.15rem; line-height: 1.2; padding-top: .25rem; }
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: .8rem; }
.stat-card { background: var(--bg); padding: .8rem; border-radius: var(--radius); text-align: center; }
.stat-card .value { font-size: 1.6rem; font-weight: 700; color: var(--accent); }
.stat-card .label { font-size: .75rem; color: var(--text-muted); margin-top: .2rem; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: .5rem .7rem; text-align: left; border-bottom: 1px solid var(--border); }
th { color: var(--text-muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; }

/* ===== Views ===== */
.view { display: none; flex: 1; overflow: hidden; flex-direction: column; }
.view.active { display: flex; }
#view-main.active { flex-direction: row; }
#view-admin.active { overflow-y: auto; }

/* ===== Modal ===== */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.6);
    display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal { background: var(--surface); border-radius: var(--radius); padding: 1.5rem; width: 380px; max-width: 95vw; }
.modal h3 { margin-bottom: 1rem; }
.modal input, .modal select { width: 100%; padding: .5rem .7rem; margin-bottom: .8rem;
    background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius);
    color: var(--text); font-size: .9rem; }
.modal-hint { font-size: .85rem; color: var(--text-muted); margin-bottom: .8rem; }
.modal-actions { display: flex; gap: .5rem; justify-content: flex-end; margin-top: 1rem; }
.day-change-list { max-height: 50vh; overflow-y: auto; }
.day-change-item { display: flex; align-items: center; justify-content: space-between; gap: .5rem;
    padding: .4rem 0; border-bottom: 1px solid var(--border); }
.day-change-item:last-child { border-bottom: none; }
.day-change-item .task-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.hidden { display: none !important; }

/* ===== Offline Banner ===== */
.offline-banner { background: #b03030; color: #fff; text-align: center;
    padding: .4rem 1rem; font-size: .85rem; font-weight: 500; }

/* ===== Undo Toast ===== */
.undo-toast { position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%);
    background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius);
    padding: .6rem 1rem; display: flex; align-items: center; gap: .8rem;
    font-size: .9rem; box-shadow: 0 4px 16px rgba(0,0,0,.3); z-index: 999; }
.undo-toast.hidden { display: none; }
.undo-toast button { background: var(--accent); color: #fff; border: none;
    border-radius: var(--radius); padding: .25rem .7rem; cursor: pointer; font-size: .85rem; }
.undo-toast button:hover { opacity: .85; }

/* ===== Empty State ===== */
.empty-state { color: var(--text-muted); font-size: .85rem; padding: .4rem 0; font-style: italic; }

/* ===== Hide-Completed Button ===== */

/* ===== Archive View ===== */
#view-archive { padding: 1.5rem; overflow-y: auto; }
#view-archive h2 { margin-bottom: 1rem; color: var(--accent); }
.archive-item { background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: .5rem .7rem; display: flex;
    align-items: center; gap: .5rem; opacity: .75; }
.archive-item .task-text { flex: 1; font-size: .9rem; }
.archive-meta { font-size: .75rem; color: var(--text-muted); flex-shrink: 0; }
.archive-actions { display: flex; gap: .3rem; flex-shrink: 0; }
.archive-actions button { background: none; border: none; color: var(--text-muted);
    cursor: pointer; font-size: .85rem; padding: 2px 5px; border-radius: 3px; }
.archive-actions button:hover { background: var(--border); color: var(--text); }

/* ===== Mobile ===== */
@media (max-width: 640px) {
    #app { height: auto; min-height: 100dvh; }
    .view { overflow: visible; }
    #view-main.active { flex-direction: column; overflow: visible; }
    .col { overflow-y: visible; flex: none; }
    #view-admin.active, #view-archive.active { overflow-y: visible; }
    #view-main.focus-left  #colRight,
    #view-main.focus-right #colLeft { opacity: 1; }
    .topbar { flex-wrap: wrap; }
    .topbar .brand { display: none; }
    .topbar .view-title { display: inline; }
    .search-input, .search-input:focus { flex: 1; width: auto; min-width: 0; transition: none; }

    /* Navigation: fixed tab bar + "Mehr" sheet that slides up above it */
    :root { --tabbar-h: calc(3.6rem + env(safe-area-inset-bottom, 0px)); }
    #app { padding-bottom: var(--tabbar-h); }
    .undo-toast { bottom: calc(var(--tabbar-h) + .8rem); }
    .tabbar { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
        position: fixed; left: 0; right: 0; bottom: 0; z-index: 90;
        height: var(--tabbar-h); padding-bottom: env(safe-area-inset-bottom, 0px);
        background: var(--surface); border-top: 1px solid var(--border);
        box-shadow: 0 -4px 16px rgba(0,0,0,.18); }
    .tabbar > * { position: relative; display: flex; flex-direction: column; align-items: center;
        justify-content: center; gap: .2rem; min-width: 0; padding: 0 .15rem;
        background: none; border: none; font: inherit; font-size: .68rem; cursor: pointer;
        color: var(--text-muted); text-decoration: none; -webkit-tap-highlight-color: transparent; }
    .tabbar > * span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .tabbar .nav-ico { width: 1.45rem; height: 1.45rem; transition: transform .15s; }
    .tabbar > .active { color: var(--text); font-weight: 600; }
    .tabbar > .active .nav-ico { color: var(--accent); transform: translateY(-1px); }
    .nav-open .tabbar > .active:not(#navMoreBtn) { color: var(--text-muted); font-weight: 400; }
    .nav-open .tabbar > .active:not(#navMoreBtn)::before { display: none; }
    .nav-open .tabbar > .active:not(#navMoreBtn) .nav-ico { color: inherit; }
    .nav-open #navMoreBtn { color: var(--text); }
    .nav-open #navMoreBtn .nav-ico { color: var(--accent); }
    .tabbar > .active::before { content: ''; position: absolute; top: -1px; left: 28%; right: 28%;
        height: 3px; border-radius: 0 0 3px 3px; background: var(--accent); }
    .tabbar > :active .nav-ico { transform: scale(.9); }

    .nav-backdrop { display: block; position: fixed; inset: 0; z-index: 88;
        background: rgba(0,0,0,.5); opacity: 0; visibility: hidden;
        transition: opacity .2s, visibility 0s .2s; }
    .nav-open .nav-backdrop { opacity: 1; visibility: visible; transition: opacity .2s; }
    .nav-open { overflow: hidden; }

    .topbar .mainnav { position: fixed; left: 0; right: 0; bottom: var(--tabbar-h); z-index: 89;
        display: block; max-height: calc(100dvh - var(--tabbar-h) - 3rem); overflow-y: auto;
        padding: .5rem .9rem 1rem; background: var(--surface);
        border-radius: 18px 18px 0 0; box-shadow: 0 -8px 30px rgba(0,0,0,.3);
        transform: translateY(105%); visibility: hidden;
        transition: transform .25s cubic-bezier(.2,.8,.2,1), visibility 0s .25s; }
    .nav-open .topbar .mainnav { transform: none; visibility: visible;
        transition: transform .25s cubic-bezier(.2,.8,.2,1); }
    .mainnav::before { content: ''; display: block; width: 2.5rem; height: 4px; margin: 0 auto .8rem;
        border-radius: 2px; background: var(--border); }
    .nav-links { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .5rem; min-width: 0; }
    .nav-links a, .nav-links a:hover { display: flex; flex-direction: column; align-items: center;
        justify-content: center; gap: .4rem; min-height: 4.6rem; padding: .5rem .25rem;
        border-radius: 12px; background: var(--bg); color: var(--text); font-size: .8rem;
        text-align: center; border: 1px solid transparent; }
    .nav-links .nav-ico { display: block; width: 1.6rem; height: 1.6rem; color: var(--text-muted); }
    .nav-links a.active { background: var(--surface2); border-color: var(--accent); }
    .nav-links a.active .nav-ico { color: var(--accent); }
    .nav-links a:active { transform: scale(.97); }
    .nav-tools { display: grid; grid-template-columns: 1fr 1fr; gap: .25rem .5rem;
        margin-top: .9rem; padding: .7rem 0 0; border-left: none; border-top: 1px solid var(--border); }
    .nav-tool { justify-content: flex-start; gap: .6rem; width: auto; height: auto; min-height: 2.9rem;
        padding: 0 .7rem; border-radius: 10px; font-size: .85rem; color: var(--text); text-align: left; }
    .nav-tool span { display: inline; }
    .nav-tool-logout { color: var(--accent); }
}
@media (max-width: 640px) and (prefers-reduced-motion: reduce) {
    .topbar .mainnav, .nav-backdrop, .tabbar .nav-ico { transition: none !important; }
}

/* ===== Recipes View ===== */
#recipeView { flex: 1; overflow-y: auto; padding: 1.5rem; }
.recipe-url-form { display: flex; gap: .4rem; margin-bottom: 1rem; flex-wrap: wrap; }
.recipe-url-form input { flex: 1; min-width: 200px; padding: .45rem .7rem;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    color: var(--text); font-size: .9rem; }
.recipe-url-form input:focus { outline: none; border-color: var(--accent2); }

.recipe-form { background: var(--surface); border-radius: var(--radius);
    padding: 1rem; margin-bottom: 1.2rem; }
.recipe-form-inner { display: flex; flex-direction: column; gap: .7rem; }
.recipe-form-row { display: grid; grid-template-columns: 1fr 1fr; gap: .7rem; }
.recipe-form-field { display: flex; flex-direction: column; gap: .2rem; }
.recipe-form-field label { font-size: .75rem; color: var(--text-muted);
    font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.recipe-form-field input, .recipe-form-field textarea {
    padding: .4rem .6rem; background: var(--bg); border: 1px solid var(--border);
    border-radius: var(--radius); color: var(--text); font-size: .9rem;
    font-family: inherit; resize: vertical; }
.recipe-form-field input:focus, .recipe-form-field textarea:focus {
    outline: none; border-color: var(--accent2); }
.recipe-form-actions { display: flex; gap: .5rem; justify-content: flex-end; margin-top: .3rem; }

.recipe-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem; margin-bottom: 1rem; }
.recipe-card { background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); overflow: hidden; cursor: pointer;
    transition: border-color .15s, box-shadow .15s; }
.recipe-card:hover { border-color: var(--accent2); box-shadow: 0 2px 8px rgba(0,0,0,.2); }
.recipe-card.selected { border-color: var(--accent); box-shadow: 0 2px 8px rgba(0,0,0,.2); }
.recipe-card-img { width: 100%; height: 140px; object-fit: cover; display: block; }
.recipe-card-img-placeholder { width: 100%; height: 140px; display: flex; align-items: center;
    justify-content: center; background: var(--surface2); font-size: 2.5rem; }
.recipe-card-body { padding: .6rem .8rem; }
.recipe-card-title { font-size: .9rem; font-weight: 600; margin-bottom: .3rem;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recipe-card-link { font-size: .8rem; color: var(--accent); text-decoration: none; display: block; margin-bottom: .2rem; }
.recipe-card-link:hover { text-decoration: underline; }

.recipe-tags { display: flex; flex-wrap: wrap; gap: .25rem; margin-top: .3rem; }
.recipe-tag { font-size: .7rem; background: var(--surface2); border-radius: 3px;
    padding: .1rem .35rem; color: var(--text-muted); }

.recipe-detail { background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 1rem; margin-bottom: 1.2rem; }
.recipe-detail-header { display: flex; align-items: flex-start; gap: 1rem;
    margin-bottom: 1rem; flex-wrap: wrap; }
.recipe-detail-title { font-size: 1.2rem; font-weight: 700; flex: 1; }
.recipe-detail-actions { display: flex; gap: .4rem; flex-wrap: wrap; flex-shrink: 0; }
.recipe-detail-body { display: flex; gap: 1.5rem; align-items: flex-start; }
.recipe-detail-img { width: 200px; height: 150px; object-fit: cover;
    border-radius: var(--radius); flex-shrink: 0; }
.recipe-detail-content { flex: 1; min-width: 0; }
.recipe-detail-content h3 { font-size: .8rem; color: var(--text-muted);
    text-transform: uppercase; letter-spacing: .05em; margin: .8rem 0 .3rem; }
.recipe-detail-desc { font-size: .9rem; color: var(--text-muted); line-height: 1.5; }
.recipe-ingredients { padding-left: 1.2rem; font-size: .9rem; line-height: 1.7; }
.recipe-steps { padding-left: 1.4rem; font-size: .9rem; line-height: 1.7; }
.recipe-steps li, .recipe-ingredients li { margin-bottom: .15rem; }
.recipe-notes-text { font-size: .9rem; background: var(--surface2); border-radius: var(--radius);
    padding: .5rem .7rem; line-height: 1.5; white-space: pre-wrap; }

.recipe-bookmarklet { margin-top: 2rem; padding: .8rem 1rem; background: var(--surface);
    border-radius: var(--radius); border: 1px solid var(--border); font-size: .85rem; color: var(--text-muted); }
.recipe-bookmarklet summary { cursor: pointer; font-weight: 600; color: var(--text);
    user-select: none; }
.recipe-bookmarklet p { margin: .5rem 0; line-height: 1.5; }
.recipe-bookmarklet a { display: inline-block; cursor: grab; margin-top: .3rem; }

@media (max-width: 640px) {
    .recipe-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
    .recipe-form-row { grid-template-columns: 1fr; }
    .recipe-detail-body { flex-direction: column; }
    .recipe-detail-img { width: 100%; height: 200px; }
}

/* ===== Invoices View ===== */
#view-invoices { padding: 1.5rem; flex-direction: column; min-height: 0; }
#view-invoices.active { overflow-y: auto; }
.invoices-subnav { display: flex; gap: .4rem; margin-bottom: 1rem; flex-wrap: wrap; }
.invoices-tab-btn { padding: .4rem .8rem; background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); color: var(--text-muted); cursor: pointer; font-size: .85rem; }
.invoices-tab-btn:hover { color: var(--text); }
.invoices-tab-btn.active { background: var(--accent2); color: #fff; border-color: var(--accent2); }
.invoices-subview { display: none; }
.invoices-subview.active { display: block; }

.invoice-kunde-select { padding: .4rem .7rem; background: var(--surface2); border: 1px solid var(--border);
    border-radius: var(--radius); color: var(--text); font-size: .9rem; margin-bottom: 1rem; }

.invoice-positions { display: flex; flex-direction: column; gap: .6rem; margin-bottom: .8rem; }
.invoice-position-row { display: flex; flex-wrap: wrap; gap: .5rem; align-items: end; background: var(--surface);
    border: 1px solid var(--border); border-radius: var(--radius); padding: .6rem; }
.invoice-field { display: flex; flex-direction: column; gap: .2rem; font-size: .75rem; color: var(--text-muted); }
.invoice-field input { padding: .3rem .5rem; background: var(--surface2); border: 1px solid var(--border);
    border-radius: var(--radius); color: var(--text); font-size: .85rem; }
.invoice-position-sum { font-size: .85rem; font-weight: 600; min-width: 5rem; align-self: center; }
.invoice-position-del { background: none; border: none; color: var(--text-muted); cursor: pointer;
    font-size: .9rem; align-self: center; }
.invoice-position-del:hover { color: var(--text); }

.invoice-total { font-size: 1rem; font-weight: 600; margin-bottom: .8rem; }
.invoice-generate-result { margin-top: .8rem; display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }

.invoice-settings-field { display: flex; flex-direction: column; gap: .2rem; margin-bottom: .7rem; font-size: .85rem; }
.invoice-settings-field input, .invoice-settings-field textarea { padding: .4rem .6rem; background: var(--surface2);
    border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); font-size: .85rem; }
.invoice-settings-status { font-size: .85rem; color: var(--success); }
.invoice-template-upload { margin-top: 1rem; display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }

.invoice-placeholder-ref { margin-top: 1.5rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.invoice-placeholder-ref h4 { font-size: .9rem; margin: 0 0 .6rem; color: var(--text); }
.invoice-placeholder-group { font-size: .8rem; font-weight: 600; color: var(--text-muted);
    margin: .9rem 0 .3rem; text-transform: uppercase; letter-spacing: .05em; }
.invoice-placeholder-ref dl { display: grid; grid-template-columns: max-content 1fr; gap: .25rem .8rem; margin: 0; }
.invoice-placeholder-ref dt { font-size: .8rem; }
.invoice-placeholder-ref dd { margin: 0; font-size: .8rem; color: var(--text-muted); }
.invoice-placeholder-ref code { background: var(--surface2); border: 1px solid var(--border);
    border-radius: 3px; padding: .05rem .35rem; font-size: .78rem; color: var(--accent2); white-space: nowrap; }

/* ===== Places View ===== */
#view-places { overflow: hidden; padding: 0; flex-direction: column; min-height: 0; }
.places-toolbar { display: flex; gap: .6rem; margin-bottom: 1.2rem; flex-wrap: wrap; align-items: center; }
.places-search { flex: 1; min-width: 80px; padding: .3rem .6rem; font-size: .85rem;
    background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); }
.places-search:focus { outline: none; border-color: var(--accent2); }
.places-map-wrap { display: flex; flex-direction: column; height: 100%; }
.places-map-topbar { flex-shrink: 0; padding: 1rem 1.5rem .5rem; }
.places-leaflet-map { flex: 1; min-height: 0; isolation: isolate; }
/* Mobile: the page scrolls, so "rest of the height" is 0 — size the map from the viewport */
@media (max-width: 640px) {
    .places-leaflet-map { flex: none; height: calc(100dvh - 15rem); min-height: 18rem; }
}
.place-marker { width: 14px; height: 14px; border-radius: 50%;
    background: var(--accent2); border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.4); }
.place-marker-starred { background: #f5a623; }
.place-marker-home { width: 16px; height: 16px; border-radius: 50%;
    background: var(--accent); border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.4); }
.places-sort-select { padding: .3rem .6rem; background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); color: var(--text); font-size: .85rem; cursor: pointer; }
.places-sort-select:focus { outline: none; border-color: var(--accent2); }
.places-list { display: flex; flex-direction: column; gap: .75rem; margin-bottom: 1.5rem; }

.place-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: .75rem 1rem; cursor: pointer; transition: border-color .15s; }
.place-card:hover { border-color: var(--accent2); }
.place-card-archived { opacity: .65; cursor: default; }
.place-card-archived:hover { border-color: var(--border); }
.place-card-header { display: flex; align-items: center; gap: .5rem; margin-bottom: .3rem; }
.place-name { font-weight: 600; flex: 1; font-size: .95rem; min-width: 0;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.place-card-actions { display: flex; align-items: center; gap: .4rem; flex-shrink: 0; }
.place-distance { font-size: .78rem; color: var(--text-muted); background: var(--surface2);
    padding: .1rem .45rem; border-radius: 10px; }
.place-card.starred { box-shadow: inset 3px 0 0 #f5a623; border-color: #f5a62366; }
.place-map-btn { background: none; border: none; color: var(--text-muted); cursor: pointer;
    font-size: .85rem; padding: 2px 5px; border-radius: 3px; text-decoration: none; line-height: 1; }
.place-map-btn:hover { background: var(--border); color: var(--text); }
.place-visit-btn { background: none; border: 1px solid var(--success); color: var(--success);
    cursor: pointer; font-size: .8rem; padding: 1px 6px; border-radius: 3px; }
.place-visit-btn:hover { background: var(--success); color: #fff; }
.place-visit-form { display: flex; align-items: center; gap: .5rem; padding: .5rem 0; flex-wrap: wrap; }
.place-visit-form input[type=date] { font-size: .85rem; padding: .25rem .4rem;
    background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius);
    color: var(--text); }
.place-del-btn { background: none; border: none; color: var(--text-muted);
    cursor: pointer; font-size: .85rem; padding: 2px 5px; border-radius: 3px; }
.place-del-btn:hover { background: var(--border); color: var(--text); }
.place-tags { display: flex; flex-wrap: wrap; gap: .3rem; margin-bottom: .3rem; }
.place-tag { font-size: .75rem; padding: .1rem .5rem; border-radius: 10px;
    background: var(--surface2); color: var(--text-muted); cursor: pointer; transition: color .15s; }
.place-tag:hover { color: var(--text); }
.place-tag.active { background: var(--accent2); color: #fff; }
.place-link { font-size: .8rem; color: var(--accent2); text-decoration: none; display: block; margin-top: .3rem; }
.place-link:hover { text-decoration: underline; }
.places-tag-cloud { display: flex; flex-wrap: wrap; gap: .4rem; padding: .6rem 0 1rem; }
.place-location { font-size: .82rem; color: var(--text-muted); margin-bottom: .2rem; }
.place-desc { font-size: .85rem; color: var(--text-muted);
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.place-visited-date { font-size: .8rem; color: var(--text-muted); }

/* Tag chips input */
.tag-input-wrap { display: flex; flex-wrap: wrap; gap: .3rem; padding: .3rem .5rem;
    background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius);
    min-height: 2.1rem; align-items: center; cursor: text; }
.tag-input-wrap:focus-within { border-color: var(--accent2); }
.tag-chip { display: inline-flex; align-items: center; gap: .2rem; background: var(--accent2);
    color: #fff; font-size: .78rem; padding: .1rem .45rem; border-radius: 10px; }
.tag-chip button { background: none; border: none; color: inherit; cursor: pointer;
    padding: 0 0 0 .1rem; font-size: 1em; line-height: 1; }
.tag-input { background: none; border: none; outline: none; color: var(--text);
    font-size: .85rem; min-width: 80px; flex: 1; padding: 0; }

/* Location autocomplete */
.location-input-wrap { position: relative; }
.location-input { width: 100%; padding: .4rem .7rem; background: var(--surface2);
    border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); font-size: .85rem; }
.location-input:focus { outline: none; border-color: var(--accent2); }
.location-clear-btn { position: absolute; right: .5rem; top: 50%; transform: translateY(-50%);
    background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: .85rem; padding: 0; }
.location-dropdown { position: absolute; top: 100%; left: 0; right: 0; background: var(--surface);
    border: 1px solid var(--border); border-radius: var(--radius); z-index: 100;
    max-height: 200px; overflow-y: auto; box-shadow: 0 4px 12px rgba(0,0,0,.3); }
.location-dropdown.hidden { display: none; }
.location-dropdown-item { padding: .5rem .75rem; cursor: pointer; font-size: .85rem;
    border-bottom: 1px solid var(--border); }
.location-dropdown-item:last-child { border-bottom: none; }
.location-dropdown-item:hover { background: var(--surface2); }

/* Place add/edit form */
.place-form { display: flex; flex-direction: column; gap: .5rem; }
.place-form-name { padding: .45rem .7rem; background: var(--surface2); border: 1px solid var(--border);
    border-radius: var(--radius); color: var(--text); font-size: .9rem; width: 100%; }
.place-form-name:focus { outline: none; border-color: var(--accent2); }
.place-form-desc { padding: .4rem .7rem; background: var(--surface2); border: 1px solid var(--border);
    border-radius: var(--radius); color: var(--text); font-size: .85rem; resize: vertical; width: 100%; }
.place-form-desc:focus { outline: none; border-color: var(--accent2); }
.place-form-btns { display: flex; gap: .5rem; }

/* Archive section */
.places-archive { margin-top: 1.5rem; border-top: 1px solid var(--border); padding-top: 1rem; }
.places-archive-toggle { background: none; border: none; color: var(--text-muted);
    cursor: pointer; font-size: .9rem; padding: 0; margin-bottom: .75rem; }
.places-archive-toggle:hover { color: var(--text); }
.places-archive-body { display: flex; flex-direction: column; gap: .5rem; }

/* ===== Shopping View ===== */
#view-shopping { overflow: hidden; padding: 0; flex-direction: column; min-height: 0; }
.shopping-toolbar { display: flex; gap: .6rem; margin-bottom: 1.2rem; flex-wrap: wrap; }
/* Packliste */
.packing-toolbar { align-items: center; }
.packing-chip { background: none; border: 1px solid var(--border); border-radius: 999px;
    padding: .25rem .8rem; color: var(--text-muted); font-size: .85rem; cursor: pointer; }
.packing-chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.packing-toggle.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.packing-progress { margin-left: auto; color: var(--text-muted); font-size: .85rem; font-variant-numeric: tabular-nums; }
.packing-count { margin-left: .6rem; color: var(--text-muted); font-size: .8rem; letter-spacing: 0;
    text-transform: none; font-variant-numeric: tabular-nums; }
.packing-module-form { margin-bottom: 1rem; }
.packing-item.is-packed { opacity: .45; }
.packing-item.is-packed .task-text { text-decoration: line-through; color: var(--text-muted); }
.packing-item.is-dup { opacity: .45; }
.packing-item.is-dup .task-text { font-size: .85rem; }
.packing-dup-hint { color: var(--text-muted); font-size: .8rem; white-space: nowrap; }
.packing-qty { font-weight: 600; font-size: .9rem; font-variant-numeric: tabular-nums; }
.packing-clock { background: none; border: none; cursor: pointer; font-size: .9rem; opacity: .2; padding: 0 .2rem; }
.packing-clock.on { opacity: 1; }
.packing-lastminute .day-header { color: var(--accent); }
.packing-viewtoggle { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.packing-viewtoggle-btn { background: none; border: none; padding: .25rem .7rem; color: var(--text-muted); font-size: .85rem; cursor: pointer; }
.packing-viewtoggle-btn.active { background: var(--accent2); color: #fff; }
.packing-tag { font-size: .75rem; color: var(--text-muted); border: 1px solid var(--border); border-radius: 999px;
    padding: 0 .45rem; white-space: nowrap; }
.packing-cat-label { background: none; border: 1px dashed var(--border); border-radius: 999px; padding: 0 .45rem;
    font-size: .75rem; color: var(--text-muted); cursor: pointer; white-space: nowrap; }
.packing-tag, .packing-cat-label { display: inline-block; max-width: 10rem; overflow: hidden; text-overflow: ellipsis; }
.packing-item .task-text { min-width: 0; }
#view-packing .add-task-form input { min-width: 0; }
.packing-add-select { max-width: 7.5rem; font-size: .8rem; background: var(--surface); color: var(--text);
    border: 1px solid var(--border); border-radius: var(--radius); }
.packing-cat-move { margin-left: .3rem; }

/* ===== Weight View ===== */
#view-weight { overflow: hidden; padding: 0; flex-direction: column; min-height: 0; }

/* Shared inner scroll container for weight + shopping views */
.view-scroll { flex: 1; overflow-y: auto; padding: 1.5rem; min-height: 0; }
.weight-controls { display: flex; justify-content: flex-end; margin-bottom: 1rem; }
.weight-range-select { padding: .3rem .6rem; background: var(--surface);
    border: 1px solid var(--border); border-radius: var(--radius);
    color: var(--text); font-size: .85rem; cursor: pointer; }
.weight-range-select:focus { outline: none; border-color: var(--accent2); }

.weight-chart-wrap { position: relative; background: var(--surface);
    border-radius: var(--radius); padding: 1rem; margin-bottom: 1.2rem;
    border: 1px solid var(--border); }

.habit-chart-controls { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap;
    font-size: .85rem; color: var(--text-muted); margin-bottom: 1.2rem; }
.habit-chart-cb { display: flex; align-items: center; gap: .15rem; color: var(--text);
    cursor: pointer; user-select: none; }
.habit-chart-cb input { cursor: pointer; }
.weight-table-wrap { background: var(--surface); border-radius: var(--radius);
    border: 1px solid var(--border); overflow: hidden; margin-bottom: 1.5rem; }
.weight-table-wrap .bp-table-sub { padding: .6rem .8rem 0; margin: 0; }
.weight-diff-up   { color: var(--accent); }
.weight-diff-down { color: var(--success); }
.weight-habit-dots { display: flex; gap: 3px; align-items: center; }
.user-prefs-section { display: flex; gap: 1.5rem; padding: .75rem 1.25rem;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); margin-bottom: 1rem; flex-wrap: wrap; }
.user-prefs-field { display: flex; align-items: center; gap: .4rem; cursor: default; }
.user-prefs-label { font-size: .85rem; color: var(--text-muted); }
.user-prefs-input { width: 5rem; padding: .2rem .4rem; background: var(--surface2);
    border: 1px solid var(--border); border-radius: 4px; color: var(--text);
    font-size: .9rem; text-align: right; }
.user-prefs-input:focus { outline: none; border-color: var(--accent); }
.input-invalid, .input-invalid:focus { border-color: var(--accent); }
.user-prefs-unit { font-size: .85rem; color: var(--text-muted); }
.weight-del-btn { background: none; border: none; color: var(--text-muted);
    cursor: pointer; font-size: .85rem; padding: 2px 5px; border-radius: 3px; }
.weight-del-btn:hover { background: var(--border); color: var(--text); }
.weight-week-summary td { background: var(--surface2); padding: .25rem .8rem;
    border-top: 1px solid var(--border); font-size: .8rem; color: var(--text-muted); }
.weight-week-summary .wk-label { font-weight: 600; }

/* Weight input in day header */
.weight-input-wrap { display: inline-flex; align-items: center; gap: .25rem;
    margin-left: .5rem; }
.weight-day-input { width: 56px; padding: .15rem .35rem; background: var(--surface2);
    border: 1px solid var(--border); border-radius: var(--radius);
    color: var(--text); font-size: .8rem; text-align: right; }
.weight-day-input:focus { outline: none; border-color: var(--accent2); }
/* Hide number input spinners */
.weight-day-input::-webkit-outer-spin-button,
.weight-day-input::-webkit-inner-spin-button { -webkit-appearance: none; }
.weight-day-input[type=number] { -moz-appearance: textfield; }
.weight-kg-label { font-size: .75rem; color: var(--text-muted); }
.weight-save-btn { background: none; border: none; color: var(--text-muted);
    cursor: pointer; font-size: .85rem; padding: 1px 3px; transition: color .2s; }
.weight-save-btn:hover { color: var(--text); }

@media (max-width: 640px) {
    .view-scroll { padding: 1rem; }
    #view-invoices { padding: 1rem; }
}

/* ===== Habit Tracker ===== */
.habit-input-wrap {
    display: inline-flex;
    gap: .25rem;
    align-items: center;
    margin-left: .5rem;
}
.habit-btn {
    font-size: .7rem;
    padding: .2rem .45rem;
    border-radius: 4px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-muted);
    cursor: pointer;
    transition: background .15s, color .15s, border-color .15s;
    line-height: 1.4;
}
.habit-btn.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}
.habit-btn:hover:not(.active) {
    background: var(--surface2);
    color: var(--text);
}
.habit-streaks {
    padding: 1rem 1.5rem 0;
    max-width: 600px;
}
.habit-streaks-heading {
    margin: 0 0 .5rem;
    font-size: .75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .05em;
    font-weight: 600;
}
.habit-streak-row {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .45rem 0;
    border-bottom: 1px solid var(--border);
}
.habit-def-row { display: flex; align-items: center; gap: .5rem; margin-bottom: .5rem; flex-wrap: wrap; }
.habit-def-row input[type="text"] { flex: 1; min-width: 8rem; padding: .3rem .5rem; border: 1px solid var(--border); border-radius: 4px; background: var(--surface); color: var(--text); }
.habit-color-swatches { display: flex; gap: .3rem; }
.habit-color-swatch { width: 18px; height: 18px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; padding: 0; }
.habit-color-swatch.selected { border-color: var(--text); }
.habit-streak-row:last-child {
    border-bottom: none;
}
.habit-streak-name {
    flex: 1;
    font-weight: 500;
}
.habit-streak-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--border);
    flex-shrink: 0;
}
.habit-streak-dot.done {
    background: var(--success);
}
.habit-streak-progress { font-size: .75rem; color: var(--text-muted);
    font-variant-numeric: tabular-nums; }
.habit-streak-progress.met { color: var(--success); }
.habit-week-label { font-size: .75rem; color: var(--text-muted); }
.habit-streak-count {
    color: var(--text-muted);
    font-size: .875rem;
    min-width: 4.5rem;
    text-align: right;
}
.habit-config-select {
    font-size: .75rem;
    padding: .15rem .3rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--surface);
    color: var(--text-muted);
    cursor: pointer;
    margin-left: .5rem;
}
.habit-config-select:focus {
    outline: none;
    border-color: var(--accent2);
}
.habit-sick-label {
    display: flex;
    align-items: center;
    gap: .3rem;
    font-size: .75rem;
    color: var(--text-muted);
    cursor: pointer;
    margin-left: .5rem;
    white-space: nowrap;
}
.habit-nachtragen-row {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: .5rem 0 .3rem;
    border-top: 1px solid var(--border);
    flex-wrap: wrap;
}
.habit-nachtragen-date {
    font-size: .75rem;
    padding: .15rem .3rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--surface);
    color: var(--text-muted);
    cursor: pointer;
}
.habit-nachtragen-date:focus {
    outline: none;
    border-color: var(--accent2);
}
.weight-habit-only-row td {
    color: var(--text-muted);
    font-style: italic;
}
.bp-section {
    padding: 1rem 1.5rem 1.5rem;
    max-width: 600px;
}
.bp-form {
    display: flex;
    align-items: center;
    gap: .5rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}
.bp-input {
    width: 4.5rem;
    padding: .25rem .4rem;
    font-size: .875rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--surface);
    color: var(--text);
    text-align: center;
}
.bp-input:focus { outline: none; border-color: var(--accent2); }
.bp-sep { font-weight: 600; color: var(--text-muted); }
.bp-unit { font-size: .75rem; color: var(--text-muted); }
.bp-field-group { display: inline-flex; align-items: center; gap: .5rem; }
.bp-time-input { width: 6.5rem; }
.bp-time { color: var(--text-muted); }
.bp-status { font-size: .8rem; }
.bp-status-ok    { color: var(--text); }
.bp-status-ok::before { content: '✓ '; color: var(--success); font-weight: 600; }
.bp-status-error { color: var(--accent); }
.bp-table-sub { font-size: .75rem; color: var(--text-muted); margin: -.25rem 0 .5rem; }
.bp-table { width: 100%; border-collapse: collapse; font-size: .875rem; }
.bp-table th { text-align: left; padding: .3rem .5rem; color: var(--text-muted); font-weight: 600; font-size: .75rem; border-bottom: 2px solid var(--border); }
.bp-table td { padding: .35rem .5rem; border-bottom: 1px solid var(--border); }
.bp-table .bp-num { text-align: right; font-variant-numeric: tabular-nums; }
.bp-table .bp-date { white-space: nowrap; font-variant-numeric: tabular-nums; }
.bp-cat { display: inline-flex; align-items: center; gap: .35rem; color: var(--text); white-space: nowrap; }
.bp-cat-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }

/* BP chart card: stats, legend, crosshair readout */
.card-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(8.5rem, max-content));
    gap: .75rem 2rem; margin-bottom: .9rem; }
.card-stat-label { font-size: .75rem; color: var(--text-muted); }
.card-stat-value { font-size: 1.3rem; font-weight: 600; color: var(--text); line-height: 1.3; }
.card-stat-value.weight-diff-up   { color: var(--accent); }
.card-stat-value.weight-diff-down { color: var(--success); }
.card-stat-unit { font-size: .75rem; font-weight: 400; color: var(--text-muted); }
.card-stat-meta { display: flex; flex-direction: column; gap: .1rem; font-size: .75rem; color: var(--text-muted); }
.chart-legend { display: flex; align-items: center; gap: .9rem; flex-wrap: wrap;
    font-size: .8rem; color: var(--text); margin-bottom: .5rem; }
.chart-legend-note { color: var(--text-muted); }
.chart-key { display: inline-block; width: 14px; height: 2px; border-radius: 1px;
    vertical-align: middle; margin-right: .35rem; flex: none; }
.chart-key-dashed { background: repeating-linear-gradient(90deg, var(--text-muted) 0 4px, transparent 4px 7px); }
.chart-key-dotted { background: repeating-linear-gradient(90deg, var(--text-muted) 0 2px, transparent 2px 4px); }
.chart-svg { display: block; touch-action: pan-y; }
.chart-svg:focus { outline: none; }
.chart-svg:focus-visible { outline: 2px solid var(--accent2); outline-offset: 2px; border-radius: 2px; }
.chart-tooltip { position: absolute; z-index: 5; pointer-events: none; min-width: 8rem; max-width: 16rem;
    background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius);
    padding: .4rem .6rem; font-size: .8rem; box-shadow: 0 2px 8px rgba(0,0,0,.2); }
.chart-tip-date { font-size: .75rem; color: var(--text-muted); margin-bottom: .2rem; }
.chart-tip-row { display: flex; align-items: center; flex-wrap: nowrap; gap: .1rem .4rem;
    white-space: nowrap; font-variant-numeric: tabular-nums; }
.chart-tip-row strong { font-weight: 600; min-width: 3.4em; text-align: right; }
.chart-tip-row .chart-tip-label { min-width: 3.4em; }
.chart-tip-row .bp-cat { margin-left: auto; }
.chart-tip-time { color: var(--text-muted); min-width: 2.6em; }
.chart-tip-label { color: var(--text-muted); }
.chart-tip-sub { font-size: .75rem; color: var(--text-muted); margin-top: .2rem; }
.chart-tip-habits { display: flex; flex-wrap: wrap; gap: .1rem .5rem; margin-top: .25rem; font-size: .75rem; }
.chart-tooltip .bp-cat { margin-top: .25rem; font-size: .75rem; }
.chart-card-head { display: flex; align-items: baseline; justify-content: space-between;
    gap: 1rem; margin-bottom: .5rem; }
.chart-card-head .habit-streaks-heading { margin-bottom: 0; }

/* Printable BP log — hidden on screen, the only thing on paper */
#print-area { display: none; }
@media print {
    html, body { background: #fff !important; }
    body > *:not(#print-area) { display: none !important; }
    #print-area {
        display: block;
        /* Light values regardless of the app theme; printers drop dark backgrounds */
        --surface: #fff; --surface2: #fff; --bg: #fff;
        --text: #000; --text-muted: #444; --border: #bbb;
        --bp-sys: #c62828; --bp-dia: #1565c0;
        background: #fff; color: #000; padding: 0;
        font-size: 11pt;
    }
    #print-area h1 { font-size: 16pt; margin-bottom: .2rem; }
    #print-area .print-meta { color: #333; margin-bottom: 1rem; }
    #print-area .card-stats { margin-bottom: 1rem; }
    #print-area .card-stat-value { font-size: 13pt; }
    #print-area .print-chart { margin: 0 0 1rem; break-inside: avoid; }
    #print-area .bp-section { padding: 0; max-width: none; }
    #print-area .bp-table { width: 100%; }
    #print-area .bp-table thead { display: table-header-group; }
    #print-area th { text-transform: none; letter-spacing: 0; }
    #print-area .bp-table tr { break-inside: avoid; }
    #print-area .bp-cat-dot { border: 1px solid #666; }
    #print-area .print-note { margin-top: 1rem; font-size: 9pt; color: #333; }
    @page { margin: 15mm; }
}
@media (max-width: 640px) {
    .bp-section { padding-left: 0; padding-right: 0; }
    .bp-table { font-size: .8rem; }
    .bp-table td, .bp-table th { padding-left: .3rem; padding-right: .3rem; }
}

/* ===== Periodic Tasks ===== */
.periodic-task-item { cursor: default; border-left: 3px solid var(--accent2); }
.periodic-task-item:hover { border-color: var(--accent2); }
.periodic-icon { font-size: .85rem; color: var(--accent2); flex-shrink: 0; margin-top: 1px; }
.periodic-badge {
    font-size: .7rem; color: var(--text-muted); background: var(--surface2);
    border: 1px solid var(--border); border-radius: 3px; padding: 1px 5px;
    white-space: nowrap; align-self: center;
}

/* Periodic management view */
.periodic-hint {
    font-size: .85rem; color: var(--text-muted); margin-bottom: 1.2rem; line-height: 1.5;
}
.periodic-form {
    display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: 1.5rem; align-items: center;
}
.periodic-select {
    padding: .3rem .5rem; font-size: .875rem; border: 1px solid var(--border);
    border-radius: var(--radius); background: var(--surface); color: var(--text);
    cursor: pointer;
}
.periodic-select:focus { outline: none; border-color: var(--accent2); }
.periodic-select-sm { font-size: .8rem; padding: .2rem .4rem; }
.periodic-weeks { width: 4.5rem; }
.periodic-list { display: flex; flex-direction: column; gap: .5rem; }
.periodic-manage-row {
    display: flex; align-items: center; gap: .6rem; flex-wrap: wrap;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: .5rem .8rem;
}
.periodic-manage-text {
    flex: 1; font-size: .9rem; cursor: pointer; min-width: 8rem;
}
.periodic-manage-text:hover { color: var(--accent); }
.periodic-inline-edit {
    flex: 1; min-width: 8rem; font-size: .9rem;
    background: var(--surface2); border: 1px solid var(--accent2);
    border-radius: var(--radius); color: var(--text); padding: .2rem .4rem;
}
.periodic-next {
    font-size: .8rem; color: var(--text-muted); white-space: nowrap;
    min-width: 5.5rem; text-align: right;
}
.periodic-next.overdue { color: var(--accent); font-weight: 600; }
.periodic-date { width: 9.5rem; }
.periodic-date-label { display: flex; align-items: center; gap: .4rem; font-size: .8rem; color: var(--text-muted); }
.periodic-manage-row.paused { opacity: .55; }
.periodic-manage-row.paused .periodic-icon { color: var(--text-muted); }
.periodic-pause-btn {
    color: var(--text-muted); background: none; border: none; cursor: pointer;
    font-size: .95rem; padding: 2px 6px;
}
.periodic-pause-btn:hover { color: var(--accent2); }
.periodic-summary { font-size: .85rem; color: var(--text-muted); margin: 0 0 .8rem; }
.periodic-stats {
    flex-basis: 100%; text-align: left; font-size: .75rem; color: var(--text-muted);
    background: none; border: none; cursor: pointer; padding: 0; margin-top: -.1rem;
}
.periodic-stats:hover { color: var(--accent2); }
.periodic-history {
    flex-basis: 100%; display: flex; flex-wrap: wrap; gap: .3rem .5rem;
    font-size: .75rem; color: var(--text-muted); padding-top: .2rem;
}
.periodic-history[hidden] { display: none; }
.periodic-history-item {
    border: 1px solid var(--border); border-radius: 3px; padding: 1px 5px;
    white-space: nowrap; background: var(--surface2);
}
.periodic-history-item.done   { color: #4caf50; border-color: rgba(76,175,80,.4); }
.periodic-history-item.missed { color: #ef5350; border-color: rgba(239,83,80,.4); }

/* ===== Priority ===== */
.priority-dot {
    width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0;
    margin-top: 4px; cursor: pointer; transition: transform .15s;
}
.priority-dot:hover { transform: scale(1.35); }
.priority-dot.priority-none   { background: var(--border); opacity: .4; }
.priority-dot.priority-high   { background: #ef5350; }
.priority-dot.priority-medium { background: #ff9800; }
.priority-dot.priority-low    { background: #42a5f5; }

/* ===== Geschenke ===== */
#view-gifts { overflow: hidden; padding: 0; flex-direction: column; min-height: 0; }
.gift-form-section { max-width: none; }
.gift-form { align-items: center; }
.gift-input { padding: .25rem .5rem; font-size: .875rem; border: 1px solid var(--border);
    border-radius: 4px; background: var(--surface); color: var(--text); width: 9rem; }
.gift-input-wide { width: 14rem; }
.gift-input:focus { outline: none; border-color: var(--accent2); }

.gift-person { background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); margin-bottom: .75rem; overflow: hidden; }
.gift-person-head { display: flex; align-items: baseline; gap: .5rem; width: 100%;
    padding: .6rem .8rem; background: none; border: none; cursor: pointer;
    color: var(--text); font-size: .95rem; text-align: left; font-family: inherit; }
.gift-person-head:hover { background: var(--surface2); }
.gift-person-name { font-weight: 600; }
.gift-person-meta { color: var(--text-muted); font-size: .8rem; }
.gift-person-body { display: flex; flex-direction: column; }
.gift-person-body.collapsed { display: none; }

.gift-row { display: flex; align-items: baseline; gap: .6rem; padding: .4rem .8rem;
    border-top: 1px solid var(--border); font-size: .875rem; }
.gift-row:hover { background: var(--surface2); }
.gift-date { color: var(--text-muted); font-variant-numeric: tabular-nums;
    white-space: nowrap; min-width: 5.6rem; }
.gift-item { font-weight: 500; }
.gift-details { display: flex; flex-wrap: wrap; gap: .4rem; align-items: baseline;
    color: var(--text-muted); font-size: .8rem; }
.gift-occasion { border: 1px solid var(--border); border-radius: 999px; padding: 0 .45rem; }
.gift-actions { margin-left: auto; display: flex; align-items: center; gap: .25rem; white-space: nowrap; }
.gift-idea .gift-date { font-style: italic; }
.gift-idea { background: color-mix(in srgb, var(--accent2) 8%, transparent); }

.gift-modal-field { display: flex; flex-direction: column; gap: .2rem; margin-bottom: .6rem; font-size: .85rem; }
.gift-modal-field span { color: var(--text-muted); }
.gift-modal-field input { padding: .4rem .6rem; background: var(--bg); border: 1px solid var(--border);
    border-radius: var(--radius); color: var(--text); font-size: .9rem; }
.gift-modal-field input:focus { outline: none; border-color: var(--accent2); }

@media (max-width: 640px) {
    .gift-input, .gift-input-wide { width: 100%; }
    .gift-form .weight-save-btn { width: 100%; padding: .45rem; border: 1px solid var(--border);
        border-radius: var(--radius); background: var(--surface2); }
    .gift-row { flex-wrap: wrap; gap: .3rem .6rem; }
    .gift-actions { margin-left: auto; }
}

/* ===== Offline-Warteschlange ===== */
.offline-banner.offline-banner-pending { background: var(--accent2); }
.pending-badge { display: inline-block; margin-left: .4rem; padding: 0 .45rem; font-size: .7rem;
    color: var(--text-muted); border: 1px dashed var(--border); border-radius: 999px;
    white-space: nowrap; font-style: normal; vertical-align: middle; }
.is-pending { opacity: .8; }

/* ===== Einladungen (events) ===== */
.events-view .admin-section { margin-top: 1rem; }
.event-detail-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 1rem; align-items: start; }
@media (max-width: 900px) { .event-detail-grid { grid-template-columns: minmax(0, 1fr); } }
.event-section { border: 1px solid var(--border); border-top: 4px solid var(--accent2); box-shadow: 0 2px 8px rgba(0, 0, 0, .12); }
.event-section-mail { border-top-color: var(--accent); }
.event-section-guests { border-top-color: var(--success); }
.event-section > h3 { font-size: .95rem; color: var(--text); letter-spacing: .03em; padding-bottom: .5rem; border-bottom: 1px solid var(--border); margin-bottom: 1rem; }
.event-detail-grid .event-section { margin-top: 0; }
.event-detail-grid .event-field textarea { min-height: 4.5rem; }
.event-form-row { display: flex; flex-wrap: wrap; gap: .5rem; }
.event-form-row input[type="text"] { flex: 1 1 14rem; }
.event-form-row input, .event-edit-grid input, .event-field input, .event-field textarea, .event-add-guests textarea, .event-link-row input {
    padding: .45rem .6rem; border: 1px solid var(--border); border-radius: var(--radius);
    background: var(--bg); color: var(--text); font: inherit; }
.event-card { display: block; width: 100%; text-align: left; background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: .8rem 1rem; margin-bottom: .6rem; color: var(--text); cursor: pointer; font: inherit; }
.event-card:hover { background: var(--surface2); }
.event-card-title { font-weight: 600; font-size: 1.05rem; }
.event-card-meta { color: var(--text-muted); font-size: .85rem; margin-top: .15rem; }
.event-card-counts { font-size: .85rem; margin-top: .35rem; }
.event-edit-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: .6rem .8rem; margin-bottom: .6rem; align-items: end; }
.event-field { display: flex; flex-direction: column; gap: .25rem; font-size: .8rem; color: var(--text-muted); margin-bottom: .6rem; }
.event-field input, .event-field textarea { color: var(--text); font-size: .95rem; width: 100%; }
.event-image-box { margin: .4rem 0 .6rem; }
.event-image-preview { display: block; max-width: 100%; max-height: 220px; border-radius: var(--radius); margin-bottom: .4rem; }
.event-link-row { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; margin-top: .4rem; }
.event-link-row input { flex: 1 1 16rem; font-size: .85rem; }
.event-link-label { font-size: .8rem; color: var(--text-muted); }
.event-summary { margin-bottom: .8rem; }
.event-add-guests { display: flex; flex-direction: column; gap: .5rem; align-items: flex-start; margin-bottom: .8rem; }
.event-add-guests textarea { width: 100%; }
.table-wrap { overflow-x: auto; margin-top: .8rem; }
.guest-yes .guest-status { color: var(--success); }
.guest-no .guest-status { color: var(--text-muted); }
.guest-no td { opacity: .7; }
.guest-email, .guest-sent { color: var(--text-muted); font-size: .85rem; }
.guest-message { max-width: 18rem; white-space: pre-wrap; font-size: .85rem; }
.guest-actions { white-space: nowrap; }
.guest-actions .btn { margin-right: .2rem; text-decoration: none; }
.event-badge { display: inline-block; margin-left: .5rem; padding: .05rem .5rem; border-radius: 999px; font-size: .7rem;
    font-weight: 600; text-transform: uppercase; letter-spacing: .04em; background: var(--surface2); color: var(--text-muted); vertical-align: middle; }
.event-cancelled .event-card-title { text-decoration: line-through; }
.guest-history-row td { background: var(--bg); font-size: .8rem; color: var(--text-muted); padding: .4rem .7rem .4rem 1.5rem; }
.guest-history-entry { line-height: 1.6; }
.modal textarea { width: 100%; padding: .5rem .7rem; margin-bottom: .8rem; border: 1px solid var(--border);
    border-radius: var(--radius); background: var(--bg); color: var(--text); font: inherit; }
