:root {
  --bg: #eef1f5;
  --card: #ffffff;
  --text: #1c2733;
  --muted: #64748b;
  --accent: #2563eb;
  --border: #dbe2ea;
  --danger: #dc2626;
  --shadow: 0 1px 3px rgba(16, 24, 40, .1);
  --radius: 10px;
}
[data-theme="dark"] {
  --bg: #0f172a;
  --card: #1e293b;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #60a5fa;
  --border: #334155;
  --shadow: 0 1px 3px rgba(0, 0, 0, .4);
}
* { box-sizing: border-box; margin: 0; }
body {
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text); min-height: 100vh;
  background-size: cover; background-position: center; background-attachment: fixed;
}
.hidden { display: none !important; }
button { cursor: pointer; font: inherit; }
input, select, textarea { font: inherit; color: var(--text); }

/* ---- auth ---- */
.auth-screen { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.auth-card {
  background: var(--card); padding: 32px; border-radius: 14px; box-shadow: var(--shadow);
  width: 320px; display: flex; flex-direction: column; gap: 12px; border: 1px solid var(--border);
}
.auth-card h1 { font-size: 22px; text-align: center; }
.auth-card input {
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg);
}
.auth-card button {
  padding: 10px; background: var(--accent); color: #fff; border: 0; border-radius: 8px; font-weight: 600;
}
.auth-error { color: var(--danger); font-size: 13px; text-align: center; min-height: 1em; }

/* ---- topbar ---- */
#topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 10px 18px; background: var(--card); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 50; flex-wrap: wrap;
}
.topbar-left { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
#app-title { font-weight: 700; font-size: 16px; margin-right: 8px; }
#page-tabs { display: flex; gap: 4px; }
.page-tab {
  padding: 6px 14px; border-radius: 8px; border: 0; background: transparent; color: var(--muted);
  font-weight: 600;
}
.page-tab.active { background: var(--accent); color: #fff; }
.page-tab .tab-edit { margin-left: 7px; font-size: 11px; opacity: .75; }
.page-tab .tab-edit:hover { opacity: 1; }
.page-tab:hover:not(.active) { background: var(--bg); }
#search-form { display: flex; gap: 0; flex: 1; max-width: 480px; min-width: 220px; }
#search-engine {
  border: 1px solid var(--border); border-right: 0; border-radius: 8px 0 0 8px;
  background: var(--bg); padding: 0 6px; max-width: 90px;
}
#search-input {
  flex: 1; padding: 8px 12px; border: 1px solid var(--border); border-radius: 0 8px 8px 0;
  background: var(--bg); outline: none;
}
.topbar-right { display: flex; align-items: center; gap: 10px; }
#clock { color: var(--muted); font-variant-numeric: tabular-nums; }
.btn {
  padding: 7px 12px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--card); color: var(--text); font-weight: 600;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.icon-btn {
  border: 0; background: transparent; font-size: 17px; color: var(--muted);
  padding: 4px 8px; border-radius: 6px;
}
.icon-btn:hover { background: var(--bg); color: var(--text); }
.icon-btn.active { color: #fff; background: var(--accent); }

/* Ansichtsmodus (Standard): alle Edit-Affordances aus — nur der ✎-Toggle schaltet sie frei */
body:not(.edit-mode) .widget-actions,
body:not(.edit-mode) .item-actions,
body:not(.edit-mode) .tab-edit,
body:not(.edit-mode) .widget-add-row:not(.bm-more),
body:not(.edit-mode) #add-widget,
body:not(.edit-mode) #add-page { display: none !important; }
body:not(.edit-mode) .widget-header { cursor: default; }
body.edit-mode .widget { outline: 1px dashed color-mix(in srgb, var(--accent) 45%, transparent); }

/* ---- board (GridStack) ---- */
#board { padding: 14px; max-width: 1600px; margin: 0 auto; }
.grid-stack-item-content { overflow: hidden !important; }
.grid-stack-item .widget { height: auto; }
/* Einheitliche Widget-Höhe: Widget füllt die Zelle, Inhalt scrollt innen */
.grid-stack.fixed-h .grid-stack-item .widget { height: 100%; display: flex; flex-direction: column; }
.grid-stack.fixed-h .widget-body { flex: 1 1 auto; overflow-y: auto; min-height: 0; }
.grid-stack-item.ui-draggable-dragging .widget { box-shadow: 0 8px 30px rgba(0,0,0,.25); }
.gs-placeholder .placeholder-content { border: 2px dashed var(--accent); border-radius: var(--radius); background: transparent; }
.widget {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  border: 1px solid var(--border); overflow: hidden;
  /* var(--text) HIER auswerten, nicht am body — sonst erben Kinder die Theme-Farbe
     statt der pro Widget gesetzten Kontrastfarbe */
  color: var(--text);
}
.widget-header {
  display: flex; align-items: center; gap: 8px; padding: 9px 12px;
  border-bottom: 1px solid var(--border); cursor: grab;
}
.widget-header:active { cursor: grabbing; }
.widget-title { font-weight: 700; flex: 1; font-size: 13.5px; }
.widget-actions { display: flex; gap: 2px; opacity: 0; transition: opacity .15s; }
.widget:hover .widget-actions { opacity: 1; }
.widget-actions .icon-btn { font-size: 13px; padding: 2px 6px; }
.widget-body { padding: 6px 0; }
.sortable-ghost { opacity: .4; }
.sortable-drag { opacity: .9; }

/* bookmarks */
.bm-list { list-style: none; padding: 0; }
.bm-item { display: flex; align-items: center; }
.bm-item a {
  flex: 1; display: flex; align-items: center; gap: 9px; padding: 6px 12px;
  color: var(--text); text-decoration: none; overflow: hidden;
}
.bm-item a:hover { background: var(--bg); }
.bm-item img { width: 16px; height: 16px; border-radius: 3px; flex-shrink: 0; }
.bm-item .bm-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bm-item .item-actions { opacity: 0; display: flex; padding-right: 6px; }
.bm-item:hover .item-actions { opacity: 1; }
/* bookmarks — icon grid view */
.bm-icons {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr));
  gap: 4px; padding: 8px 10px;
}
.bm-tile { position: relative; }
.bm-tile a {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 10px 4px 8px; border-radius: 8px; text-align: center;
}
.bm-tile img { width: 28px; height: 28px; border-radius: 6px; }
.bm-tile .bm-title {
  font-size: 11.5px; line-height: 1.25; max-width: 100%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.bm-tile .item-actions {
  position: absolute; top: 2px; right: 2px; padding: 0;
  background: var(--card); border-radius: 6px;
}

.widget-add-row {
  display: block; width: 100%; text-align: left; padding: 6px 12px; border: 0;
  background: transparent; color: var(--muted); font-size: 13px;
}
.widget-add-row:hover { color: var(--accent); background: var(--bg); }

/* notes */
.notes-body { padding: 4px 12px 10px; }
.notes-view { min-height: 40px; line-height: 1.55; cursor: text; padding: 4px 0; }
.notes-view h2, .notes-view h3, .notes-view h4 { margin: 4px 0; }
.notes-view ul { margin: 2px 0; padding-left: 20px; }
.notes-view code { background: var(--bg); padding: 1px 5px; border-radius: 4px; font-size: 12.5px; }
.notes-view a { color: var(--accent); }
.notes-empty { color: var(--muted); }
.notes-body textarea {
  width: 100%; min-height: 110px; border: 0; background: transparent; resize: vertical;
  outline: none; line-height: 1.5;
}

/* todo */
.todo-list { list-style: none; padding: 0; }
.todo-item { display: flex; align-items: center; gap: 8px; padding: 5px 12px; }
.todo-item:hover { background: var(--bg); }
.todo-item input[type=checkbox] { accent-color: var(--accent); }
.todo-item span { flex: 1; }
.todo-item.done span { text-decoration: line-through; color: var(--muted); }
.todo-item .item-actions { opacity: 0; }
.todo-item:hover .item-actions { opacity: 1; }
.todo-add { display: flex; padding: 6px 12px; }
.todo-add input {
  flex: 1; border: 0; border-top: 1px solid var(--border); background: transparent;
  padding: 6px 0 2px; outline: none;
}

/* rss */
.rss-list { list-style: none; padding: 0; }
.rss-list a {
  display: block; padding: 6px 12px; color: var(--text); text-decoration: none;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.rss-list a:hover { background: var(--bg); color: var(--accent); }
.rss-list .rss-date { color: var(--muted); font-size: 11.5px; display: block; }
.rss-empty { padding: 8px 12px; color: var(--muted); }

/* weather */
.weather-body { padding: 12px; display: flex; align-items: center; gap: 14px; }
.weather-temp { font-size: 30px; font-weight: 700; }
.weather-meta { color: var(--muted); font-size: 13px; }
.weather-icon { font-size: 34px; }
.weather-days { display: flex; gap: 10px; padding: 0 12px 12px; }
.weather-day { text-align: center; font-size: 11.5px; color: var(--muted); }
.weather-day b { display: block; color: var(--text); }

/* iframe */
.iframe-body iframe { width: 100%; border: 0; display: block; }

/* ---- modal ---- */
#modal-root {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .55); z-index: 100;
  display: flex; align-items: flex-start; justify-content: center; padding-top: 8vh;
}
.modal {
  background: var(--card); border-radius: 14px; padding: 22px; width: 440px; max-width: 94vw;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .3); border: 1px solid var(--border);
  max-height: 80vh; overflow: auto; position: relative;
}
.modal-close {
  position: absolute; top: 12px; right: 12px; border: 0; background: transparent;
  color: var(--muted); font-size: 15px; cursor: pointer; padding: 4px 8px; border-radius: 6px;
}
.modal-close:hover { background: var(--bg); color: var(--text); }
.modal h2 { font-size: 17px; margin-bottom: 14px; }
.modal .field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.modal .field label { font-size: 12.5px; font-weight: 600; color: var(--muted); }
.modal input[type=text], .modal input[type=url], .modal input[type=password], .modal input[type=number],
.modal select, .modal textarea {
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); outline: none;
}
.modal .modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.modal .danger { color: var(--danger); border-color: var(--danger); }
.type-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.type-grid button {
  padding: 14px 10px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg);
  font-weight: 600; color: var(--text);
}
.type-grid button:hover { border-color: var(--accent); color: var(--accent); }
.token-row { display: flex; gap: 8px; align-items: center; }
.token-row code {
  flex: 1; overflow: hidden; text-overflow: ellipsis; background: var(--bg);
  padding: 6px 8px; border-radius: 6px; font-size: 12px; white-space: nowrap;
}
.settings-sep { border: 0; border-top: 1px solid var(--border); margin: 16px 0; }
.icon-gallery { display: flex; flex-wrap: wrap; gap: 6px; max-height: 120px; overflow-y: auto; }
.icon-gallery img {
  width: 26px; height: 26px; border-radius: 6px; cursor: pointer;
  border: 2px solid var(--border); padding: 2px; background: var(--bg);
}
.icon-gallery img:hover { border-color: var(--accent); }
.icon-gallery img.selected { border-color: var(--accent); }
.icon-tile { position: relative; display: inline-block; }
.icon-del {
  position: absolute; top: -7px; right: -7px; display: none;
  width: 16px; height: 16px; line-height: 13px; padding: 0;
  border: 0; border-radius: 50%; background: var(--danger); color: #fff;
  font-size: 10px; cursor: pointer;
}
.icon-tile:hover .icon-del { display: block; }
.preset-row { display: flex; gap: 6px; flex-wrap: wrap; }
.preset {
  width: 34px; height: 26px; border-radius: 6px; border: 1px solid var(--border); cursor: pointer;
}
.preset-none { background: var(--bg); color: var(--muted); font-size: 12px; }
.preset-img { width: 46px; height: 30px; background-size: cover; background-position: center; }

@media (max-width: 800px) {
  #board { grid-template-columns: 1fr !important; }
  #topbar { gap: 8px; }
}

/* ---- Kontextmenü (start.me-Stil) ---- */
.ctx-menu {
  position: fixed; z-index: 300; min-width: 230px; padding: 6px 0;
  background: var(--card); color: var(--text); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: 0 10px 36px rgba(0, 0, 0, .28);
}
.ctx-item { padding: 8px 18px; cursor: pointer; font-size: 13.5px; white-space: nowrap; }
.ctx-item:hover { background: var(--bg); }
.ctx-item.danger { color: var(--danger); }
.ctx-sep { border-top: 1px solid var(--border); margin: 5px 0; }
