/* ── Reset & Tokens ──────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #ffffff;
  --surface:   #fafafa;
  --border:    #e8e8e8;
  --text-1:    #111827;
  --text-2:    #6b7280;
  --text-3:    #9ca3af;
  --accent:    #2563eb;
  --accent-h:  #1d4ed8;
  --danger:    #ef4444;
  --danger-h:  #dc2626;
  --active-bg: #eff6ff;
  --radius:    8px;
  --sidebar-w: 272px;
  --font:      -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

html, body {
  height: 100%;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text-1);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* ── Login ───────────────────────────────────────────────────────────────── */
#loading-screen {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.loading-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

#login-screen {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-card {
  text-align: center;
  padding: 52px 44px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--bg);
  box-shadow: 0 4px 28px rgba(0, 0, 0, .06);
  width: 340px;
}

.login-card h1 {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -.5px;
  margin-bottom: 6px;
}

.login-card p {
  color: var(--text-2);
  font-size: 14px;
  margin-bottom: 32px;
}

.btn-google {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 11px 20px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 500;
  color: var(--text-1);
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .07);
  transition: background .12s, box-shadow .12s;
}
.btn-google:hover    { background: #f5f5f5; }
.btn-google:active   { background: #eee; }
.btn-google:disabled { opacity: .6; cursor: not-allowed; }

/* ── App Shell ───────────────────────────────────────────────────────────── */
#app {
  display: flex;
  height: 100%;
  overflow: hidden;
}

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow: hidden;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.app-title {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -.3px;
}

.user-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

#user-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--border);
}

/* Search */
.sidebar-search {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-search input {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  font-family: var(--font);
  font-size: 13px;
  color: var(--text-1);
  outline: none;
  transition: border-color .15s;
}
.sidebar-search input::placeholder { color: var(--text-3); }
.sidebar-search input:focus         { border-color: var(--accent); }

/* New note */
.sidebar-new {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-new button {
  width: 100%;
  padding: 8px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background .12s;
}
.sidebar-new button:hover    { background: var(--accent-h); }
.sidebar-new button:disabled { opacity: .6; cursor: not-allowed; }

/* Notes list */
.notes-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0;
}

.notes-empty {
  padding: 20px 16px;
  font-size: 13px;
  color: var(--text-3);
  text-align: center;
}

.sync-error {
  margin: 8px 12px 0;
  padding: 7px 10px;
  background: #fef3cd;
  border: 1px solid #f0c040;
  border-radius: var(--radius);
  font-size: 12px;
  color: #7c5e10;
}

/* Note item */
.note-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  padding: 10px 14px;
  background: none;
  border: none;
  border-left: 3px solid transparent;
  text-align: left;
  cursor: pointer;
  font-family: var(--font);
  transition: background .1s;
  min-width: 0;
}
.note-item:hover  { background: rgba(0, 0, 0, .04); }
.note-item.active { background: var(--active-bg); border-left-color: var(--accent); }

.ni-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-1);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}

.ni-preview {
  font-size: 12px;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}

.ni-time {
  font-size: 11px;
  color: var(--text-3);
  display: block;
  margin-top: 1px;
}

/* ── Main / Editor ───────────────────────────────────────────────────────── */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}

.empty-state {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: var(--text-3);
}

#editor {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.editor-header {
  display: flex;
  align-items: center;
  padding: 16px 24px 14px;
  border-bottom: 1px solid var(--border);
  gap: 10px;
  flex-shrink: 0;
}

.note-title {
  flex: 1;
  font-family: var(--font);
  font-size: 20px;
  font-weight: 600;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text-1);
  min-width: 0;
  letter-spacing: -.3px;
}
.note-title::placeholder { color: var(--text-3); }

#note-content {
  flex: 1;
  padding: 18px 24px;
  border: none;
  outline: none;
  resize: none;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.75;
  color: var(--text-1);
  background: transparent;
}
#note-content::placeholder { color: var(--text-3); }

/* ── Markdown Preview ────────────────────────────────────────────────────── */
.note-preview {
  flex: 1;
  padding: 18px 24px;
  overflow-y: auto;
  font-size: 15px;
  line-height: 1.75;
  color: var(--text-1);
}

.note-preview h1 { font-size: 1.55em; font-weight: 700; letter-spacing: -.4px; margin: 0 0 .5em; }
.note-preview h2 { font-size: 1.25em; font-weight: 600; margin: 1.4em 0 .4em; }
.note-preview h3 { font-size: 1.05em; font-weight: 600; margin: 1.2em 0 .3em; }
.note-preview h4,
.note-preview h5,
.note-preview h6 { font-size: 1em; font-weight: 600; margin: 1em 0 .3em; }

.note-preview p  { margin: 0 0 .85em; }

.note-preview a  { color: var(--accent); text-decoration: none; }
.note-preview a:hover { text-decoration: underline; }

.note-preview strong { font-weight: 600; }
.note-preview em     { font-style: italic; }

.note-preview ul,
.note-preview ol { padding-left: 1.6em; margin: 0 0 .85em; }
.note-preview li { margin-bottom: .2em; }

.note-preview blockquote {
  border-left: 3px solid var(--border);
  margin: 0 0 .85em;
  padding: 3px 0 3px 14px;
  color: var(--text-2);
}
.note-preview blockquote p { margin: 0; }

.note-preview code {
  font-family: 'SF Mono', 'Fira Code', Consolas, 'Courier New', monospace;
  font-size: .85em;
  background: #f3f4f6;
  padding: 2px 5px;
  border-radius: 4px;
}
.note-preview pre {
  background: #f3f4f6;
  border-radius: 8px;
  padding: 14px 16px;
  overflow-x: auto;
  margin: 0 0 .85em;
}
.note-preview pre code { background: none; padding: 0; font-size: .85em; }

.note-preview hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1.4em 0;
}

.note-preview table {
  width: 100%;
  border-collapse: collapse;
  font-size: .9em;
  margin: 0 0 .85em;
}
.note-preview th,
.note-preview td { padding: 6px 12px; border: 1px solid var(--border); text-align: left; }
.note-preview th { background: var(--surface); font-weight: 600; }

.editor-footer {
  padding: 6px 24px;
  border-top: 1px solid var(--border);
  height: 32px;
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

#save-status {
  font-size: 12px;
  color: var(--text-3);
}

/* ── Icon Buttons ────────────────────────────────────────────────────────── */
.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: none;
  border: none;
  border-radius: 6px;
  color: var(--text-2);
  cursor: pointer;
  transition: background .1s, color .1s;
  flex-shrink: 0;
}
.icon-btn:hover           { background: rgba(0, 0, 0, .06); color: var(--text-1); }
.icon-btn-danger          { color: var(--text-3); }
.icon-btn-danger:hover    { background: #fef2f2; color: var(--danger); }

/* ── Modal Buttons ───────────────────────────────────────────────────────── */
.btn-secondary,
.btn-danger {
  padding: 8px 16px;
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background .12s;
  border: none;
}

.btn-secondary {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-1);
}
.btn-secondary:hover { background: var(--border); }

.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-danger:hover { background: var(--danger-h); }

/* ── Modal ───────────────────────────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.modal-card {
  background: var(--bg);
  border-radius: 12px;
  padding: 28px;
  width: 300px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, .14);
}

.modal-card h3 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 6px;
}

.modal-card p {
  font-size: 13px;
  color: var(--text-2);
  margin-bottom: 22px;
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

/* ── Scrollbar ───────────────────────────────────────────────────────────── */
.notes-list::-webkit-scrollbar       { width: 4px; }
.notes-list::-webkit-scrollbar-track { background: transparent; }
.notes-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.sidebar-version {
  padding: 8px 14px 10px;
  font-size: 11px;
  color: var(--text-3);
  flex-shrink: 0;
}

/* Back button — only visible on mobile */
.back-btn { display: none; }

/* ── Mobile layout (single-panel navigation) ─────────────────────────────── */
@media (max-width: 639px) {
  /* List view: sidebar fills the screen */
  .sidebar {
    width: 100%;
    border-right: none;
  }

  /* Editor view: hide the sidebar, show the main panel */
  .main { display: none; }

  #app.note-open .sidebar { display: none; }
  #app.note-open .main    { display: flex; }

  /* Show the back arrow in the editor header */
  .back-btn { display: flex; }

  /* Give the editor a bit more breathing room on narrow screens */
  .editor-header    { padding: 14px 16px; }
  #note-content     { padding: 14px 16px; font-size: 16px; }
  .note-preview     { padding: 14px 16px; font-size: 16px; }
  .editor-footer    { padding: 6px 16px; }
}
