:root {
  --primary: #2f6f4f;
  --primary-dark: #24573f;
  --bg: #f5f6f4;
  --card-bg: #ffffff;
  --border: #dfe3e0;
  --text: #232823;
  --text-muted: #6b756f;
  --danger: #b3392c;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { overflow-x: hidden; max-width: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); }

/* ---- Auth pages ---- */
.auth-page { display: flex; align-items: center; justify-content: center; height: 100vh; }
.auth-box { background: var(--card-bg); padding: 2.2rem; border-radius: 12px; box-shadow: 0 4px 20px rgba(0,0,0,.08); width: 340px; }
.auth-box h1 { margin-top: 0; font-size: 1.4rem; }
.auth-box label { display: block; margin: .8rem 0 .3rem; font-size: .85rem; color: var(--text-muted); }
.auth-box input { width: 100%; padding: .6rem; border: 1px solid var(--border); border-radius: 8px; font-size: 1rem; }
.auth-box button { margin-top: 1.2rem; width: 100%; }
.error { color: var(--danger); font-size: .9rem; }
.success { color: var(--primary); font-size: .9rem; }

/* ---- Buttons ---- */
button, .btn-secondary, .btn-primary, .btn-danger, .btn-link {
  cursor: pointer; border: none; border-radius: 8px; padding: .55rem 1rem;
  font-size: .9rem; font-weight: 500; text-decoration: none; display: inline-block;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: #eceeec; color: var(--text); }
.btn-secondary:hover { background: #dfe3e0; }
.btn-danger { background: #fbe4e1; color: var(--danger); }
.btn-danger:hover { background: #f6cfc9; }
.btn-link { background: transparent; color: var(--text-muted); }
.icon-btn.active { color: var(--primary); }
.pin-btn { font-size: 1rem; }

/* ---- Layout ---- */
#topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: .8rem 1.2rem; background: var(--card-bg); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 1.1rem; cursor: pointer; }
.topbar-actions { display: flex; gap: .5rem; }

#layout { display: flex; height: calc(100vh - 58px); min-width: 0; }

#sidebar {
  width: 280px; min-width: 220px; max-width: 600px; background: var(--card-bg); border-right: 1px solid var(--border);
  overflow-y: auto; overflow-x: hidden; padding: .8rem; flex-shrink: 0; position: relative;
}
#sidebarResizeHandle {
  width: 6px; flex-shrink: 0; cursor: col-resize; background: transparent; position: relative; z-index: 5;
}
#sidebarResizeHandle:hover, #sidebarResizeHandle.dragging { background: var(--primary); opacity: .3; }
@media (max-width: 900px) { #sidebarResizeHandle { display: none; } }
.sidebar-header { display: flex; justify-content: space-between; align-items: center; font-weight: 600; margin-bottom: .5rem; color: var(--text-muted); font-size: .85rem; text-transform: uppercase; }
.sidebar-header button { background: var(--primary); color: white; min-width: 26px; min-height: 26px; border-radius: 50%; padding: 0; line-height: 1; }

#content { flex: 1; min-width: 0; overflow-y: auto; padding: 1.4rem; }
.empty-state { color: var(--text-muted); text-align: center; margin-top: 4rem; }
.hidden { display: none !important; }

/* ---- Folder tree ---- */
.folder-node { margin-bottom: 2px; }
.folder-row { display: flex; align-items: center; gap: 4px; padding: .4rem .5rem; border-radius: 6px; cursor: pointer; min-width: 0; }
.folder-row:hover { background: #eef2ef; }
.folder-row.active { background: #dcecdf; font-weight: 600; }
.folder-row .label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder-row .actions { display: none; gap: 2px; }
.folder-row:hover .actions { display: flex; }
.folder-row .actions button { background: none; padding: 2px 5px; font-size: .8rem; color: var(--text-muted); }
.folder-children { margin-left: 16px; border-left: 1px dashed var(--border); padding-left: 6px; }
.folder-checkbox { margin-right: 4px; }

#exportBar { margin-top: 1rem; padding: .8rem; background: #f0f4f1; border-radius: 8px; }
#exportBar p { margin: 0 0 .5rem; font-size: .85rem; color: var(--text-muted); }
#exportBar button { display: block; width: 100%; margin-bottom: .4rem; }

/* ---- Folder view ---- */
.folder-view-header { margin-bottom: 1rem; }
.folder-view-header h2 { margin: 0 0 .6rem; }
.tabs { display: flex; gap: .4rem; border-bottom: 1px solid var(--border); }
.tab { background: none; border-radius: 8px 8px 0 0; color: var(--text-muted); padding: .5rem 1rem; }
.tab.active { background: var(--card-bg); color: var(--primary); font-weight: 600; border: 1px solid var(--border); border-bottom-color: var(--card-bg); margin-bottom: -1px; }
.tab-count { color: var(--text-muted); font-weight: 400; font-size: .85em; }
.tab-panel { display: none; padding-top: 1rem; }
.tab-panel.active { display: block; }

.drop-zone {
  border: 2px dashed var(--border); border-radius: 12px; padding: 1.6rem; text-align: center;
  margin-bottom: 1.2rem; background: var(--card-bg);
}
.drop-zone.dragover { border-color: var(--primary); background: #eef7f0; }
.drop-zone p { margin: 0 0 .8rem; color: var(--text-muted); }
.drop-zone button { margin: 0 .3rem; }

.doc-grid, .notes-grid, .todos-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: .8rem; }

.doc-card, .note-card, .todo-card {
  background: var(--card-bg); border: 1px solid var(--border); border-radius: 10px; padding: .8rem;
  display: flex; flex-direction: column; gap: .4rem; min-width: 0; overflow-wrap: break-word;
}
.doc-card .icon { font-size: 1.8rem; }
.doc-card .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-card .meta { font-size: .75rem; color: var(--text-muted); }
.doc-card .row { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: auto; }
.doc-card .row button, .doc-card .row a { flex: 1 1 45%; text-align: center; font-size: .72rem; padding: .35rem .3rem; }

.note-card { cursor: pointer; }
.note-card .title { font-weight: 600; }
.note-card .preview { font-size: .8rem; color: var(--text-muted); max-height: 3.2em; overflow: hidden; }
.note-card .meta { font-size: .7rem; color: var(--text-muted); }

.todo-card .todo-header { display: flex; flex-direction: column; gap: .4rem; }
.todo-header-icons { display: flex; gap: .3rem; align-items: center; }
.todo-item { display: flex; align-items: flex-start; gap: .4rem; padding: .2rem 0; min-width: 0; }
.todo-item.done .todo-item-field { text-decoration: line-through; color: var(--text-muted); }
.todo-add-row { display: flex; gap: .4rem; margin-top: .5rem; min-width: 0; }
.todo-add-row input { flex: 1; min-width: 0; border: 1px solid var(--border); border-radius: 6px; padding: .3rem .5rem; box-sizing: border-box; }
.icon-btn { background: none; color: var(--text-muted); padding: 2px 6px; flex-shrink: 0; }

/* Automatisch wachsende Textfelder: kein Abschneiden mehr, Text bricht bei Bedarf um */
.autogrow-field {
  border: none; background: transparent; font-family: inherit; resize: none; overflow: hidden;
  white-space: pre-wrap; word-break: break-word; min-width: 0; flex: 1; padding: 0; line-height: 1.35;
}
.autogrow-field:focus { outline: 1px solid var(--border); border-radius: 4px; }
.todo-title-field { font-weight: 600; font-size: 1rem; }
.todo-item-field { font-size: .92rem; }

/* ---- Modals ---- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal-box { background: var(--card-bg); border-radius: 12px; padding: 1.4rem; width: 500px; max-width: 92vw; max-height: 88vh; overflow-y: auto; }
.modal-box.small { width: 360px; }
.modal-box input[type=text], .modal-box textarea { width: 100%; border: 1px solid var(--border); border-radius: 8px; padding: .6rem; font-size: 1rem; margin-bottom: .6rem; font-family: inherit; }
.modal-box textarea { min-height: 220px; resize: vertical; }
.modal-actions { display: flex; justify-content: space-between; align-items: center; margin-top: .6rem; flex-wrap: wrap; gap: .5rem; }
.modal-actions > div { display: flex; gap: .4rem; flex-wrap: wrap; }
.hint { font-size: .78rem; color: var(--text-muted); margin-top: .6rem; }

.scan-pages { display: flex; flex-wrap: wrap; gap: .5rem; margin: .8rem 0; }
.scan-pages .page-thumb { position: relative; width: 90px; height: 120px; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.scan-pages .page-thumb img { width: 100%; height: 100%; object-fit: cover; }
.scan-pages .page-thumb .remove { position: absolute; top: 2px; right: 2px; background: rgba(255,255,255,.9); border-radius: 50%; width: 20px; height: 20px; padding: 0; font-size: .7rem; line-height: 1; }

@media (max-width: 780px) {
  #layout { flex-direction: column; height: auto; }
  #sidebar { width: 100%; max-height: 260px; }
  #content { padding: 1rem; }
}

/* ============================================================
   v2 – Dashboard, Unterordner, Teilen, Verschieben, Scan-Editor
   ============================================================ */

.dash-section { margin-bottom: 1.8rem; }
.dash-section:empty { display: none; margin: 0; }
.dash-title { grid-column: 1 / -1; font-weight: 700; font-size: 1rem; margin-bottom: .6rem; color: var(--text); }

.back-link { display: none; margin-bottom: .4rem; padding-left: 0; }

.doc-top, .note-top { display: flex; justify-content: space-between; align-items: flex-start; }
.note-top .title { font-weight: 600; cursor: pointer; }
.note-card .meta { cursor: pointer; }

/* ---- Unterordner-Kacheln ---- */
.subfolder-grid, .move-tree-inline { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: .6rem; margin-bottom: 1rem; }
.subfolder-tile {
  background: var(--card-bg); border: 1px solid var(--border); border-radius: 10px; padding: .7rem;
  display: flex; align-items: center; gap: .5rem; cursor: pointer; min-height: 4.4rem;
}
.subfolder-tile:hover { border-color: var(--primary); }
.subfolder-tile .sf-name { flex: 1; white-space: normal; word-break: break-word; font-weight: 500; }
#subfolderList:empty { display: none; }
.section-label { font-weight: 600; color: var(--text-muted); font-size: .85rem; text-transform: uppercase; }
.panel-toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: .6rem; }
.folder-items-toolbar { flex-wrap: wrap; gap: .6rem; margin-top: 1.2rem; }
.folder-items-count { color: var(--text-muted); font-size: .8rem; }
.folder-items-controls { display: flex; gap: .5rem; flex-wrap: wrap; width: 100%; }
.folder-items-controls select {
  flex: 1 1 150px; min-width: 0; max-width: 100%;
  background: var(--card-bg); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: .5rem .6rem; font-size: .85rem;
}

/* ---- Notiz: offen im Dashboard ---- */
.note-open-card { background: var(--card-bg); border: 1px solid var(--border); border-radius: 10px; padding: .8rem; margin-bottom: .8rem; }
.note-open-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: .5rem; }
.note-open-header input { flex: 1; min-width: 0; border: none; background: transparent; font-weight: 600; font-size: 1rem; box-sizing: border-box; }
.note-open-header { flex-wrap: wrap; }
.note-open-card textarea { width: 100%; min-height: 100px; border: 1px solid var(--border); border-radius: 8px; padding: .5rem; font-family: inherit; resize: vertical; }

/* ---- Teilen ---- */
.share-options { display: flex; flex-direction: column; gap: .5rem; margin: .8rem 0; }
.share-btn { text-align: center; }
.share-link-row { display: flex; gap: .4rem; }
.share-link-row input { flex: 1; border: 1px solid var(--border); border-radius: 8px; padding: .5rem; font-size: .8rem; }

/* ---- Verschieben ---- */
.move-tree { max-height: 300px; overflow-y: auto; }
.move-row { padding: .5rem .6rem; border-radius: 6px; cursor: pointer; }
.move-row:hover { background: #eef2ef; }

/* ---- Scan-Editor (Crop) ---- */
.crop-box { width: 640px; }
.crop-container { width: 100%; height: 340px; background: #111; border-radius: 8px; overflow: hidden; }
.crop-container img { max-width: 100%; display: block; }
.crop-toolbar { display: flex; gap: .5rem; justify-content: center; margin: .8rem 0; }
.page-thumb .edit { position: absolute; bottom: 2px; right: 2px; background: rgba(255,255,255,.9); border-radius: 6px; width: 22px; height: 22px; padding: 0; font-size: .7rem; line-height: 1; }

/* ============================================================
   Mobile-Optimierung
   ============================================================ */

@media (max-width: 780px) {
  #topbar { padding: .6rem .8rem; }
  .topbar-actions { gap: .3rem; }
  .topbar-actions .btn-secondary, .topbar-actions a { padding: .45rem .6rem; font-size: .78rem; }
  .search-input { width: 130px; }
  .search-results { width: 90vw; max-width: 90vw; left: -40px; }
  .brand { font-size: 1rem; }

  #layout { position: relative; overflow: hidden; }

  #sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 60; width: 82vw; max-width: 320px;
    transform: translateX(-105%); transition: transform .2s ease; box-shadow: 2px 0 12px rgba(0,0,0,.15);
  }
  #sidebar.open { transform: translateX(0); }
  .sidebar-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 55; }

  #content { padding: .8rem; }

  .back-link { display: inline-block; }

  .tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .tab { white-space: nowrap; padding: .5rem .8rem; }

  .doc-grid, .notes-grid, .todos-grid, .subfolder-grid { grid-template-columns: 1fr 1fr; gap: .6rem; }

  .modal-box { width: 94vw; padding: 1rem; }
  .modal-actions { flex-direction: column-reverse; align-items: stretch; }
  .modal-actions > div { flex-direction: column; }
  .modal-actions button, .modal-actions > div button { width: 100%; }
  .crop-box { width: 94vw; }
  .crop-container { height: 260px; }

  .drop-zone { padding: 1.1rem; }
  .drop-zone button { display: block; width: 100%; margin: .4rem 0 0; }

  button, .btn-secondary, .btn-primary, .btn-danger { padding: .6rem .8rem; }
  .doc-card .row, .row { flex-wrap: wrap; }
  .doc-card .row button, .doc-card .row a { flex: 1 1 45%; }
}

@media (max-width: 420px) {
  .doc-grid, .notes-grid, .todos-grid, .subfolder-grid { grid-template-columns: 1fr; }
}

/* ============================================================
   v4 – Dropdown-Menü, einklappbare Ordner
   ============================================================ */

.menu-wrap { position: relative; }
.dropdown-menu {
  position: absolute; top: calc(100% + 6px); right: 0; background: var(--card-bg);
  border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 6px 20px rgba(0,0,0,.12);
  min-width: 180px; padding: .4rem; display: flex; flex-direction: column; gap: .15rem; z-index: 80;
}
.dropdown-menu button, .dropdown-menu a {
  display: block; text-align: left; background: none; border: none; border-radius: 6px;
  padding: .55rem .7rem; font-size: .88rem; color: var(--text); text-decoration: none; cursor: pointer;
}
.dropdown-menu button:hover, .dropdown-menu a:hover { background: #eef2ef; }

.topbar-icon { font-size: 1.15rem; }
.topbar-spacer { flex: 1; }
.topbar-group { display: flex; align-items: center; gap: .25rem; }

.tb-icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 42px; height: 42px; border-radius: 12px; background: transparent;
  font-size: 1.25rem; color: var(--text); border: none; cursor: pointer;
  text-decoration: none; transition: background .15s ease, transform .1s ease;
}
.tb-icon-btn:hover { background: #eef2ef; }
.tb-icon-btn:active { transform: scale(.94); }
.tb-icon-btn.active { background: #dcecdf; }
.icon-only { display: none; }

.search-wrap { position: relative; }
.search-input {
  border: 1px solid var(--border); border-radius: 8px; padding: .45rem .7rem; font-size: .9rem;
  width: 220px; margin-left: .3rem;
}
.search-results {
  position: absolute; top: calc(100% + 6px); left: 0; width: 300px; max-width: 80vw; max-height: 400px;
  overflow-y: auto; background: var(--card-bg); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 6px 20px rgba(0,0,0,.12); z-index: 90; padding: .4rem;
}
.search-group-label { font-size: .72rem; font-weight: 700; color: var(--text-muted); text-transform: uppercase; padding: .4rem .4rem .2rem; }
.search-result-item { padding: .5rem .5rem; border-radius: 6px; cursor: pointer; font-size: .88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-result-item:hover { background: #eef2ef; }
.search-loading { padding: .7rem; color: var(--text-muted); font-size: .85rem; text-align: center; }

.collapse-toggle {
  display: inline-flex; align-items: center; justify-content: center; width: 18px; height: 18px;
  font-size: .7rem; color: var(--text-muted); cursor: pointer; flex-shrink: 0;
}
.collapse-toggle.spacer { cursor: default; }

/* Hamburger-Menü: nur auf dem Handy sichtbar (steht bewusst ganz am Ende,
   damit es garantiert Vorrang vor .tb-icon-btn hat) */
.icon-only { display: none; }
@media (max-width: 780px) {
  .icon-only { display: inline-flex; }
}

/* ============================================================
   v5 - Aufgabenbereich mit Wiedervorlage
   ============================================================ */

.task-list { max-height: 220px; overflow-y: auto; margin-bottom: .3rem; }
.task-empty-hint { font-size: .8rem; color: var(--text-muted); padding: .3rem .2rem; }
.task-sidebar-item { display: flex; align-items: flex-start; gap: .4rem; padding: .4rem .3rem; border-radius: 6px; }
.task-sidebar-item:hover { background: #eef2ef; }
.task-sidebar-item input[type=checkbox] { margin-top: .2rem; flex-shrink: 0; }
.task-sidebar-text { cursor: pointer; min-width: 0; flex: 1; }
.task-sidebar-title { font-size: .85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.task-sidebar-due { font-size: .72rem; color: var(--text-muted); }
.task-sidebar-item.due .task-sidebar-due { color: var(--danger); font-weight: 600; }

.task-field-label { display: block; font-size: .8rem; color: var(--text-muted); margin: .6rem 0 .3rem; }
#taskModal input[type=file], #taskModal input[type=datetime-local] {
  width: 100%; border: 1px solid var(--border); border-radius: 8px; padding: .5rem; font-size: .9rem;
}
.task-existing-file { font-size: .85rem; margin-top: .3rem; }
.task-existing-file a { color: var(--primary); }

.due-task-wrapper {
  background: #fff4e0; border: 1px solid #f0c988; border-radius: 10px; margin-bottom: .6rem;
}
.due-task-card {
  display: flex; align-items: center; gap: .7rem; padding: .7rem .9rem; flex-wrap: wrap;
}
.due-task-wrapper .task-subitems-wrap { margin: 0 .9rem .7rem 3.1rem; }
.due-task-wrapper .task-subitems-toggle { margin-left: -1.2rem; color: #8a6420; }
.due-task-info { flex: 1; min-width: 160px; }
.due-task-title { font-weight: 600; }
.due-task-meta { font-size: .78rem; color: #8a6420; }

@media (max-width: 780px) {
  .task-list { max-height: 160px; }
}

/* ============================================================
   v6 - Einklappbare Sidebar-Bereiche + Arztrechnungen
   ============================================================ */

.sidebar-header.collapsible { cursor: pointer; user-select: none; }
.sidebar-header.collapsible span:first-child { display: flex; align-items: center; gap: .3rem; }
.collapse-arrow { display: inline-block; font-size: .7rem; color: var(--text-muted); width: 12px; }
.sidebar-collapsible.collapsed { display: none; }

.medical-drop-zone {
  border: 2px dashed var(--border); border-radius: 10px; padding: .7rem; text-align: center; margin-bottom: .6rem;
}
.medical-drop-zone.dragover { border-color: var(--primary); background: #eef7f0; }
.medical-drop-zone p { margin: 0 0 .5rem; font-size: .78rem; color: var(--text-muted); }
.medical-drop-actions { display: flex; gap: .4rem; justify-content: center; }
.medical-drop-actions button { font-size: .78rem; padding: .4rem .6rem; }

.medical-year-node { margin-bottom: .4rem; }
.medical-year-label { display: flex; align-items: center; gap: .3rem; font-weight: 700; font-size: .82rem; padding: .2rem .3rem; color: var(--text); cursor: pointer; }
.medical-year-months.collapsed { display: none; }
.medical-month-row {
  display: flex; justify-content: space-between; padding: .35rem .6rem; margin-left: .4rem;
  border-radius: 6px; cursor: pointer; font-size: .82rem;
}
.medical-month-row:hover { background: #eef2ef; }
.medical-month-total { color: var(--text-muted); font-size: .76rem; }

.move-row-medical { color: #b3392c; font-weight: 600; border-bottom: 1px solid var(--border); margin-bottom: .3rem; padding-bottom: .5rem; }
.move-row-invoice { color: #2c5cb3; font-weight: 600; border-bottom: 1px solid var(--border); margin-bottom: .3rem; padding-bottom: .5rem; }

.medical-form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .7rem; margin-bottom: .6rem; }
.medical-form-grid label { display: flex; flex-direction: column; gap: .25rem; font-size: .78rem; color: var(--text-muted); }
.medical-form-grid input { border: 1px solid var(--border); border-radius: 8px; padding: .5rem; font-size: .9rem; font-family: inherit; color: var(--text); }
@media (max-width: 600px) { .medical-form-grid { grid-template-columns: 1fr; } }

.medical-summary {
  display: flex; flex-wrap: wrap; gap: .8rem; align-items: center; background: var(--card-bg);
  border: 1px solid var(--border); border-radius: 10px; padding: .9rem 1rem; margin-bottom: 1rem;
}
.medical-stat { display: flex; flex-direction: column; gap: .1rem; padding-right: 1.2rem; border-right: 1px solid var(--border); }
.medical-stat:last-of-type { border-right: none; }
.medical-stat-label { font-size: .72rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .02em; }
.medical-stat-value { font-size: 1.15rem; font-weight: 700; }
.medical-stat-reimbursed { color: var(--primary); }

.medical-bills-list { display: flex; flex-direction: column; gap: .5rem; }
.medical-bill-row {
  display: grid; grid-template-columns: 1.1fr .8fr 1.3fr .7fr .85fr .85fr 1.3fr 1.5fr; gap: .5rem; align-items: center;
  background: var(--card-bg); border: 1px solid var(--border); border-radius: 8px; padding: .6rem .8rem; font-size: .84rem;
}
.mb-status { border: 1px solid var(--border); border-radius: 6px; padding: .3rem; font-size: .78rem; width: 100%; }
.mb-reimb { display: flex; flex-direction: column; gap: .3rem; }
.mb-reimb-amount { border: 1px solid var(--border); border-radius: 6px; padding: .3rem; font-size: .78rem; width: 100%; box-sizing: border-box; }
.mb-flag-cell { display: flex; flex-direction: column; gap: .3rem; }
.mb-flag-label { display: flex; align-items: center; gap: .3rem; font-size: .78rem; cursor: pointer; white-space: nowrap; }
.mb-flag-date { border: 1px solid var(--border); border-radius: 6px; padding: .25rem; font-size: .76rem; width: 100%; box-sizing: border-box; }
.mb-actions { display: flex; gap: .4rem; }
.mb-actions a, .mb-actions button { font-size: .76rem; padding: .35rem .5rem; }
@media (max-width: 1000px) {
  .medical-bill-row { grid-template-columns: 1fr 1fr; }
  .mb-actions { grid-column: 1 / -1; }
}

/* ============================================================
   v7 - Erledigte Aufgaben, Mehrseiten-Scan Feinschliff
   ============================================================ */

.sub-collapsible { padding-left: .6rem; font-size: .85rem; opacity: .85; }
.done-title { text-decoration: line-through; color: var(--text-muted); }
.done-task { justify-content: space-between; }
.done-task-actions { display: flex; gap: .2rem; flex-shrink: 0; }
.done-task-actions button { background: none; border: none; padding: .2rem .3rem; cursor: pointer; font-size: .85rem; }

/* ============================================================
   v8 - Jahreskalender (Woche/Monat/Jahr, Bereiche, Feiertage)
   ============================================================ */

.cal-year-buttons { display: flex; gap: .4rem; margin-bottom: .7rem; flex-wrap: wrap; }
.cal-year-btn-group { display: flex; align-items: center; gap: .2rem; flex: 1; min-width: 70px; }
.cal-year-btn { flex: 1; min-width: 54px; border: 1px solid var(--border); background: #fff; border-radius: 8px; padding: .5rem .3rem; font-weight: 700; font-size: .85rem; cursor: pointer; text-align: center; white-space: nowrap; }
.cal-year-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.cal-year-btn-group .pin-btn { flex-shrink: 0; padding: .3rem; font-size: .8rem; }

.cal-cat-header { display: flex; justify-content: space-between; align-items: center; font-size: .78rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .02em; font-weight: 700; margin: .4rem 0 .3rem; }
.cal-cat-header button { background: none; border: 1px solid var(--border); border-radius: 6px; min-width: 26px; min-height: 26px; padding: 0; cursor: pointer; font-size: .9rem; line-height: 1; }
.cal-category-list { display: flex; flex-direction: column; gap: .2rem; margin-bottom: .4rem; }
.cal-cat-row { display: flex; align-items: center; gap: .5rem; padding: .35rem .3rem; border-radius: 6px; cursor: pointer; }
.cal-cat-row:hover, .cal-cat-row.active { background: #eef2ef; }
.cal-cat-row.active { outline: 2px solid var(--primary); outline-offset: -2px; }
.cal-cat-swatch { width: 16px; height: 16px; border-radius: 50%; flex-shrink: 0; cursor: pointer; }
.cal-cat-name { flex: 1; font-size: .85rem; cursor: pointer; }

.cal-color-swatches { display: flex; flex-wrap: wrap; gap: .4rem; margin: .4rem 0 .8rem; }
.cal-color-swatch { width: 30px; height: 30px; border-radius: 50%; cursor: pointer; border: 3px solid #fff; box-shadow: 0 0 0 1px var(--border); }
.cal-color-swatch.active { box-shadow: 0 0 0 3px var(--primary); }

.cal-view-switch { display: flex; gap: .3rem; background: #eef1ee; border-radius: 8px; padding: .25rem; }
.cal-view-btn { background: none; border: none; padding: .45rem .9rem; border-radius: 6px; font-weight: 700; font-size: .85rem; cursor: pointer; color: var(--text-muted); }
.cal-view-btn.active { background: #fff; color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

.cal-nav { display: flex; gap: .5rem; margin: .8rem 0; }

/* Tageszelle - Basis */
.cal-day { position: relative; display: flex; flex-direction: column; border: 1px solid var(--border); background: #fff; user-select: none; touch-action: pan-y; cursor: pointer; box-sizing: border-box; }
.cal-grid-painting .cal-day { touch-action: none; }
.cal-day.empty { background: transparent; border: none; }
.cal-day-num { font-weight: 600; }
.cal-day-stripes { display: flex; flex-wrap: wrap; gap: 2px; margin-top: auto; }
.cal-stripe { display: block; height: 5px; border-radius: 2px; flex: 1 1 auto; min-width: 6px; }
.cal-weekend { background: #f4f4f2; }
.cal-holiday { background: #fde3e3; }
.cal-ferien { background: #fff6d9; }
.cal-holiday.cal-weekend, .cal-ferien.cal-weekend { background: linear-gradient(135deg, #fde3e3 50%, #f4f4f2 50%); }

/* Jahresansicht */
.cal-year-outer { display: flex; flex-direction: column; gap: 1.2rem; }
.cal-year-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
@media (max-width: 900px) { .cal-year-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 560px) { .cal-year-grid { grid-template-columns: 1fr; } }

.cal-year-stats { background: var(--card-bg); border: 1px solid var(--border); border-radius: 10px; padding: 1rem 1.2rem; }
.cal-year-stats-title { font-weight: 700; margin-bottom: .6rem; }
.cal-year-stats-list { display: flex; flex-direction: column; gap: .3rem; }
.cal-year-stats-row { display: flex; align-items: center; gap: .6rem; padding: .3rem 0; border-bottom: 1px solid var(--border); }
.cal-year-stats-row:last-child { border-bottom: none; }
.cal-year-stats-name { flex: 1; }
.cal-year-stats-count { color: var(--text-muted); font-weight: 600; font-size: .85rem; }
.cal-year-month { background: var(--card-bg); border: 1px solid var(--border); border-radius: 10px; padding: .6rem; }
.cal-year-month-title { font-weight: 700; margin-bottom: .4rem; cursor: pointer; }
.cal-year-month-title:hover { color: var(--primary); }
.cal-mini-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.cal-mini-dow { font-size: .62rem; text-align: center; color: var(--text-muted); font-weight: 700; }
.cal-day-mini { min-height: 38px; padding: 2px; border-radius: 3px; font-size: .68rem; }
.cal-day-mini .cal-day-stripes { gap: 1px; }
.cal-day-mini .cal-stripe { height: 3px; }

/* Monatsansicht */
.cal-month-grid { display: flex; flex-direction: column; gap: 2px; }
.cal-month-dow-row, .cal-month-week-row { display: grid; grid-template-columns: 40px repeat(7, 1fr); gap: 2px; }
.cal-month-dow, .cal-week-num-header { text-align: center; font-size: .78rem; font-weight: 700; color: var(--text-muted); padding: .3rem 0; }
.cal-week-num { display: flex; align-items: center; justify-content: center; font-size: .75rem; color: var(--text-muted); font-weight: 700; background: #f4f4f2; border-radius: 6px; }
.cal-day-large { min-height: 76px; padding: .4rem; border-radius: 6px; font-size: .85rem; }
@media (max-width: 780px) { .cal-day-large { min-height: 52px; font-size: .75rem; padding: .25rem; } }

/* Wochenansicht */
.cal-week-kw-label { font-weight: 700; margin-bottom: .6rem; color: var(--text-muted); }
.cal-week-row { display: grid; grid-template-columns: repeat(7, 1fr); gap: .6rem; }
@media (max-width: 780px) { .cal-week-row { grid-template-columns: 1fr; } }
.cal-week-day-col { display: flex; flex-direction: column; gap: .3rem; }
.cal-week-day-label { font-size: .8rem; font-weight: 700; color: var(--text-muted); }
.cal-day-week { min-height: 160px; padding: .6rem; border-radius: 8px; font-size: .95rem; }
.cal-day-week .cal-stripe { height: 8px; }

/* ============================================================
   v9 - Kalender: Sichtbarkeits-Checkboxen, Tages-Notizen
   ============================================================ */

.cal-cat-row input[type=checkbox] { flex-shrink: 0; }
.cal-day-note-preview {
  font-size: .68rem; color: #4a4a4a; background: rgba(255,255,255,.75); border-radius: 3px; font-weight: 600;
  padding: 1px 3px 1px 4px; margin: 2px 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.cal-day-week .cal-day-note-preview, .cal-day-large .cal-day-note-preview { white-space: normal; font-size: .74rem; }
.cal-day-note-preview-mini { font-size: .58rem; line-height: 1.1; padding: 0 1px; margin: 1px 0; }
.cal-day-mini { position: relative; }
#calNoteTextarea { width: 100%; box-sizing: border-box; border: 1px solid var(--border); border-radius: 8px; padding: .6rem; font-family: inherit; font-size: .95rem; margin: .5rem 0; }
#calNoteCategorySelect { width: 100%; border: 1px solid var(--border); border-radius: 8px; padding: .5rem; font-size: .9rem; margin: .3rem 0; background: #fff; }
.cal-note-existing-list { display: flex; flex-direction: column; gap: .3rem; margin-bottom: .6rem; max-height: 160px; overflow-y: auto; }
.cal-note-existing-row { display: flex; align-items: center; gap: .5rem; padding: .4rem .5rem; border-radius: 6px; background: #f4f5f7; cursor: pointer; }
.cal-note-existing-row:hover { background: #eaebee; }
.cal-note-existing-text { flex: 1; min-width: 0; font-size: .85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Mobiler Griff für das Kalender-Menü (nutzt den bereits vorhandenen globalen Sidebar-Mechanismus) */
.cal-mobile-handle {
  display: none; position: fixed; left: 0; top: 50%; transform: translateY(-50%); z-index: 40;
  background: var(--primary); color: #fff; border: none; border-radius: 0 8px 8px 0;
  padding: .8rem .4rem; font-size: 1rem; cursor: pointer; box-shadow: 2px 0 6px rgba(0,0,0,.15);
}
@media (max-width: 900px) { .cal-mobile-handle { display: block; } }

/* ============================================================
   v10 - Rich-Text-Editor (Notizen + Textseiten im Dokumenten-Editor)
   ============================================================ */

.rte-toolbar { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; margin: .5rem 0; padding: .4rem; background: #f4f5f7; border-radius: 8px; }
.rte-toolbar button {
  background: #fff; border: 1px solid var(--border); border-radius: 6px; min-width: 30px; height: 30px;
  font-size: .9rem; cursor: pointer; padding: 0 .4rem;
}
.rte-toolbar button:active, .rte-toolbar button.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.rte-toolbar select { border: 1px solid var(--border); border-radius: 6px; height: 30px; font-size: .82rem; padding: 0 .3rem; background: #fff; }
.rte-color-label { display: flex; align-items: center; gap: .2rem; font-size: .85rem; cursor: pointer; position: relative; }
.rte-color-label input[type=color] { width: 22px; height: 22px; border: none; padding: 0; cursor: pointer; border-radius: 4px; }

.rte-editable {
  min-height: 220px; border: 1px solid var(--border); border-radius: 8px; padding: .8rem; font-size: 1rem;
  line-height: 1.5; overflow-y: auto; background: #fff;
}
.rte-editable:empty::before { content: attr(data-placeholder); color: #9aa1ab; }
.rte-editable ul { padding-left: 1.4rem; margin: .3rem 0; }
.rte-editable:focus { outline: 2px solid var(--primary); outline-offset: -1px; }

.an2-textpage-wrap .rte-editable { min-height: 50vh; font-family: Georgia, 'Times New Roman', serif; font-size: 1.05rem; }

/* ============================================================
   v13 - Dashboard: Positionen vertauschen, Sidebar verschiebbar
   ============================================================ */

.dash-move-btns { display: flex; gap: .4rem; margin: .4rem 0; }
.dash-move-btns button { background: #f1f2f5; border: 1px solid var(--border); border-radius: 6px; font-size: .8rem; padding: .3rem .6rem; cursor: pointer; }
.dash-move-btns button:disabled { opacity: .25; cursor: default; }
.subfolder-tile { position: relative; }
.subfolder-tile .dash-move-btns { position: absolute; top: 4px; right: 4px; margin: 0; gap: 2px; }
.subfolder-tile .dash-move-btns button { padding: 2px 5px; font-size: .7rem; }

.drag-handle {
  cursor: grab; touch-action: none; flex-shrink: 0; user-select: none; -webkit-user-select: none;
  -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent;
  color: var(--text-muted); font-size: 1.1rem; letter-spacing: -2px; padding: .3rem .4rem;
  line-height: 1; display: inline-flex; align-items: center;
}
.drag-handle:active { cursor: grabbing; }
.todo-item.dragging, .task-subitem-row.dragging {
  position: relative; z-index: 5; background: var(--card-bg); box-shadow: 0 2px 10px rgba(0,0,0,.15);
  border-radius: 6px; opacity: .95; touch-action: none;
}

/* Volltext-Sprechblase bei Antippen eines gekürzten Namens (v15) */
.name-tooltip-popup {
  position: absolute; z-index: 500; background: #2a2f38; color: #fff; padding: .5rem .7rem; border-radius: 8px;
  font-size: .82rem; max-width: 260px; word-wrap: break-word; box-shadow: 0 4px 12px rgba(0,0,0,.25);
  animation: calFadeIn .12s ease-out;
}
@keyframes calFadeIn { from { opacity: 0; transform: translateY(-3px); } to { opacity: 1; transform: translateY(0); } }

/* ============================================================
   v16 - Aufgaben: Hauptansicht + Einzelanpinnen im Dashboard
   ============================================================ */

.sidebar-header-link { cursor: pointer; }
.sidebar-header-link:hover { text-decoration: underline; }

.tasks-main-list { display: flex; flex-direction: column; gap: .5rem; margin-bottom: 1rem; }
.task-main-item { display: flex; align-items: center; gap: .8rem; padding: .7rem .9rem; }
.task-main-text { flex: 1; min-width: 0; cursor: pointer; }
.task-main-title { font-weight: 600; }

.task-attachments-list { display: flex; flex-direction: column; gap: .3rem; margin-bottom: .5rem; }
.task-attachment-row { display: flex; align-items: center; gap: .5rem; background: #f4f5f7; border-radius: 6px; padding: .4rem .6rem; }
.task-attachment-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); text-decoration: none; }
.task-attachment-name:hover { text-decoration: underline; }
.task-attach-buttons { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: .8rem; }
.task-attach-buttons button:disabled { opacity: .4; cursor: default; }
.task-attach-search-results { display: flex; flex-direction: column; gap: .3rem; max-height: 260px; overflow-y: auto; margin-top: .5rem; }
.task-attach-search-item { display: flex; align-items: center; gap: .5rem; padding: .5rem .6rem; border-radius: 6px; cursor: pointer; background: #f4f5f7; }
.task-attach-search-item:hover { background: #eaebee; }

/* ============================================================
   v17 - Dashboard: eine gemeinsame, typenübergreifende Liste
   ============================================================ */

.dash-pinned-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: .8rem; align-items: start; }
.dash-pinned-grid .subfolder-tile { position: relative; min-height: 60px; }

.mb-invoice-number { font-size: .75rem; color: var(--text-muted); margin-top: .15rem; }

/* ============================================================
   Rechnungen (allgemein) - eigene Spaltenaufteilung, da weniger
   Felder als bei den Arztrechnungen
   ============================================================ */
.invoice-row { grid-template-columns: 1.1fr 1.1fr .8fr 1.2fr .8fr .9fr 1.5fr; }
@media (max-width: 1000px) {
  .invoice-row { grid-template-columns: 1fr 1fr; }
}

.scan-destination-options { display: flex; flex-direction: column; gap: .6rem; margin-top: .8rem; }
.scan-destination-options button { padding: .8rem; font-size: .95rem; text-align: left; }

/* ============================================================
   Unteraufgaben
   ============================================================ */
.task-subitems-wrap { margin: .1rem 0 .4rem 1.9rem; }
.task-subitems-toggle { display: flex; align-items: center; gap: .3rem; font-size: .78rem; color: var(--text-muted); cursor: pointer; padding: .15rem 0; }
.task-subitems-toggle .arrow { display: inline-block; width: .8rem; }
.task-subitems-body { margin-top: .2rem; }
.task-subitems-body.collapsed { display: none; }
.task-subitems-list { display: flex; flex-direction: column; gap: .2rem; }
.task-subitem-row { display: flex; align-items: center; gap: .4rem; padding: .2rem 0; }
.task-subitem-row .task-subitem-text { flex: 1; font-size: .85rem; }
.task-subitem-row.done .task-subitem-text { text-decoration: line-through; color: var(--text-muted); }
.task-subitem-row .icon-btn { flex-shrink: 0; opacity: .5; padding: .1rem .3rem; }
.task-subitem-row .icon-btn:hover { opacity: 1; }
.task-comment-input { width: 100%; box-sizing: border-box; border: 1px solid var(--border); border-radius: 6px; padding: .4rem .5rem; font-size: .82rem; font-family: inherit; resize: vertical; margin-top: .3rem; }

.task-main-wrapper { background: var(--card-bg); border: 1px solid var(--border); border-radius: 8px; }
.task-main-wrapper.due { border-left: 4px solid #e07b3f; }
.task-main-wrapper .task-subitems-wrap { margin: 0 .9rem .7rem 3.1rem; }
.task-main-wrapper .task-subitems-toggle { margin-left: -1.2rem; }

.task-subitems-list-modal { display: flex; flex-direction: column; gap: .3rem; margin-bottom: .4rem; }
.task-subitem-add-row { display: flex; gap: .4rem; margin-bottom: .8rem; }
.task-subitem-add-row input { flex: 1; border: 1px solid var(--border); border-radius: 6px; padding: .4rem .5rem; }

/* ============================================================
   Kalender: Notiz-Verknüpfung im Tagesdialog
   ============================================================ */
.cal-note-modal-header { display: flex; align-items: center; justify-content: space-between; }
.cal-day-notes-corner-btn { font-size: 1.1rem; padding: .2rem .4rem; }
.cal-day-notes-panel { background: #f4f5f7; border-radius: 8px; padding: .6rem; margin-bottom: .7rem; }
.cal-day-notes-panel.hidden { display: none; }
.cal-day-notes-linked-list { display: flex; flex-direction: column; gap: .3rem; margin-bottom: .5rem; }
.cal-day-note-linked-item { display: flex; align-items: center; justify-content: space-between; background: #fff; border-radius: 6px; padding: .35rem .5rem; }
.cal-day-note-linked-title { cursor: pointer; font-size: .85rem; }
.cal-day-note-linked-title:hover { text-decoration: underline; }
.cal-day-notes-panel input[type=text] { width: 100%; box-sizing: border-box; border: 1px solid var(--border); border-radius: 6px; padding: .4rem .5rem; margin-bottom: .4rem; }
.cal-day-notes-search-results { display: flex; flex-direction: column; gap: .3rem; max-height: 160px; overflow-y: auto; }

/* ============================================================
   Kalender: farbige Ecken für Tageskommentar / verknüpfte Notiz
   (wie ein Excel-Zellkommentar)
   ============================================================ */
.cal-day-corner { position: absolute; width: 0; height: 0; border-style: solid; }
.cal-day-corner-comment { top: 0; right: 0; border-width: 0 9px 9px 0; border-color: transparent #e8a33d transparent transparent; }
.cal-day-corner-noteLink { bottom: 0; right: 0; border-width: 0 0 9px 9px; border-color: transparent transparent #3d7ce8 transparent; }

/* ============================================================
   Kopfzeile: Offene Rechnungen/Arztrechnungen (Badge + Panel)
   ============================================================ */
.tb-icon-btn { position: relative; }
.tb-badge {
  position: absolute; top: 2px; right: 2px; min-width: 16px; height: 16px; padding: 0 3px;
  border-radius: 8px; background: #d94f4f; color: #fff; font-size: .65rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center; line-height: 1;
}
.tb-badge.hidden { display: none; }

.open-items-modal-box { width: 900px; max-width: 95vw; }
.open-items-modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; padding-bottom: .8rem; border-bottom: 1px solid var(--border); }
.open-items-modal-header h2 { margin: 0; }
.open-items-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.2rem; }
@media (max-width: 700px) {
  .open-items-grid { grid-template-columns: 1fr; }
}
.open-items-section { background: #f7f8f6; border-radius: 10px; padding: .8rem .9rem; }
.open-items-section h4 { margin: 0 0 .6rem 0; font-size: .82rem; text-transform: uppercase; letter-spacing: .03em; color: var(--text-muted); }
.open-items-list { display: flex; flex-direction: column; gap: .4rem; }
.open-items-row {
  display: flex; align-items: center; justify-content: space-between; gap: .8rem;
  background: #fff; border: 1px solid var(--border); padding: .6rem .8rem; border-radius: 8px; cursor: pointer; font-size: .9rem;
}
.open-items-row:hover { background: #eef2ef; border-color: #cfd6cf; }
.open-items-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.open-items-left { display: flex; flex-direction: column; gap: .1rem; min-width: 0; flex: 1; }
.open-items-left .open-items-title { white-space: normal; }
.open-items-month { font-size: .76rem; color: var(--text-muted); }
.open-items-amount { font-weight: 600; flex-shrink: 0; white-space: nowrap; }
.open-items-status { color: #b3392c; font-size: .82rem; flex-shrink: 0; font-weight: 600; white-space: nowrap; }
.open-items-empty { color: var(--text-muted); font-size: .85rem; padding: .4rem .1rem; margin: 0; }
