@import url('https://fonts.googleapis.com/css2?family=DM+Mono:ital@0;1&family=Manrope:wght@400;500;600&family=Playfair+Display:ital,wght@0,400;1,400&display=swap');

/* ── Tokens — mirror yuluowei.com ── */
:root {
  color-scheme: light;

  --bg:     #fafafa;
  --bg-2:   #f3f1ed;
  --fg:     #14110f;
  --fg-2:   #4a4641;
  --fg-3:   #8a857d;
  --line:   rgba(26, 23, 20, 0.13);
  --accent: oklch(0.62 0.10 60);
  --accent-strong: oklch(0.50 0.10 60);
  --warn:   #7a5200;
  --warn-bg:#fdf4e0;

  /* backward-compat aliases (tasks + writer use these) */
  --panel:       var(--bg-2);
  --panel-soft:  color-mix(in srgb, var(--bg-2) 60%, var(--bg));
  --field:       var(--bg);
  --text:        var(--fg);
  --muted:       var(--fg-3);
  --chip:        var(--bg-2);
  --chip-line:   rgba(26, 23, 20, 0.15);
  --active:      #f1ebe0;
  --shadow:      0 1px 3px rgba(20, 17, 15, .05);
}

.dark {
  color-scheme: dark;

  --bg:     #14110f;
  --bg-2:   #1c1916;
  --fg:     #ece7df;
  --fg-2:   #b3aca0;
  --fg-3:   #6e685e;
  --line:   rgba(236, 231, 223, 0.13);
  --accent: oklch(0.74 0.09 70);
  --accent-strong: oklch(0.85 0.09 70);
  --warn:   #e8b84b;
  --warn-bg:#241c08;

  --panel:       var(--bg-2);
  --panel-soft:  color-mix(in srgb, var(--bg-2) 60%, var(--bg));
  --field:       var(--bg-2);
  --text:        var(--fg);
  --muted:       var(--fg-3);
  --chip:        #2a2418;
  --chip-line:   rgba(236, 231, 223, 0.16);
  --active:      #25200f;
  --shadow:      none;
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-font-smoothing: antialiased; }
body {
  font-family: 'Manrope', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--fg);
  min-height: 100dvh;
  transition: background 600ms ease, color 600ms ease;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
button {
  border: 0;
  background: var(--accent);
  color: white;
  padding: 10px 14px;
  cursor: pointer;
}
button:disabled { opacity: .5; cursor: not-allowed; }
.ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--fg);
}
.hidden { display: none !important; }

/* ── Eyebrow / Mono labels (shared) ── */
.eyebrow, .mono {
  font-family: 'DM Mono', monospace;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 11px;
}

/* ── Login gate — matches yuluowei.com/admin exactly ── */
.login {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.login-box {
  width: 100%;
  max-width: 400px;
}

.login-box .gate-eyebrow {
  font-family: 'DM Mono', monospace;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 11px;
  color: var(--fg-3);
  display: block;
  margin-bottom: 1.75rem;
}

.login-box h1 {
  font-family: 'Playfair Display', serif;
  font-weight: 400;
  font-size: clamp(2.5rem, 7vw, 3.8rem);
  letter-spacing: -0.015em;
  line-height: 0.95;
  color: var(--fg);
  margin-bottom: 2.5rem;
}
.login-box h1 em { font-style: italic; }

.login-box input {
  border: none;
  border-bottom: 1px solid var(--line);
  padding: 14px 0;
  width: 100%;
  font-family: 'DM Mono', monospace;
  font-size: 15px;
  letter-spacing: 0.06em;
  background: transparent;
  color: var(--fg);
  display: block;
  margin-bottom: 1.25rem;
  transition: border-color 300ms ease;
}
.login-box input:focus { outline: none; border-bottom-color: var(--fg); }
.login-box input::placeholder {
  color: var(--fg-3);
  font-family: 'Manrope', sans-serif;
  letter-spacing: 0;
  font-size: 14px;
}

.login-box button[type="submit"] {
  width: 100%;
  border: 1px solid var(--line);
  padding: 1rem 1.5rem;
  font-family: 'DM Mono', monospace;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 11px;
  color: var(--fg);
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 200ms ease, border-color 200ms ease;
}
.login-box button[type="submit"]:hover { background: var(--bg-2); border-color: var(--fg-2); }

#loginError { color: #b42318; min-height: 20px; font-size: 12px; margin-top: 0.75rem; }

/* ── App chrome ── */
.app { min-height: 100vh; }

.topbar {
  height: 60px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 1.5rem;
  border-bottom: 1px solid var(--line);
  background: var(--bg-2);
}

.topbar h1 {
  font-family: 'Playfair Display', serif;
  font-weight: 400;
  font-size: 1.3rem;
  letter-spacing: -0.01em;
  margin: 0;
}
.topbar p {
  font-family: 'DM Mono', monospace;
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--fg-3);
  margin: 3px 0 0;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.top-actions button {
  font-family: 'DM Mono', monospace;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 10px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--fg-3);
  padding: 6px 14px;
  transition: color 200ms ease, border-color 200ms ease;
}
.top-actions button:hover { color: var(--fg); border-color: var(--fg-2); }

/* ── Writer workspace ── */
.workspace {
  display: grid;
  grid-template-columns: minmax(240px, 280px) minmax(620px, 1.35fr) minmax(380px, 1fr);
  gap: 1px;
  min-height: calc(100vh - 60px);
  background: var(--line);
}

.setup, .inputs, .outputs {
  background: var(--bg);
  padding: 18px;
  overflow: auto;
}

label {
  display: block;
  margin: 18px 0 8px;
  font-family: 'DM Mono', monospace;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 10px;
  color: var(--fg-3);
}

select, textarea, input[type="search"] {
  width: 100%;
  border: none;
  border-bottom: 1px solid var(--line);
  padding: 10px 0;
  background: transparent;
  color: var(--fg);
  font-size: 13.5px;
  transition: border-color 250ms ease;
}
select:focus, textarea:focus, input[type="search"]:focus { outline: none; border-bottom-color: var(--fg); }
textarea { resize: vertical; line-height: 1.5; }
input::placeholder, textarea::placeholder { color: var(--fg-3); }

.checks { display: grid; gap: 6px; }
.checks label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  font-family: 'Manrope', sans-serif;
  font-size: 13px;
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
  color: var(--fg-2);
}

.model-info { display: grid; gap: 8px; }
.model {
  border-top: 1px solid var(--line);
  padding: 12px 0;
}
.model h3 { margin: 0 0 6px; font-size: 13px; font-weight: 600; }
.model p { margin: 4px 0; color: var(--fg-3); line-height: 1.45; font-size: 12px; }

.obsidian-picker {
  border-top: 1px solid var(--line);
  padding: 12px 0;
  container-type: inline-size;
}
.search-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.selected-notes { display: flex; flex-wrap: wrap; gap: 8px; min-height: 32px; margin: 10px 0; }

.obsidian-panel {
  display: grid;
  grid-template-columns: clamp(180px, 22%, 260px) minmax(260px, 1fr) minmax(320px, 1.15fr);
  gap: 10px;
  margin-top: 10px;
  min-height: 420px;
}
.obsidian-nav, .obsidian-list, .note-preview {
  min-height: 0;
  max-height: 520px;
  overflow: auto;
  background: var(--bg-2);
  border: 1px solid var(--line);
  padding: 8px;
}
.obsidian-nav summary {
  cursor: pointer;
  color: var(--fg-3);
  font-family: 'DM Mono', monospace;
  font-size: 10px;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  margin: 10px 0 6px;
}

.source-btn, .tree-item button, .tag-pill, .note-open {
  width: 100%;
  text-align: left;
  background: transparent;
  color: var(--fg);
  border: 0;
  padding: 5px 6px;
  font-size: 13px;
}
.source-btn.active, .tree-item button.active, .tag-pill.active, .note-row.active {
  background: var(--active);
}
.tree-item button {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  padding: 5px 6px 5px calc(6px + var(--depth) * 12px);
  min-width: 0;
}
.tree-item span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-item small, .tag-pill small { color: var(--fg-3); font-size: 12px; flex: 0 0 auto; }
.tag-list { display: grid; gap: 3px; }
.tag-pill { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 5px 6px; }

.muted, .empty-small { color: var(--fg-3); font-size: 13px; }

.note-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  background: var(--active);
  color: var(--accent-strong);
  border: 1px solid var(--line);
  padding: 5px 8px;
  font-size: 12px;
}
.note-chip span { font-weight: 600; }

.note-results { display: grid; gap: 6px; }
.note-row {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px;
  min-width: 0;
  margin: 0;
  padding: 8px;
  border-bottom: 1px solid var(--line);
  background: transparent;
  font-weight: 500;
  cursor: pointer;
}
.note-row span { min-width: 0; }
.note-row strong {
  display: -webkit-box;
  overflow: hidden;
  font-size: 13.5px;
  line-height: 1.3;
  overflow-wrap: anywhere;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}
.note-row small {
  color: var(--fg-3);
  display: -webkit-box;
  overflow: hidden;
  font-weight: 400;
  font-size: 12px;
  line-height: 1.3;
  margin-top: 2px;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}
.note-row em { color: var(--fg-3); font-style: normal; line-height: 1.35; margin-top: 5px; display: block; }
.note-open { min-width: 0; overflow: hidden; padding: 0; }
.note-preview { background: var(--bg); }
.preview-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 10px; border-bottom: 1px solid var(--line); padding-bottom: 8px;
}
.preview-head h3 { margin: 0; font-size: 14px; overflow-wrap: anywhere; }
.preview-head p { margin: 4px 0 0; color: var(--fg-3); font-size: 12px; line-height: 1.35; }
.preview-tags { display: flex; flex-wrap: wrap; gap: 5px; margin: 8px 0; }
.preview-tags span {
  background: var(--bg-2);
  color: var(--fg-3);
  padding: 3px 7px;
  font-size: 11px;
  border: 1px solid var(--line);
}
.note-preview pre { white-space: pre-wrap; line-height: 1.5; margin: 0; font-size: 13px; }

.warnings { margin-top: 10px; color: var(--warn); }
.warning {
  background: var(--warn-bg);
  border: 1px solid var(--line);
  padding: 8px;
  margin-top: 8px;
  font-size: 13px;
}

.actions { display: flex; gap: 8px; margin-top: 16px; }
.actions button {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--fg);
  font-family: 'DM Mono', monospace;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 10px;
  padding: 8px 16px;
  transition: background 180ms ease;
}
.actions button:hover { background: var(--bg-2); }
.actions button.primary-action {
  background: var(--fg);
  color: var(--bg);
  border-color: var(--fg);
}
.actions button.primary-action:hover { opacity: 0.88; }

.output-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.output-head h2 {
  font-family: 'Playfair Display', serif;
  font-weight: 400;
  font-size: 1.25rem;
  letter-spacing: -0.01em;
  margin: 0;
}
.results.empty { color: var(--fg-3); padding: 18px 0; font-size: 13.5px; }
.result { border-top: 1px solid var(--line); padding: 16px 0; }
.result h3 { margin: 0 0 12px; font-size: 15px; font-weight: 600; }

.version {
  margin-top: 12px;
  border: 1px solid var(--line);
}
.version-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-2);
}
.version-head button {
  font-family: 'DM Mono', monospace;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.10em;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--fg-3);
  padding: 5px 10px;
}
.version pre { white-space: pre-wrap; margin: 0; padding: 12px; line-height: 1.5; font-size: 13px; }

.final-editor {
  margin-top: 12px;
  border: 1px solid var(--line);
  background: var(--bg);
}
.final-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 10px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-2);
}
.final-head span { color: var(--fg-3); font-size: 12px; }
.final-text {
  border: 0;
  min-height: 180px;
  padding: 12px;
  width: 100%;
  background: var(--bg);
  color: var(--fg);
  resize: vertical;
  line-height: 1.5;
  font-size: 13px;
}

@media (max-width: 1100px) { .workspace { grid-template-columns: 1fr; } }
@container (max-width: 1050px) {
  .obsidian-panel { grid-template-columns: minmax(180px, .72fr) minmax(260px, 1fr); }
  .note-preview { grid-column: 1 / -1; max-height: 360px; }
}
@container (max-width: 680px) {
  .search-row, .obsidian-panel { grid-template-columns: 1fr; }
  .obsidian-nav, .obsidian-list, .note-preview { max-height: 340px; }
}
