:root {
  color-scheme: light;
  --bg: #f4f6fb;
  --panel: #ffffff;
  --panel-soft: #f9fbff;
  --text: #182033;
  --muted: #64708a;
  --border: #dfe5ef;
  --primary: #2563eb;
  --primary-dark: #1748aa;
  --danger: #dc2626;
  --shadow: 0 20px 60px rgba(20, 33, 61, 0.12);
  --radius: 18px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background: var(--bg);
}

button, input, textarea {
  font: inherit;
}

button {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  border-radius: 12px;
  padding: 0.62rem 0.9rem;
  cursor: pointer;
  transition: 0.16s ease;
}

button:hover { border-color: #b8c3d7; transform: translateY(-1px); }
button:disabled { cursor: not-allowed; opacity: 0.55; transform: none; }
button.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
button.primary:hover { background: var(--primary-dark); }
button.ghost { background: transparent; }
button.danger { border-color: #fecaca; color: var(--danger); background: #fff7f7; }
.ghost-link {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  border-radius: 12px;
  padding: 0.62rem 0.9rem;
  text-decoration: none;
  transition: 0.16s ease;
}
.ghost-link:hover { border-color: #b8c3d7; transform: translateY(-1px); }
.primary-link {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  border-radius: 12px;
  padding: 0.78rem 0.9rem;
  background: var(--primary);
  color: #fff;
  text-decoration: none;
  font-weight: 700;
  transition: 0.16s ease;
}
.primary-link:hover { background: var(--primary-dark); transform: translateY(-1px); }

input {
  width: 100%;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  border-radius: 12px;
  padding: 0.78rem 0.9rem;
  outline: none;
}
input:focus { border-color: var(--primary); box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.12); }

[hidden] { display: none !important; }

.auth-view {
  min-height: 100%;
  display: grid;
  grid-template-columns: minmax(320px, 560px) minmax(320px, 420px);
  gap: 2rem;
  align-items: center;
  justify-content: center;
  padding: 3rem 1.2rem;
  background:
    radial-gradient(circle at 10% 15%, rgba(37, 99, 235, 0.20), transparent 34rem),
    radial-gradient(circle at 90% 80%, rgba(14, 165, 233, 0.18), transparent 28rem),
    var(--bg);
}

.brand-card, .auth-card {
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(20px);
  border: 1px solid rgba(255,255,255,0.7);
  border-radius: 28px;
  box-shadow: var(--shadow);
  padding: clamp(1.5rem, 4vw, 3rem);
}

.brand-mark {
  width: 64px;
  height: 64px;
  border-radius: 20px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #2563eb, #06b6d4);
  color: #fff;
  font-weight: 800;
  letter-spacing: 0.06em;
}

.eyebrow { color: var(--primary); font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; font-size: 0.78rem; }
.brand-card h1 { margin: 1rem 0; font-size: clamp(2rem, 5vw, 4rem); line-height: 1.05; }
.muted { color: var(--muted); line-height: 1.75; }
.feature-list { display: grid; gap: 0.75rem; padding-left: 1.2rem; color: var(--text); }
.auth-card { display: grid; gap: 1rem; }
.auth-card label { display: grid; gap: 0.4rem; color: var(--muted); }
.auth-actions { display: flex; gap: 0.75rem; flex-wrap: wrap; }
.logto-box { display: grid; gap: 0.85rem; }
.auth-divider {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--muted);
  font-size: 0.88rem;
}
.auth-divider::before, .auth-divider::after {
  content: "";
  height: 1px;
  background: var(--border);
  flex: 1;
}
.error { margin: 0; color: #b91c1c; background: #fef2f2; border: 1px solid #fecaca; padding: 0.75rem; border-radius: 12px; }

.app {
  height: 100vh;
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr) 300px;
  overflow: hidden;
}

.sidebar, .inspector {
  background: var(--panel);
  border-right: 1px solid var(--border);
  overflow: auto;
}
.inspector { border-right: 0; border-left: 1px solid var(--border); }

.sidebar-header, .topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem;
  border-bottom: 1px solid var(--border);
}
.sidebar-header strong { display: block; font-size: 1.1rem; }
.sidebar-header small { display: block; color: var(--muted); margin-top: 0.15rem; }
.user-actions { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; justify-content: flex-end; }
.sync-row { display: grid; grid-template-columns: 1fr auto; gap: 0.5rem; padding: 1rem; }
.search-box { display: grid; gap: 0.4rem; color: var(--muted); padding: 0 1rem 1rem; }
.note-list-section, .panel { padding: 1rem; }
.section-title { font-size: 0.78rem; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 0.75rem; }

.note-list { display: grid; gap: 0.55rem; }
.note-item {
  width: 100%;
  text-align: left;
  display: grid;
  gap: 0.25rem;
  background: var(--panel-soft);
  border-radius: 14px;
}
.note-item.active { border-color: var(--primary); background: #eff6ff; box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.10); }
.note-item-title { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.note-item-meta { color: var(--muted); font-size: 0.78rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.workspace {
  min-width: 0;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  overflow: hidden;
}
.topbar { background: rgba(255,255,255,0.9); }
.title-group { min-width: 0; flex: 1; display: grid; gap: 0.45rem; }
.note-title {
  border: 0;
  box-shadow: none !important;
  padding: 0;
  border-radius: 0;
  background: transparent;
  font-size: clamp(1.5rem, 3vw, 2.35rem);
  font-weight: 800;
}
.tag-input { padding: 0.5rem 0.65rem; background: var(--panel-soft); }
.status-group { display: flex; align-items: center; gap: 0.7rem; white-space: nowrap; }
.save-status { color: var(--muted); font-size: 0.9rem; }

.toolbar {
  display: flex;
  gap: 0.45rem;
  align-items: center;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  background: var(--panel-soft);
}
.toolbar button { padding: 0.48rem 0.7rem; white-space: nowrap; }
.divider { width: 1px; height: 28px; background: var(--border); margin: 0 0.25rem; }

.editor {
  overflow: auto;
  padding: clamp(1.2rem, 4vw, 3rem);
  line-height: 1.75;
  font-size: 1.05rem;
  outline: none;
  background: #fff;
}
.editor[contenteditable="true"] { cursor: text; }
.editor h1, .editor h2, .editor h3 { line-height: 1.25; }
.editor blockquote { border-left: 4px solid var(--primary); padding-left: 1rem; margin-left: 0; color: #475569; background: #f8fafc; border-radius: 0 12px 12px 0; }
.editor img, .editor video { max-width: min(100%, 880px); border-radius: 16px; box-shadow: 0 14px 36px rgba(15, 23, 42, 0.12); }
.editor audio { width: min(100%, 720px); }
.editor figure { margin: 1.4rem 0; }
.editor figcaption { color: var(--muted); font-size: 0.9rem; }
.editor .placeholder { color: var(--muted); }
.editor.dragging { outline: 4px dashed rgba(37, 99, 235, 0.35); outline-offset: -18px; background: #eff6ff; }

.hint { color: var(--muted); line-height: 1.6; margin-top: 0; }
.link-list { display: grid; gap: 0.45rem; }
.link-list.empty, .media-library.empty { color: var(--muted); font-size: 0.9rem; line-height: 1.55; }
.link-pill {
  text-align: left;
  padding: 0.55rem 0.7rem;
  background: #f8fafc;
}
.link-pill.missing { border-style: dashed; color: var(--primary); }
.media-library { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.5rem; }
.media-card {
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
  display: grid;
  gap: 0.4rem;
  min-width: 0;
}
.media-card img, .media-card video { width: 100%; aspect-ratio: 1.2 / 1; object-fit: cover; border-radius: 10px; background: #f1f5f9; }
.media-card audio { width: 100%; }
.media-card span { color: var(--muted); font-size: 0.72rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

@media (max-width: 1100px) {
  .app { grid-template-columns: 260px minmax(0, 1fr); }
  .inspector { display: none; }
}

@media (max-width: 760px) {
  .auth-view { grid-template-columns: 1fr; }
  .app { height: auto; min-height: 100vh; grid-template-columns: 1fr; overflow: visible; }
  .sidebar, .inspector, .workspace { overflow: visible; }
  .inspector { display: block; border-left: 0; border-top: 1px solid var(--border); }
  .topbar, .sidebar-header { align-items: flex-start; flex-direction: column; }
  .status-group { width: 100%; justify-content: space-between; }
}
