/* NoteHub — Oberflaeche auf Basis der Material-3-Farbtokens aus Styles/material-designs/. */

:root {
  --radius: 12px;
  --pane-gap: 1px;
  --shadow: 0 6px 18px rgb(0 0 0 / 12%);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: 'Sofia Sans', system-ui, sans-serif;
  font-size: 15px;
  background: var(--md-sys-color-surface);
  color: var(--md-sys-color-on-surface);
}

.material-symbols-rounded {
  font-size: 20px;
  line-height: 1;
  user-select: none;
}

/* ---------- Grundgeruest ---------- */

.shell {
  display: grid;
  grid-template-rows: 52px 1fr;
  height: 100vh;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px 0 12px;
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
  background: var(--md-sys-color-surface-container-low);
}

.topbar form { display: flex; }

.topbar-spacer { flex: 1; }

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-right: 8px;
  font-size: 19px;
  font-weight: 600;
  color: var(--md-sys-color-primary);
  white-space: nowrap;
}

.save-state {
  min-width: 90px;
  text-align: right;
  font-size: 13px;
  color: var(--md-sys-color-on-surface-variant);
}

.save-state.is-saving { font-style: italic; }

.user-name {
  font-size: 13px;
  color: var(--md-sys-color-on-surface-variant);
}

/* Ohne min-height:0 gilt fuer das Rasterelement min-height:auto: der Inhalt waechst dann ueber
   die Fensterhoehe hinaus und der Editor bekommt nie zu wenig Platz -- es entsteht also auch
   nie ein Rollbalken. */
.content {
  min-height: 0;
  overflow: hidden;
}

/* ---------- Buttons ---------- */

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--md-sys-color-on-surface-variant);
  cursor: pointer;
}

.icon-button:hover { background: var(--md-sys-color-surface-container-high); }
.icon-button:disabled { opacity: .35; cursor: default; }
.icon-button.small { width: 26px; height: 26px; }
.icon-button.small .material-symbols-rounded { font-size: 16px; }

.button {
  padding: 8px 16px;
  border: 1px solid var(--md-sys-color-outline);
  border-radius: 999px;
  background: var(--md-sys-color-surface-container);
  color: var(--md-sys-color-on-surface);
  font: inherit;
  cursor: pointer;
}

.button:hover { background: var(--md-sys-color-surface-container-high); }
.button:disabled { opacity: .4; cursor: default; }

.button.danger {
  background: var(--md-sys-color-error);
  border-color: var(--md-sys-color-error);
  color: var(--md-sys-color-on-error);
}

.link-button {
  margin: 8px 12px;
  padding: 6px;
  border: none;
  background: none;
  color: var(--md-sys-color-primary);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

/* ---------- Seitenlayouts ---------- */

.workspace {
  display: grid;
  grid-template-columns: 220px 300px minmax(0, 1fr) 340px;
  height: 100%;
}

.pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  border-right: 1px solid var(--md-sys-color-outline-variant);
  overflow: hidden;
}

.todo-pane { border-right: none; }

/* Kein eigener Hintergrund: surface-container-lowest ist im hellen Thema reines Weiss und
   stach gegen das Creme der uebrigen Flaeche ab. Die Bereiche trennen die Linien. */

.pane-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
}

.pane-header h2 {
  flex: 1;
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--md-sys-color-on-surface-variant);
}

/* ---------- Listen ---------- */

.list {
  flex: 1;
  margin: 0;
  padding: 6px;
  overflow-y: auto;
  list-style: none;
}

.list-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: var(--radius);
  cursor: pointer;
}

.list-item:hover { background: var(--md-sys-color-surface-container); }

.list-item.selected {
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
}

.list-item-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.list-item-actions { display: none; gap: 2px; }
.list-item:hover .list-item-actions { display: flex; }

.list-empty {
  padding: 16px 10px;
  color: var(--md-sys-color-on-surface-variant);
  font-size: 13px;
}

.note-item { flex-direction: column; align-items: stretch; gap: 2px; }

.note-item-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}

/* Ohne min-height/min-width:0 laesst ein Flex-Element sich nicht unter seine Inhaltsbreite
   druecken -- der Titel liefe dann ueber das Datum. */
.note-item-head .list-item-title { min-width: 0; }

/* Im Todo-Eintrag ist der Titel kein Flex-Kind, sondern steckt in einem Block. Ohne die
   Blockdarstellung greifen overflow und text-overflow auf dem span nicht. */
.todo-item-body .list-item-title {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.timestamp {
  flex-shrink: 0;
  font-size: 12px;
  color: var(--md-sys-color-on-surface-variant);
}

.timestamp.overdue { color: var(--md-sys-color-error); font-weight: 600; }

.note-item-meta,
.note-item-excerpt {
  font-size: 12px;
  color: var(--md-sys-color-on-surface-variant);
}

.note-item-excerpt { line-height: 1.4; }

.note-item-excerpt mark,
mark {
  padding: 0 2px;
  border-radius: 3px;
  background: var(--md-sys-color-tertiary-container);
  color: var(--md-sys-color-on-tertiary-container);
}

/* ---------- Suche ---------- */

.search-box {
  display: flex;
  align-items: center;
  flex: 1;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--md-sys-color-surface-container);
  color: var(--md-sys-color-on-surface-variant);
}

.search-box input {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  color: var(--md-sys-color-on-surface);
  font: inherit;
  outline: none;
}

.search-scope {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  font-size: 13px;
  color: var(--md-sys-color-on-surface-variant);
}

/* ---------- Todos ---------- */

.todo-new {
  /* Flex mit Umbruch statt festem Raster: das Datumsfeld bringt eine vom Browser
     vorgegebene Mindestbreite mit, im Raster wurde der Knopf dadurch abgeschnitten. */
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
}

.todo-new input:not([type='date']) { flex: 1 1 100%; }
.todo-new input[type='date'] { flex: 1 1 auto; }
.todo-new .button { flex: 0 0 auto; }

.todo-new input {
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--radius);
  background: var(--md-sys-color-surface-container-lowest);
  color: var(--md-sys-color-on-surface);
  font: inherit;
}

.todo-item-body { flex: 1; min-width: 0; }

.todo-item.done .list-item-title {
  text-decoration: line-through;
  color: var(--md-sys-color-on-surface-variant);
}

/* ---------- Editorbereich ---------- */

.editor-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
}

.editor-header .todo-done {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
}

/* Bilanz bzw. Fehlermeldung der Daily-Fortschreibung, rechts neben dem Titel. */
.daily-state {
  flex: 0 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  color: var(--md-sys-color-on-surface-variant);
}

.daily-state.is-error { color: var(--md-sys-color-error); }

.note-title {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  color: var(--md-sys-color-on-surface);
  font-family: inherit;
  font-size: 22px;
  font-weight: 600;
  outline: none;
}

.due-date {
  padding: 6px 10px;
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--radius);
  background: var(--md-sys-color-surface-container-lowest);
  color: var(--md-sys-color-on-surface);
  font: inherit;
}

.inline-input {
  flex: 1;
  min-width: 0;
  padding: 4px 6px;
  border: 1px solid var(--md-sys-color-primary);
  border-radius: 6px;
  background: var(--md-sys-color-surface-container-lowest);
  color: var(--md-sys-color-on-surface);
  font: inherit;
}

.placeholder-text {
  margin: 40px;
  color: var(--md-sys-color-on-surface-variant);
}

/* ---------- TipTap ---------- */

.editor-toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 2px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
}

/* Gilt nur fuer die Werkzeugknoepfe selbst. Ohne den Ausschluss geraten auch die Knoepfe in den
   Aufklappmenues (Farbe, Link) auf 30x30 und ihre Beschriftung schiebt sich uebereinander. */
.editor-toolbar button:not(.button):not(.editor-color-swatch):not(.editor-emoji-tab):not(.editor-emoji-item) {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--md-sys-color-on-surface-variant);
  cursor: pointer;
}

.editor-toolbar button:not(.button):not(.editor-emoji-tab):not(.editor-emoji-item):hover { background: var(--md-sys-color-surface-container-high); }

.editor-toolbar button.is-active {
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
}

.editor-toolbar-divider {
  width: 1px;
  height: 20px;
  margin: 0 6px;
  background: var(--md-sys-color-outline-variant);
}

.editor-color,
.editor-link,
.editor-emoji { position: relative; }

.editor-emoji-menu {
  position: absolute;
  z-index: 20;
  top: 34px;
  left: 0;
  display: none;
  flex-direction: column;
  gap: 6px;
  width: max-content;
  padding: 8px;
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--radius);
  background: var(--md-sys-color-surface-container-high);
  box-shadow: var(--shadow);
}

.editor-emoji-menu.is-open { display: flex; }

.editor-emoji-tabs {
  display: flex;
  gap: 4px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
}

.editor-emoji-tab {
  padding: 4px 10px;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--md-sys-color-on-surface-variant);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.editor-emoji-tab.is-active {
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
}

.editor-emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, 32px);
  gap: 2px;
}

.editor-emoji-item {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 8px;
  background: transparent;
  font-size: 19px;
  line-height: 1;
  cursor: pointer;
}

.editor-emoji-item:hover { background: var(--md-sys-color-surface-container-highest); }

.editor-link-menu {
  position: absolute;
  z-index: 20;
  top: 34px;
  left: 0;
  display: none;
  flex-wrap: nowrap;
  gap: 6px;
  width: max-content;
  max-width: calc(100vw - 32px);
  padding: 8px;
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--radius);
  background: var(--md-sys-color-surface-container-high);
  box-shadow: var(--shadow);
}

.editor-link-menu.is-open { display: flex; }

/* Feste Breite statt Flex-Basis: die Breite des Menues wird ueber max-content bestimmt, und
   dabei zaehlt die Wunschbreite eines Eingabefelds nicht mit. */
.editor-link-menu input {
  flex: 0 0 auto;
  width: 280px;
  padding: 6px 10px;
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--radius);
  background: var(--md-sys-color-surface-container-lowest);
  color: var(--md-sys-color-on-surface);
  font: inherit;
}

.editor-link-menu .button { flex: 0 0 auto; padding: 6px 12px; white-space: nowrap; }

.rich-editor a {
  color: var(--md-sys-color-primary);
  text-decoration: underline;
  cursor: pointer;
}

.editor-color-menu {
  position: absolute;
  z-index: 20;
  top: 34px;
  left: 0;
  /* Bewusst ueber eine Klasse statt ueber [hidden]: display:grid wuerde die
     Browservorgabe [hidden] { display: none } ueberstimmen. */
  display: none;
  grid-template-columns: repeat(4, 24px);
  gap: 6px;
  padding: 8px;
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--radius);
  background: var(--md-sys-color-surface-container-high);
  box-shadow: var(--shadow);
}

.editor-color-menu.is-open { display: grid; }

.editor-color-swatch {
  width: 24px;
  height: 24px;
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: 50%;
  color: var(--md-sys-color-on-surface-variant);
  cursor: pointer;
}

.rich-editor {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px 24px 60px;
}

.rich-editor .ProseMirror { outline: none; line-height: 1.6; }
.rich-editor .ProseMirror > * + * { margin-top: .45em; }

.rich-editor h1,
.rich-editor h2,
.rich-editor h3 { margin: .5em 0 .2em; line-height: 1.3; }

.rich-editor h1 { font-size: 1.7em; }
.rich-editor h2 { font-size: 1.4em; }
.rich-editor h3 { font-size: 1.2em; }

/* Ohne diese Regeln greifen die Browservorgaben (1em Aussenabstand an ul/ol und an
   jedem Absatz innerhalb eines Listenpunkts) und die Eintraege stehen weit auseinander. */
.rich-editor ul,
.rich-editor ol { margin: .25em 0; padding-left: 1.4em; }

.rich-editor li { margin: 0; }
.rich-editor li > p { margin: .1em 0; }
.rich-editor li > ul,
.rich-editor li > ol { margin: .1em 0; }

.rich-editor blockquote {
  margin-left: 0;
  padding-left: 14px;
  border-left: 3px solid var(--md-sys-color-outline);
  color: var(--md-sys-color-on-surface-variant);
}

.rich-editor pre {
  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--md-sys-color-surface-container-high);
  overflow-x: auto;
  font-family: ui-monospace, 'Cascadia Code', Consolas, monospace;
  font-size: 13px;
}

.rich-editor code {
  padding: 1px 4px;
  border-radius: 4px;
  background: var(--md-sys-color-surface-container-high);
  font-family: ui-monospace, 'Cascadia Code', Consolas, monospace;
  font-size: .9em;
}

.rich-editor pre code { padding: 0; background: none; }

.rich-editor hr {
  border: none;
  border-top: 1px solid var(--md-sys-color-outline-variant);
}

.rich-editor img { max-width: 100%; border-radius: 8px; }

.rich-editor ul[data-type='taskList'] { list-style: none; padding-left: 2px; }

.rich-editor ul[data-type='taskList'] li {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

/* Die Zeilenhoehe des ersten Absatzes als Hoehe des Kaestchens: so sitzt es mittig zur
   ersten Textzeile statt darueber. */
.rich-editor ul[data-type='taskList'] li > label {
  display: flex;
  align-items: center;
  height: 1.6em;
  margin: 0;
  flex: 0 0 auto;
}

.rich-editor ul[data-type='taskList'] li > label input { margin: 0; }

.rich-editor ul[data-type='taskList'] li > div {
  flex: 1 1 auto;
  min-width: 0;
}

.rich-editor ul[data-type='taskList'] li > div > p { margin: 0; }

.rich-editor .ProseMirror p.is-editor-empty:first-child::before {
  content: attr(data-placeholder);
  float: left;
  height: 0;
  color: var(--md-sys-color-on-surface-variant);
  pointer-events: none;
}

/* ---------- Dialog ---------- */

.dialog-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgb(0 0 0 / 45%);
}

.dialog {
  width: min(440px, 90vw);
  padding: 24px;
  border-radius: 20px;
  background: var(--md-sys-color-surface-container-high);
  color: var(--md-sys-color-on-surface);
  box-shadow: var(--shadow);
}

.dialog h2 { margin: 0 0 8px; font-size: 20px; }
.dialog p { margin: 0 0 20px; color: var(--md-sys-color-on-surface-variant); }

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* ---------- Anmeldung ---------- */

.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--md-sys-color-surface-container-low);
}

.login-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: min(360px, 90vw);
  padding: 32px;
  border-radius: 20px;
  background: var(--md-sys-color-surface-container-lowest);
  box-shadow: var(--shadow);
}

.login-card h1 {
  margin: 0 0 16px;
  color: var(--md-sys-color-primary);
  text-align: center;
}

.login-card label {
  margin-top: 10px;
  font-size: 13px;
  color: var(--md-sys-color-on-surface-variant);
}

.login-card input {
  padding: 10px 12px;
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--radius);
  background: var(--md-sys-color-surface-container-lowest);
  color: var(--md-sys-color-on-surface);
  font: inherit;
}

.login-card button {
  margin-top: 20px;
  padding: 11px;
  border: none;
  border-radius: 999px;
  background: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.login-error {
  margin: 0;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: var(--md-sys-color-error-container);
  color: var(--md-sys-color-on-error-container);
  font-size: 13px;
}

/* ---------- Fehlerhinweis von Blazor ---------- */

#blazor-error-ui {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  padding: 12px 16px;
  background: var(--md-sys-color-error-container);
  color: var(--md-sys-color-on-error-container);
  box-shadow: var(--shadow);
}

#blazor-error-ui .dismiss {
  position: absolute;
  top: 8px;
  right: 12px;
  cursor: pointer;
}


/* ---------- Aufklappbereiche in der TopBar ---------- */

/* Die Knoepfe erscheinen erst, wenn der zugehoerige Bereich aus dem Raster faellt. */
.panel-toggle {
  display: none;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: 999px;
  background: transparent;
  color: var(--md-sys-color-on-surface-variant);
  font: inherit;
  font-size: 14px;
  white-space: nowrap;
  cursor: pointer;
}

.panel-toggle:hover { background: var(--md-sys-color-surface-container); }

.panel-toggle span:not(.material-symbols-rounded) {
  max-width: 22ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.panel-toggle.is-open {
  background: var(--md-sys-color-secondary-container);
  border-color: transparent;
  color: var(--md-sys-color-on-secondary-container);
}

.panel-backdrop {
  position: fixed;
  inset: 52px 0 0 0;
  z-index: 25;
}

/* Gemeinsame Darstellung eines aus dem Raster genommenen Bereichs: schwebend unter der TopBar. */
.workspace .pane.as-panel {
  position: fixed;
  z-index: 30;
  top: 52px;
  width: 320px;
  max-height: min(70vh, 640px);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: 0 0 var(--radius) var(--radius);
  background: var(--md-sys-color-surface-container-low);
  box-shadow: var(--shadow);
  visibility: hidden;
}

.workspace .pane.as-panel.is-visible { visibility: visible; }

/* ---------- Umbruchpunkte ----------
   1500: Notizbuecher, 1300: Notizenliste, 1000: Todos wandern in die TopBar. */

@media (max-width: 1500px) {
  .workspace { grid-template-columns: 300px minmax(0, 1fr) 340px; }
  .panel-toggle.for-notebooks { display: inline-flex; }

  .notebook-pane {
    position: fixed;
    background: var(--md-sys-color-surface-container-low);
    z-index: 30;
    top: 52px;
    left: 8px;
    width: 300px;
    max-height: min(70vh, 640px);
    border: 1px solid var(--md-sys-color-outline-variant);
    border-radius: 0 0 var(--radius) var(--radius);
    box-shadow: var(--shadow);
    visibility: hidden;
  }

  .workspace.panel-notebooks .notebook-pane { visibility: visible; }
}

@media (max-width: 1300px) {
  .workspace { grid-template-columns: minmax(0, 1fr) 340px; }
  .panel-toggle.for-notes { display: inline-flex; }

  .note-list-pane {
    position: fixed;
    background: var(--md-sys-color-surface-container-low);
    z-index: 30;
    top: 52px;
    left: 8px;
    width: 360px;
    max-height: min(70vh, 640px);
    border: 1px solid var(--md-sys-color-outline-variant);
    border-radius: 0 0 var(--radius) var(--radius);
    background: var(--md-sys-color-surface-container-low);
    box-shadow: var(--shadow);
    visibility: hidden;
  }

  .workspace.panel-notes .note-list-pane { visibility: visible; }
}

@media (max-width: 1000px) {
  .workspace { grid-template-columns: minmax(0, 1fr); }
  .panel-toggle.for-todos { display: inline-flex; }

  .todo-pane {
    position: fixed;
    background: var(--md-sys-color-surface-container-low);
    z-index: 30;
    top: 52px;
    right: 8px;
    width: min(380px, calc(100vw - 16px));
    max-height: min(70vh, 640px);
    border: 1px solid var(--md-sys-color-outline-variant);
    border-radius: 0 0 var(--radius) var(--radius);
    box-shadow: var(--shadow);
    visibility: hidden;
  }

  .workspace.panel-todos .todo-pane { visibility: visible; }
}

/* Auf schmalen Fenstern tritt der Name hinter die Symbole zurueck. */
@media (max-width: 820px) {
  .panel-toggle span:not(.material-symbols-rounded) { display: none; }
  .panel-toggle { padding: 6px 10px; }
  .user-name { display: none; }
  .save-state { min-width: 0; }
}
