:root {
  --bg: #f7f6f3;
  --panel: #ffffff;
  --ink: #2b2b2b;
  --muted: #8a8a8a;
  --line: #e7e5e0;
  --accent: #3b6ea5;
  --accent-soft: #eaf1f8;
  --error: #b3261e;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--error); }

/* ---- Login ---- */
.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  z-index: 10;
}
.login-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 2rem;
  width: min(360px, 90vw);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.06);
}
.login-card h1 { margin: 0; font-size: 1.5rem; }
.login-card input, .login-card button { padding: 0.7rem 0.8rem; font-size: 1rem; border-radius: 8px; }
.login-card input { border: 1px solid var(--line); }
.login-card button {
  border: none; background: var(--accent); color: #fff; cursor: pointer; font-weight: 600;
}

/* ---- App layout ---- */
#app { display: flex; height: 100vh; }

#sidebar {
  width: 300px;
  flex-shrink: 0;
  border-right: 1px solid var(--line);
  background: var(--panel);
  display: flex;
  flex-direction: column;
  padding: 0.75rem;
  gap: 0.6rem;
}
.sidebar-head { display: flex; gap: 0.5rem; }
.sidebar-head button {
  flex: 1; padding: 0.55rem; border-radius: 8px; border: 1px solid var(--line);
  background: var(--accent); color: #fff; cursor: pointer; font-weight: 600; font-size: 0.9rem;
}
.sidebar-head .ghost { background: transparent; color: var(--muted); }
#search {
  padding: 0.55rem 0.7rem; border: 1px solid var(--line); border-radius: 8px; font-size: 0.95rem;
}

.list { overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 2px; }
.list-item {
  text-align: left; background: transparent; border: none; border-radius: 8px;
  padding: 0.55rem 0.6rem; cursor: pointer; display: flex; flex-direction: column; gap: 2px;
}
.list-item:hover { background: var(--bg); }
.list-item.active { background: var(--accent-soft); }
.list-item .li-date { font-weight: 600; font-size: 0.9rem; }
.list-item .li-snip { color: var(--muted); font-size: 0.8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-empty { color: var(--muted); font-size: 0.85rem; padding: 0.6rem; }

/* ---- Editor ---- */
#editor-pane { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.editor-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.5rem; border-bottom: 1px solid var(--line);
}
.date-block { display: flex; align-items: baseline; gap: 0.6rem; }
.date-block h2 { margin: 0; font-size: 1.2rem; }
.head-actions { display: flex; align-items: center; gap: 0.8rem; }
.status { font-size: 0.85rem; color: var(--muted); min-width: 7ch; text-align: right; }
.status.saving { color: var(--accent); }
.status.saved { color: #2e7d32; }
.head-actions .ghost {
  background: transparent; border: 1px solid var(--line); color: var(--muted);
  padding: 0.4rem 0.7rem; border-radius: 8px; cursor: pointer; font-size: 0.85rem;
}

#entry {
  flex: 1; width: 100%; border: none; outline: none; resize: none;
  padding: 1.5rem; font-size: 1.05rem; line-height: 1.6;
  font-family: var(--sans); background: var(--bg); color: var(--ink);
}

.read-view {
  flex: 1; overflow-y: auto; padding: 1.5rem; font-size: 1.05rem; line-height: 1.6;
  white-space: pre-wrap; word-wrap: break-word; background: var(--bg);
}
.read-view a { color: var(--accent); }

@media (max-width: 640px) {
  #app { flex-direction: column; }
  #sidebar { width: 100%; height: 38vh; border-right: none; border-bottom: 1px solid var(--line); }
}
