:root {
  --bg: #f5f5f5;
  --panel: #ffffff;
  --panel-alt: #f8f8f8;
  --accent: #3498db;
  --accent-dark: #2980b9;
  --accent-light: #e3f2fd;
  --text: #2c3e50;
  --text-light: #7f8c8d;
  --muted: #95a5a6;
  --border: #e0e0e0;
  --important: #e74c3c;
  --success: #27ae60;
  --warning: #f39c12;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.08);
  --shadow-md: 0 2px 8px rgba(0,0,0,0.12);
  --shadow-lg: 0 4px 16px rgba(0,0,0,0.15);
  --radius-sm: 4px;
  --radius-md: 8px;
  --transition: all 0.2s ease;
}

html, body { height: 100%; margin: 0; }
* { box-sizing: border-box; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Noto Sans', sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  line-height: 1.5;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 1.5rem;
  background: var(--panel);
  color: var(--text);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
  z-index: 10;
}
.topbar-left { display: flex; align-items: center; gap: 0.75rem; }
.topbar-center {
  flex: 1;
  text-align: center;
  margin: 0;
  font-size: 1rem;
  font-weight: 500;
  color: var(--text);
}
.topbar-right { display: flex; align-items: center; gap: 0.75rem; }
.topbar a {
  color: var(--text-light);
  text-decoration: none;
  font-weight: 400;
  font-size: 0.875rem;
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius-sm);
  transition: var(--transition);
}
.topbar a:hover {
  color: var(--accent);
  background: var(--accent-light);
}
.brand {
  font-weight: 600;
  font-size: 1.25rem;
  color: var(--accent);
  letter-spacing: -0.5px;
}
.who {
  margin-right: 0.5rem;
  opacity: 0.85;
  font-size: 0.875rem;
  color: var(--muted);
}

main {
  padding: 1rem;
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: auto;
}

.layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 1rem;
  flex: 1;
  min-height: 0;
  overflow: visible;
  transition: grid-template-columns 0.2s ease;
}
.layout.sidebar-collapsed {
  grid-template-columns: 1fr;
}
.layout.sidebar-collapsed .folders { display: none; }
.sidebar-toggle {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.25rem 0.6rem;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text-light);
  transition: var(--transition);
}
.sidebar-toggle:hover {
  background: var(--accent-light);
  color: var(--accent);
  border-color: var(--accent);
}

.folders, .notes {
  background: var(--panel);
  padding: 1rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.folders {
  overflow-y: auto;
  max-height: 100vh;
}
.notes {
  overflow: visible;
}
.notes.notes-cards { min-height: auto; }

.folders h2, .notes h2 {
  margin: 0 0 0.75rem;
  color: var(--text);
  font-size: 0.875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.folders ul { list-style: none; padding: 0; margin: 0; }
.folders .subfolders {
  margin: 0;
  padding-left: 0.4rem;
  border-left: 1px solid var(--border);
  display: block;
}
.folders .folder-row {
  display: flex;
  align-items: center;
  gap: 0.15rem;
}
.folders .folder-link { flex: 1; }
.folders .folder-link.has-children { font-weight: 600; }
.folder-drop:not(.expanded) > .subfolders { display: none; }
.folders li {
  padding: 0 0.4rem;
  border-radius: var(--radius-sm);
  margin-bottom: 0;
  font-size: 0.85rem;
  line-height: 1.45;
  transition: var(--transition);
}
.folders li a {
  display: inline-block;
  padding: 0.05rem 0.3rem;
  border-radius: var(--radius-sm);
  color: var(--text);
  text-decoration: none;
  font-size: 0.85rem;
  transition: var(--transition);
}
.folders li a:hover {
  background: var(--accent-light);
  color: var(--accent);
}
.folders li a.active {
  background: var(--accent);
  color: #fff;
  font-weight: 500;
}
.folders a.active {
  background: var(--accent);
  color: #fff;
  padding: 0.1rem 0.3rem;
  border-radius: var(--radius-sm);
}
.folders li.active a { color: #fff; }

.inline { display: inline; }
.new-folder { margin-top: 0.75rem; display: flex; gap: 0.4rem; }
.new-folder input {
  flex: 1;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  padding: 0.4rem 0.6rem;
  font-size: 0.85rem;
  background: var(--panel);
  transition: var(--transition);
}
.new-folder input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.2);
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-bottom: 0.75rem;
  flex-shrink: 0;
}
.view-toggle a {
  padding: 0.3rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--text-light);
  font-size: 0.8rem;
  background: var(--panel);
  transition: var(--transition);
}
.view-toggle a.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.btn {
  padding: 0.4rem 0.9rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  text-decoration: none;
  font-weight: 500;
  font-size: 0.85rem;
  cursor: pointer;
  transition: var(--transition);
}
.btn:hover {
  background: var(--accent-dark);
  transform: translateY(-1px);
}
.btn:active {
  transform: translateY(0);
}

/* Card Grid */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 0.75rem;
  overflow: visible;
  align-content: start;
  padding-right: 0.25rem;
}
.card-wrap {
  position: relative;
  min-height: 200px;
  height: auto;
}
.card-wrap.span-2 {
  grid-column: span 2;
}
.card-wrap.span-3 {
  grid-column: span 3;
}
.card-wrap.height-2 {
  grid-row: span 2;
  min-height: 400px;
}
.card-wrap.span-2.height-2 {
  grid-column: span 2;
  grid-row: span 2;
  min-height: 400px;
}
.card-wrap.height-3 {
  grid-row: span 3;
  min-height: 600px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 0;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 100%;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
}
.card:active {
  transform: none;
}
.card.dragging { opacity: 0.5; }
.card.drag-over { outline: 2px dashed var(--accent); }
.card-wrap.drop-before::before,
.card-wrap.drop-after::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--accent);
  border-radius: 2px;
  z-index: 5;
  pointer-events: none;
}
.card-wrap.drop-before::before { left: -6px; }
.card-wrap.drop-after::after { right: -6px; }
.folder-drop.drag-over {
  background: var(--accent);
  color: #fff;
}
.folders li a {
  text-decoration: none;
  color: var(--text);
  display: block;
}

.card.expanded {
  height: auto;
  min-height: 200px;
  max-height: 90vh;
  overflow-y: auto;
  z-index: 30;
  box-shadow: var(--shadow-lg);
  border-color: var(--accent);
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
.card.expanded[data-double-height="true"] { min-height: 400px; }
.card.editing {
  height: auto;
  min-height: 200px;
  max-height: 90vh;
  overflow-y: auto;
  z-index: 30;
}
.card.editing[data-double-height="true"],
.card.editing[data-height="2"] { min-height: 400px; }
.card.editing[data-height="3"],
.card.expanded[data-height="3"] { min-height: 600px; }
.card.expanded[data-height="2"] { min-height: 400px; }
.card.completed { opacity: 0.6; }


.card.important { border-left: 3px solid var(--important); }
.card.prio-1 { border-top: 3px solid #95a5a6; }
.card.prio-2 { border-top: 3px solid #f39c12; }
.card.prio-3 { border-top: 3px solid #27ae60; }
.card.prio-4 { border-top: 3px solid #8e44ad; }
.card.prio-5 { border-top: 3px solid var(--important); }

.card header {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  margin-bottom: 0.3rem;
  min-height: 1rem;
}
.badge {
  background: var(--accent);
  color: #fff;
  font-size: 0.65rem;
  padding: 0.15rem 0.4rem;
  border-radius: 3px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

/* New note badge */
.card.new-card header .badge {
  background: var(--success);
}

.md {
  flex: 1;
  line-height: 1.5;
  font-size: 0.875rem;
  color: var(--text);
}
.md h1, .md h2, .md h3 {
  color: var(--accent-dark);
  margin: 0.4rem 0 0.3rem;
  font-weight: 600;
}
.md h1 { font-size: 1.15rem; }
.md h2 { font-size: 1rem; }
.md h3 { font-size: 0.9rem; }
.md p { margin: 0.3rem 0; }
.md ul, .md ol {
  padding-left: 1.25rem;
  margin: 0.3rem 0;
}
.md code {
  background: var(--panel-alt);
  padding: 0.15rem 0.35rem;
  border-radius: 3px;
  font-size: 0.8rem;
  font-family: 'Fira Code', 'DejaVu Sans Mono', Consolas, 'Courier New', monospace;
}
.md pre {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  margin: 0.5rem 0;
  overflow-x: auto;
  white-space: pre;
  font-family: 'Fira Code', 'DejaVu Sans Mono', Consolas, 'Courier New', monospace;
  font-size: 0.8rem;
  line-height: 1.35;
  tab-size: 4;
}
.md pre code {
  background: transparent;
  color: inherit;
  padding: 0;
  border-radius: 0;
  font-family: inherit;
  font-size: inherit;
  white-space: pre;
}
.md blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 0.75rem;
  color: var(--muted);
  font-style: italic;
  margin: 0.5rem 0;
}
.md a { color: var(--accent); }
.md li.task-item { list-style: none; margin-left: -1.25rem; }
.md input.task-check {
  margin-right: 0.4rem;
  vertical-align: -0.1rem;
  cursor: pointer;
}
.card .edit-form {
  display: none;
  flex-direction: column;
  gap: 0.5rem;
  flex: 1;
}
.card.editing .md { display: none; }
.card.editing .assignees { display: none; }
.card.editing .edit-form { display: flex; }
.card.editing footer { display: none; }
.card .edit-form textarea {
  flex: 1;
  min-height: 6rem;
  font-family: inherit;
  font-size: 0.85rem;
  border: none;
  background: transparent;
  border-radius: 0;
  padding: 0;
  resize: none;
  color: var(--text);
}
.card .edit-form textarea:focus {
  outline: none;
  border: none;
  box-shadow: none;
}
.card .edit-row {
  display: flex;
  gap: 0.4rem;
  align-items: center;
  flex-wrap: wrap;
}
.card .edit-row select { font-size: 0.75rem; }
.card .edit-row button { font-size: 0.75rem; }

.card header {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  margin-bottom: 0.3rem;
  min-height: 1rem;
}
.card footer {
  font-size: 0.75rem;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin-top: 0.5rem;
  border-top: 1px solid var(--border);
  padding-top: 0.4rem;
}
.actions {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
  margin-top: 0.25rem;
}
.actions button, .actions a {
  font-size: 0.75rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.2rem 0.5rem;
  cursor: pointer;
  text-decoration: none;
  color: var(--text-light);
  transition: var(--transition);
}
.actions button:hover, .actions a:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* Note Table View */
.note-table-wrap { flex: 1; overflow-y: auto; }
.note-table { width: 100%; border-collapse: collapse; }
.note-table th {
  background: var(--accent);
  color: #fff;
  padding: 0.5rem;
  text-align: left;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  position: sticky;
  top: 0;
}
.note-table td {
  border-bottom: 1px solid var(--border);
  padding: 0.5rem;
  font-size: 0.85rem;
}
.note-table tr.important { background: #fdecea; }
.note-table tr.prio-1 td:first-child { border-left: 3px solid #95a5a6; }
.note-table tr.prio-2 td:first-child { border-left: 3px solid #f39c12; }
.note-table tr.prio-3 td:first-child { border-left: 3px solid #27ae60; }
.note-table tr.prio-4 td:first-child { border-left: 3px solid #8e44ad; }
.note-table tr.prio-5 td:first-child { border-left: 3px solid var(--important); }
.note-table tr:hover { background: var(--panel-alt); }
.note-table .clickable-row { cursor: pointer; }
.note-table .detail-row td {
  background: var(--panel);
  padding: 0.75rem;
  border-top: none;
}
.note-table tr.completed { opacity: 0.6; }
.detail-row .edit-form { display: none; }
.detail-row.editing .md { display: none; }
.detail-row.editing .edit-form { display: block; }
.detail-row .edit-form textarea {
  width: 100%;
  min-height: 6rem;
  font-family: inherit;
  font-size: 0.85rem;
  border: none;
  background: transparent;
  padding: 0;
  resize: none;
  color: var(--text);
}
.detail-row .edit-form textarea:focus { outline: none; }

.btn-completed {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-light);
  cursor: pointer;
  font-size: 0.8rem;
  padding: 0.2rem 0.5rem;
  transition: var(--transition);
}
.btn-completed.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* Forms */
.login-box, .users-page {
  max-width: 720px;
}
.form-box {
  max-width: 960px;
  margin: 1.5rem auto;
  background: var(--panel);
  padding: 1.5rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.login-box form, .form-box form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.login-box input, .form-box input, .form-box textarea, .form-box select {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.75rem;
  font-family: inherit;
  font-size: 0.9rem;
  background: var(--panel);
  transition: var(--transition);
}
.login-box input:focus, .form-box input:focus, .form-box textarea:focus, .form-box select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.2);
}
.login-box button, .form-box button {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.5rem 1.25rem;
  font-weight: 500;
  cursor: pointer;
  font-size: 0.9rem;
  align-self: flex-start;
  transition: var(--transition);
}
.login-box button:hover, .form-box button:hover {
  background: var(--accent-dark);
  transform: translateY(-1px);
}
.login-box button:active, .form-box button:active {
  transform: translateY(0);
}

/* Empty States */
.empty {
  color: var(--muted);
  font-style: italic;
  text-align: center;
  padding: 2rem;
  font-size: 0.875rem;
}

/* Context Menu */
.ctx-menu {
  position: absolute;
  z-index: 100;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  padding: 0.3rem;
  min-width: 160px;
  display: none;
}
.ctx-menu button {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  padding: 0.4rem 0.75rem;
  font-size: 0.8rem;
  cursor: pointer;
  color: var(--text);
  border-radius: var(--radius-sm);
  transition: var(--transition);
}
.ctx-menu button:hover {
  background: var(--accent-light);
  color: var(--accent);
}
.ctx-menu hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 0.3rem 0;
}
.ctx-sub { position: relative; }
.ctx-submenu {
  display: none;
  position: absolute;
  left: 100%;
  top: 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  min-width: 140px;
  padding: 0.3rem;
}
.ctx-sub:hover .ctx-submenu { display: block; }
#share-submenu { max-height: 320px; overflow-y: auto; min-width: 180px; }
#share-submenu label:hover { background: rgba(52, 152, 219, 0.1); }
.ctx-menu[data-mode="empty"] [data-card-only] { display: none; }
.ctx-menu[data-mode="card"] [data-empty-only] { display: none; }
.flash-banner {
  position: fixed;
  top: 0.75rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 4px solid #d97706;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  padding: 0.6rem 1rem;
  font-size: 0.85rem;
  max-width: 32rem;
}
.readonly-hint {
  display: block;
  padding: 0.4rem 0.75rem;
  font-size: 0.8rem;
  color: var(--text-muted, #888);
  font-style: italic;
  cursor: default;
}

/* Status & utility classes */
.ok { color: var(--success); font-weight: 500; }
.conf { font-weight: 600; color: var(--accent-dark); }

/* Users */
.user-form {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}
.user-form input, .user-form select {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.4rem 0.6rem;
  background: var(--panel);
  transition: var(--transition);
}
.user-form input:focus, .user-form select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.2);
}
.user-table {
  width: 100%;
  border-collapse: collapse;
}
.user-table th, .user-table td {
  border: 1px solid var(--border);
  padding: 0.5rem;
  font-size: 0.85rem;
}

button { cursor: pointer; }

.label-short { display: none; }

@media (max-width: 700px) {
  .layout { grid-template-columns: 1fr; }
  /* Sidebar als Overlay über der Pinnwand */
  /* Sidebar als Overlay unterhalb der Topbar */
  .folders {
    position: fixed;
    top: 52px;
    left: 0;
    bottom: 0;
    width: 16rem;
    max-width: 82vw;
    z-index: 150;
    overflow-y: auto;
    box-shadow: 0 0 2rem rgba(0, 0, 0, 0.35);
  }
  .layout:not(.sidebar-collapsed) .folders { transform: none; }
  .layout.sidebar-collapsed .folders { display: none; }
  .card-grid { grid-template-columns: 1fr; }
  /* alle Karten untereinander, ohne Spalten-Spanning */
  .card-wrap { grid-column: 1 / -1 !important; }
  .topbar { padding: 0.5rem; }
  .topbar-center { display:none; }
}

/* Scrollbar styling */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: var(--bg);
}
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--muted);
}

/* Focus visible for accessibility */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Smooth transitions for all interactive elements */
button, a, input, select, textarea {
  transition: var(--transition);
}

/* Live sync badge */
#sync-badge {
  position: fixed;
  top: 0.6rem;
  right: 0.6rem;
  z-index: 200;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.35rem 0.7rem;
  font-size: 0.8rem;
  cursor: pointer;
  box-shadow: var(--shadow-lg);
}

@media (max-width: 700px) {
  .label-long { display: none; }
  .label-short { display: inline; }
}
