:root {
  /* Shared color for the left toolbar and the top search bar */
  --chrome: #1f2733;
  --chrome-hover: #2b3645;
  --chrome-border: #313c4c;
  --chrome-text: #c7d0db;
  --chrome-muted: #8995a5;

  --bg: #ffffff;
  --content-bg: #fbfcfd;
  --text: #1b2430;
  --muted: #6b7682;
  --border: #e4e8ee;
  --accent: #3b82f6;
  --accent-soft: #e8f0fe;
  --danger: #e5484d;

  --sidebar-w: 64px;
  --topbar-h: 56px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

.app {
  display: grid;
  grid-template-rows: var(--topbar-h) 1fr;
  grid-template-areas:
    "topbar"
    "main";
  height: 100vh;
}

/* ---------- Sidebar (left vertical toolbar) ---------- */
.sidebar {
  grid-area: sidebar;
  background: var(--chrome);
  color: var(--chrome-text);
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 0;
  overflow: visible; /* let the recent-notes flyout escape the rail */
  z-index: 20;
}

.sidebar-top {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  flex: 0 0 auto;
}

/* vertical icon rail */
.rail {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding-top: 12px;
  width: 100%;
}

.rail-item {
  position: relative;
}

.rail-btn {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--chrome-text);
  cursor: pointer;
  display: grid;
  place-items: center;
}

.rail-btn:hover {
  background: var(--chrome-hover);
  color: #fff;
}

/* hover flyout listing the most recent notes (drops down from the top bar) */
.flyout {
  position: absolute;
  left: 0;
  top: calc(100% + 8px);
  width: 240px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 10px 34px rgba(0, 0, 0, 0.18);
  padding: 6px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-4px);
  transition: opacity 0.12s ease, transform 0.12s ease, visibility 0.12s;
  z-index: 50;
}

/* invisible bridge so the cursor can travel from icon to flyout */
.flyout::before {
  content: "";
  position: absolute;
  left: 0;
  top: -10px;
  width: 100%;
  height: 10px;
}

.rail-item:hover .flyout,
.flyout:hover {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

/* keep the flyout hidden after a note is opened, until the cursor leaves */
.flyout.closed {
  opacity: 0 !important;
  visibility: hidden !important;
}

.flyout-title {
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 6px 8px 4px;
}

.avatar {
  width: 34px;
  height: 34px;
  padding: 0;
  overflow: hidden;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  display: grid;
  place-items: center;
  text-transform: uppercase;
}

.avatar:hover {
  filter: brightness(1.08);
}

.avatar-img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  display: block;
}

.avatar-wrap {
  position: relative;
}

.avatar-menu {
  position: absolute;
  left: 0;
  top: calc(100% + 8px);
  width: 220px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 10px 34px rgba(0, 0, 0, 0.18);
  padding: 12px;
  z-index: 60;
}

.avatar-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.avatar-email {
  font-size: 12.5px;
  color: var(--muted);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.avatar-action {
  display: block;
  width: 100%;
  text-align: left;
  margin-top: 8px;
  padding: 7px 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
}

.avatar-action:first-of-type {
  margin-top: 12px;
}

.avatar-action:hover {
  background: #eef1f5;
  border-color: var(--accent);
}

.avatar-logout {
  display: block;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  color: var(--danger);
  font-size: 13.5px;
  text-decoration: none;
}

.avatar-logout:hover {
  text-decoration: underline;
}

/* transient toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  background: #1f2733;
  color: #fff;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 13.5px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.25);
  z-index: 2000;
  max-width: 80vw;
}

/* ---------- Login overlay ---------- */
.login-overlay {
  position: fixed;
  inset: 0;
  background: var(--chrome);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

/* the [hidden] attribute must win over display:flex above */
.login-overlay[hidden] {
  display: none;
}

.login-card {
  background: var(--bg);
  border-radius: 14px;
  padding: 40px 36px;
  width: min(360px, 90vw);
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.login-logo {
  font-size: 26px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
}

.login-sub {
  color: var(--muted);
  font-size: 14px;
  margin: 8px 0 26px;
}

.login-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  height: 44px;
  background: #fff;
  color: #3c4043;
  border: 1px solid #dadce0;
  border-radius: 8px;
  text-decoration: none;
  font-size: 14.5px;
  font-weight: 500;
}

.login-btn:hover {
  background: #f7f8f8;
  border-color: #d2d5d9;
}

.g-mark {
  font-family: Arial, Helvetica, sans-serif;
  font-weight: 700;
  font-size: 18px;
  line-height: 1;
  color: #4285f4;
}

.login-error {
  color: var(--danger);
  font-size: 13px;
  margin: 16px 0 0;
}

.recent-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 360px;
  overflow-y: auto;
}

.recent-list li {
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 13.5px;
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.recent-list li:hover {
  background: var(--accent-soft);
}

.recent-list li.active {
  background: var(--accent-soft);
  color: var(--accent);
}

.recent-list .empty {
  color: var(--muted);
  font-size: 13px;
  padding: 8px 10px;
  cursor: default;
}

/* ---------- Topbar (search) ---------- */
.topbar {
  grid-area: topbar;
  background: var(--chrome);
  border-bottom: 1px solid var(--chrome-border);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  position: relative;
  z-index: 30;
}

.search {
  position: relative;
  flex: 1 1 auto;
  max-width: 560px;
}

.search-icon {
  position: absolute;
  left: 15px;
  top: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  color: var(--chrome-muted);
  font-size: 21px;
  line-height: 1;
  pointer-events: none;
}

.search-input {
  width: 100%;
  height: 38px;
  padding: 0 16px 0 42px;
  border-radius: 19px;
  border: 1px solid var(--chrome-border);
  background: var(--chrome-hover);
  color: var(--chrome-text);
  font-size: 14px;
  outline: none;
}

.search-input::placeholder {
  color: var(--chrome-muted);
}

.search-input:focus {
  border-color: var(--accent);
  background: #2f3b4c;
}

.search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.14);
  max-height: 320px;
  overflow-y: auto;
  z-index: 30;
  padding: 4px;
}

.search-results .res {
  padding: 9px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
}

.search-results .res:hover,
.search-results .res.active {
  background: var(--accent-soft);
}

.search-results .res .res-date {
  display: block;
  font-size: 11.5px;
  color: var(--muted);
  margin-top: 2px;
}

.search-results .none {
  padding: 12px;
  color: var(--muted);
  font-size: 14px;
}

/* ---------- Main editing area ---------- */
.main {
  grid-area: main;
  background: var(--content-bg);
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}

.tabs {
  display: flex;
  align-items: stretch;
  gap: 2px;
  padding: 0 8px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  min-height: 40px;
}

.tab {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px 0 14px;
  font-size: 13.5px;
  color: var(--muted);
  border-right: 1px solid var(--border);
  cursor: pointer;
  white-space: nowrap;
  min-width: 140px;
  max-width: 220px;
  background: transparent;
}

.tab .tab-title {
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tab.active {
  color: var(--text);
  background: var(--content-bg);
  box-shadow: inset 0 -2px 0 var(--accent);
}

.tab .tab-close {
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  padding: 2px 4px;
  border-radius: 4px;
  opacity: 0;
  transition: opacity 0.12s ease;
}

.tab:hover .tab-close {
  opacity: 1;
}

.tab .tab-close:hover {
  background: var(--border);
  color: var(--text);
}

/* ---------- Editor toolbar ---------- */
.editor-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.toolbar-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
}

.toolbar-groups {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-wrap: wrap;
}

/* ---------- Tag bar (left side of the editor toolbar) ---------- */
.tagbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
}

.tag-chips {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: thin;
}

.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 4px 3px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12.5px;
  white-space: nowrap;
  line-height: 1;
}

.tag-chip .tag-x {
  border: none;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 0 2px;
  border-radius: 50%;
  opacity: 0.7;
}

.tag-chip .tag-x:hover {
  opacity: 1;
  background: rgba(59, 130, 246, 0.18);
}

.tag-add {
  position: relative;
  flex: 0 0 auto;
}

.tag-add-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 26px;
  padding: 0 10px;
  border: 1px dashed var(--border);
  background: transparent;
  border-radius: 999px;
  color: var(--muted);
  font-size: 12.5px;
  cursor: pointer;
  white-space: nowrap;
}

.tag-add-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.tag-add-plus {
  font-size: 14px;
  line-height: 1;
}

.tag-popover {
  position: absolute;
  left: 0;
  top: calc(100% + 6px);
  width: 240px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 10px 34px rgba(0, 0, 0, 0.16);
  padding: 6px;
  z-index: 45;
}

.tag-pop-list {
  max-height: 240px;
  overflow-y: auto;
}

.tag-pop-empty {
  color: var(--muted);
  font-size: 13px;
  padding: 8px 10px;
}

.tag-pop-row {
  display: flex;
  align-items: center;
  gap: 2px;
  border-radius: 6px;
}

.tag-pop-row:hover {
  background: #f3f5f8;
}

.tag-pop-name {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  border: none;
  background: transparent;
  cursor: pointer;
  text-align: left;
  font-size: 13.5px;
  color: var(--text);
  padding: 7px 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tag-pop-row.on .tag-pop-name {
  color: var(--accent);
}

.tag-check {
  width: 14px;
  flex: 0 0 auto;
  color: var(--accent);
  font-size: 12px;
}

.tag-pop-act {
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  padding: 4px 6px;
  border-radius: 5px;
  flex: 0 0 auto;
}

.tag-pop-act:hover {
  background: var(--border);
  color: var(--text);
}

.tag-pop-act.danger:hover {
  background: #fdecec;
  color: var(--danger);
}

.tag-edit-input {
  flex: 1 1 auto;
  min-width: 0;
  height: 28px;
  margin: 2px 0;
  padding: 0 8px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  font-size: 13.5px;
  outline: none;
}

.tag-pop-new {
  display: flex;
  gap: 6px;
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid var(--border);
}

.tag-new-input {
  flex: 1 1 auto;
  min-width: 0;
  height: 30px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  outline: none;
}

.tag-new-input:focus {
  border-color: var(--accent);
}

.tag-new-btn {
  flex: 0 0 auto;
  height: 30px;
  padding: 0 12px;
  border: none;
  background: var(--accent);
  color: #fff;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
}

.tag-new-btn:hover {
  filter: brightness(1.05);
}

/* disable the tag bar when no note is open */
.main.no-note .tagbar {
  opacity: 0.4;
  pointer-events: none;
}

.tb-btn {
  min-width: 30px;
  height: 30px;
  padding: 0 8px;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 6px;
  color: var(--text);
  font-size: 13.5px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.tb-btn:hover {
  background: #eef1f5;
}

.tb-btn.is-active {
  background: var(--accent-soft);
  color: var(--accent);
}

.tb-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.tb-sep {
  width: 1px;
  height: 20px;
  background: var(--border);
  margin: 0 6px;
}

.toolbar-menu {
  position: relative;
}

.menu-btn {
  font-size: 18px;
}

.menu-dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.14);
  min-width: 150px;
  padding: 4px;
  z-index: 40;
}

.menu-item {
  width: 100%;
  text-align: left;
  padding: 9px 10px;
  border: none;
  background: transparent;
  border-radius: 6px;
  font-size: 14px;
  cursor: pointer;
  color: var(--text);
}

.menu-item:hover {
  background: #eef1f5;
}

.menu-item.danger {
  color: var(--danger);
}

.menu-item.danger:hover {
  background: #fdecec;
}

/* ---------- Editor surface ---------- */
.editor-wrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}

.editor {
  width: 100%;
  padding: 28px 40px 120px;
}

.editor .ProseMirror {
  outline: none;
  min-height: 60vh;
  font-size: 16px;
  line-height: 1.35;
}

.editor .ProseMirror > * + * {
  margin-top: 0.2em;
}

.editor .ProseMirror h1 {
  font-size: 1.7em;
  font-weight: 700;
}

.editor .ProseMirror h2 {
  font-size: 1.35em;
  font-weight: 700;
}

.editor .ProseMirror ul,
.editor .ProseMirror ol {
  padding-left: 1.4em;
}

.editor .ProseMirror blockquote {
  border-left: 3px solid var(--border);
  padding-left: 1em;
  color: var(--muted);
}

.editor .ProseMirror img {
  max-width: 100%;
  height: auto;
  border-radius: 6px;
  display: block;
  margin: 0.5em 0;
}

.editor .ProseMirror img.ProseMirror-selectednode {
  outline: 2px solid var(--accent);
}

/* resizable image */
.editor .ProseMirror .img-resizer {
  position: relative;
  display: inline-block;
  line-height: 0;
  max-width: 100%;
}

.editor .ProseMirror .img-resizer img {
  margin: 0.5em 0;
}

.img-resize-handle {
  position: absolute;
  right: 6px;
  bottom: 12px;
  width: 12px;
  height: 12px;
  background: var(--accent);
  border: 2px solid #fff;
  border-radius: 3px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  cursor: nwse-resize;
  opacity: 0;
  transition: opacity 0.12s ease;
}

.editor .ProseMirror .img-resizer:hover .img-resize-handle {
  opacity: 1;
}

.editor .ProseMirror code {
  background: #eef1f5;
  border-radius: 4px;
  padding: 0.1em 0.35em;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.9em;
}

/* Placeholder for an empty document */
.editor .ProseMirror p.is-editor-empty:first-child::before {
  content: attr(data-placeholder);
  float: left;
  color: var(--muted);
  pointer-events: none;
  height: 0;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  color: var(--muted);
}

.empty-new {
  padding: 9px 16px;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
}

.empty-new:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.save-status {
  position: absolute;
  right: 16px;
  bottom: 12px;
  font-size: 12px;
  color: var(--muted);
  pointer-events: none;
}

/* hide editor chrome when no note is open */
.main.no-note .editor,
.main.no-note .save-status {
  display: none;
}

.main:not(.no-note) .empty-state {
  display: none;
}

.main.no-note .editor-toolbar .tb-btn {
  pointer-events: none;
  opacity: 0.4;
}
