:root {
  --bg: #fbf9f561;
  --text: #0f1115;
  --muted: #7a7f87;
  --surface: #ffffff;
  --surface-strong: #e5e8ec;
  --primary: #000000;
  --primary-2: #555555;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
  --shadow-md: 0 8px 16px rgba(16, 24, 40, 0.08);
}

[data-theme="dark"] {
  --bg: #0f1115;
  --text: #f5f7fb;
  --muted: #a0a4ad;
  --surface: #171a21;
  --surface-strong: #232733;
  --primary: #e5e7eb;
  --primary-2: #a3a3a3;
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
  background-color: var(--bg);
}

body {
  margin: 0;
 
  color: var(--text);
  font: 16px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
    Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", Arial,
    "Apple Color Emoji", "Segoe UI Emoji";
}

.layout { display: grid; grid-template-columns: 300px 1fr 360px; min-height: 100vh; gap: 0; }
.layout.collapse-left { grid-template-columns: 108px 1fr 360px; }

.sidebar {color: var(--text); position: relative; }
.sidebar.collapsed .sidebar-inner { padding: 12px 10px; }
.sidebar.collapsed .sidebar-section,
.sidebar.collapsed .sidebar-profile,
.sidebar.collapsed #space-limits { display: none; }
.sidebar.collapsed .actions-row { display: none; }
.sidebar.collapsed .input-row.no-icon select { padding-left: 8px; }
.sidebar.collapsed { width: 60px; }

.sidebar-profile .limits-text{ display: none; }

/* Left sidebar collapse button positioning */
#btn-toggle-left-desktop { width: 22px; position: absolute; right: -12px; top: 50%; margin-top: -18px; }
@media (max-width: 500px) { #btn-toggle-left-desktop { display: none; } }
.sidebar-inner {
  padding: 20px;
    position: sticky;
    top: 8px;
    display: flex;
    flex-direction: column;
    min-height: calc(100vh - 16px);
}
.sidebar-title { font-weight: 700; margin: 12px 0; color: var(--text); }
.add-page { width: 100%; padding: 10px 12px; border-radius: 999px; border: 0; background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: #fff; cursor: pointer; box-shadow: var(--shadow-md); }
.icon-btn { width: 36px; height: 36px; display: inline-grid; place-items: center; border-radius: 10px; border: 1px solid var(--surface-strong); background: var(--surface); cursor: pointer; }
.icon-btn.primary { background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: #fff; border: 0; }
.icon { width: 16px; height: 16px; fill: currentColor; }
.input-row { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 8px; }
.input-row.no-icon { grid-template-columns: 1fr auto; }
.actions-row { display: flex; gap: 8px; align-items: center; margin: 8px 0; }
.sidebar-section { margin-bottom: 12px; }
.page-title-input { width: 100%; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--surface-strong); background: var(--surface); color: var(--text); }
.space-limits { font-size: 12px; color: var(--muted); }
.delete-page { width: 100%; margin-top: 10px; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--surface-strong); background: #fff; cursor: pointer; color: #b00020; }
.pages-list { list-style: none; padding: 0; margin: 14px 0 0; }
.pages-list li { padding: 10px 12px; border-radius: 12px; cursor: pointer; color: var(--text); display: flex; align-items: center; gap: 8px; }
.pages-list li:hover { background: var(--surface); }
.pages-list li.active { background: #f2f0ea; color: var(--text);  }

.page-item-title { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.page-item-menu { border: 1px solid var(--surface-strong); background: #fff; border-radius: 8px; padding: 1px 5px; cursor: pointer; display: none; }

.pages-list li:hover .page-item-menu { display: block; }

.page-rename-input { flex: 1 1 auto; padding: 6px 8px; border: 1px solid var(--surface-strong); border-radius: 8px; }
.context-menu { position: absolute; background: #fff; border: 1px solid var(--surface-strong); border-radius: 8px; box-shadow: var(--shadow-md); padding: 6px; display: grid; gap: 6px; }
.context-menu button { border: 0; background: transparent; padding: 6px 8px; text-align: left; cursor: pointer; }

.sidebar-profile { margin-top: auto; padding-top: 14px; border-top: 1px solid var(--surface-strong); display: grid; gap: 8px; }
.profile-row { display: grid; grid-template-columns: 32px 1fr auto auto; align-items: center; gap: 8px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: #111; color: #fff; display: grid; place-items: center; font-weight: 700; }
.limits-text { font-size: 12px; color: var(--muted); }
.badge { display: inline-block; padding: 2px 6px; border-radius: 999px; font-size: 11px; background: var(--surface); border: 1px solid var(--surface-strong); color: var(--text);}
.logout-btn { padding: 8px 12px; border-radius: 10px; border: 1px solid var(--surface-strong); background: #fff; cursor: pointer; width: 100%; }
.team-actions { display: grid; gap: 8px; margin-top: 10px; }
.invite-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; }

#profile-email{ overflow: hidden; font-size: 14px; }

.app {
  width: 100%;
  padding: 24px 40px 140px;
  margin: 0 auto;
  background: #fff;
  border: solid 1px var(--surface-strong);
  margin-top: 24px;
  border-radius: 24px;
}

.rightbar { background: transparent; }
.rightbar-inner { 
  padding: 20px 20px 20px 20px;
  position: sticky;
  top: 0;
  max-height: 100vh;
  overflow-y: auto;
 }
.widget { padding: 16px 0; border-bottom: 1px solid var(--surface-strong); }
.widget-title { font-weight: 600; font-size: 20px; margin-bottom: 8px; cursor: pointer; user-select: none; }
.widget.collapsed .today-list { display: none; }
.today-list { list-style: none; margin: 0; padding: 0; }
.today-list li { display: flex; align-items: center; gap: 6px; font-size: 13px; padding: 4px 4px; }
.today-list li.done { opacity: 0.5; }
.today-list input[type="checkbox"] {  }
.today-delete { display: none; border: 1px solid var(--surface-strong); background: var(--surface); color: var(--text); border-radius: 8px; padding: 4px 8px; cursor: pointer; }
.today-group-title { display: block; font-weight: 600; font-size: 16px; padding: 14px 4px 4px; }

.toolbar {
  position: fixed;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  z-index: 30;
  display: flex;
  gap: 8px;
  align-items: center;
  width: calc(100% - 32px);
  max-width: 900px;
  padding: 10px;
  background: #40404012;
  margin-left: -30px;
  backdrop-filter: saturate(180%) blur(10px);
  border: 0;
  border-radius: 16px;
  box-shadow: var(--shadow-sm);
}

/* Theme toggle */
.theme-toggle { display: none; grid-template-columns: auto 1fr; align-items: center; gap: 8px; margin-bottom: 8px; }
.theme-switch { position: relative; width: 42px; height: 24px; background: var(--surface-strong); border-radius: 999px; cursor: pointer; }
.theme-switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; background: #fff; border-radius: 50%; transition: transform 0.2s ease; }
[data-theme="dark"] .theme-switch::after { transform: translateX(18px); }

.toolbar button {
  appearance: none;
  border: 1px solid var(--surface-strong);
  background: var(--surface);
  padding: 8px 12px;
  border-radius: 999px;
  cursor: pointer;
  color: var(--text);
}
.toolbar button:active {
  transform: translateY(1px);
}
.toolbar-sep {
  width: 1px;
  height: 24px;
  background: var(--surface-strong);
  margin: 0 4px;
}
.autosave { color: var(--muted); margin-left: auto; font-size: 13px; }


.btn-logout{
  display: none;
  width: 32px;
  height: 32px;
}

.sidebar-profile:hover .btn-logout{ display: inline-grid; }


/* Mobile */
@media (max-width: 500px) {
  .layout { grid-template-columns: 1fr; }
  .rightbar { position: fixed; z-index: 20; top: 0; right: 0; height: 100vh; width: 80%; max-width: 360px; transform: translateX(100%); transition: transform 0.2s ease; box-shadow: var(--shadow-md); background: #fff; border-left: 1px solid var(--surface-strong); }
  .rightbar.open { transform: translateX(0); }
  .sidebar { position: fixed; z-index: 20; top: 0; left: 0; height: 100vh; width: 80%; max-width: 320px; transform: translateX(-100%); transition: transform 0.2s ease; box-shadow: var(--shadow-md); margin: 0; border-radius: 0; }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.2); opacity: 0; pointer-events: none; transition: opacity 0.2s ease; z-index: 15; }
  .sidebar-backdrop.show { opacity: 1; pointer-events: auto; }
  .rightbar-backdrop { z-index: 15; }
  .toolbar { bottom: 72px; gap: 6px; }
  .mobile-fab { position: fixed; z-index: 25; bottom: 16px; width: 48px; height: 48px; border-radius: 999px; border: 1px solid var(--surface-strong); background: #fff; display: grid; place-items: center; box-shadow: var(--shadow-md); }
  .mobile-fab.mobile-left { left: 16px; }
  .mobile-fab.mobile-right { right: 16px; }
}

/* Focus mode */
.focus-overlay { backdrop-filter: blur(8px); position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: none; align-items: center; justify-content: center; z-index: 100; padding: 24px; }
.focus-overlay.show { display: flex; }
.focus-panel { width: min(720px, 96vw); max-height: min(80vh, 800px); overflow: auto; background: var(--surface); color: var(--text); border: 1px solid var(--surface-strong); border-radius: 20px; box-shadow: var(--shadow-md); padding: 16px; }
.focus-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.focus-title { font-weight: 600; font-size: 18px; }
.focus-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.focus-list li { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1px solid var(--surface-strong); border-radius: 12px; background: var(--surface); }
.focus-list li.done { opacity: 0.6; }
.focus-list .task-title { flex: 1 1 auto; }

/* Default hidden mobile FABs on desktop */
@media (min-width: 501px) {
  .mobile-fab { display: none; }
}

.editor {
  outline: none;
  max-width: 900px;
  margin: 0 auto;
}

.editor img {
  max-width: 100%;
  height: auto;
  border-radius: 12px;
  display: block;
  box-shadow: var(--shadow-sm);
}

/* Typography */
.editor h1 {
  font-size: 52px;
  line-height: 1.1;
  margin: 28px 0 16px;
  letter-spacing: -0.02em;
}
.editor h2 {
  font-size: 28px;
  margin: 28px 0 12px;
}
.editor p { margin: 10px 0; }
.editor ul { margin: 10px 0 10px 24px; }
.editor li { margin: 6px 0; }

/* Task block */
.task {
  background: var(--surface);
  border: 1px solid var(--surface-strong);
  border-radius: 10px;
  padding: 8px;
  margin: 12px 0;
  box-shadow: var(--shadow-sm);
}

.task.dragging { opacity: 0.4; }
.task-drop-marker {
  height: 4px;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  border-radius: 4px;
  margin: 8px 0;
}

.task-header {
  display: flex;
  align-items: center;
  gap: 10px;
}

.task-title {
  font-weight: 600;
  outline: none;
  font-size: 14px;
}

.task-deadline {
  margin-left: auto;
  color: var(--muted);
  border: 0;
  background: transparent;
}

.task-delete {
  border: 1px solid var(--surface-strong);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  width: 32px;
  height: 32px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  cursor: pointer;
}

/* .task-desc removed */

.task.completed { opacity: 0.3; }

/* Prevent controls from inheriting editor styles */
.task input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--primary); }

/* Contenteditable caret visibility inside styled blocks */
[contenteditable="true"]:empty:before {
  content: attr(data-placeholder);
  color: var(--muted);
}

/* Auth modal */
dialog#auth-modal { border: 0; border-radius: 16px; padding: 0; box-shadow: var(--shadow-md); }
.auth-form { display: flex; flex-direction: column; gap: 10px; padding: 16px; min-width: 320px; }
.auth-form h3 { margin: 0 0 4px 0; }
.auth-form input { padding: 10px 12px; border-radius: 10px; border: 1px solid var(--surface-strong); }
.auth-actions { display: flex; gap: 8px; }
.auth-actions button { padding: 8px 12px; border-radius: 10px; border: 1px solid var(--surface-strong); background: #fff; cursor: pointer; }
.auth-error { color: #b00020; font-size: 13px; min-height: 18px; }
.teams-info { border: 1px solid var(--surface-strong); border-radius: 10px; padding: 8px; background: #fff; }
.teams-form { min-width: 520px; display: grid; gap: 12px; padding: 16px; }
.teams-form h3 { margin: 0; }
.teams-form .row { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.teams-form .footer { display: flex; justify-content: space-between; gap: 8px; }
.btn-danger { color: #b00020; border: 1px solid var(--surface-strong); background: #fff; border-radius: 10px; padding: 8px 12px; }
.member-item { display: flex; align-items: center; justify-content: space-between; padding: 6px 8px; border-radius: 8px; }
.member-item:hover { background: var(--surface); }
.member-remove { border: 1px solid var(--surface-strong); background: #fff; border-radius: 8px; padding: 4px 8px; cursor: pointer; }


