/* ── Variables ── */
:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #22263a;
  --border: #2e3250;
  --accent: #6c63ff;
  --accent-hover: #7c74ff;
  --accent-dim: rgba(108, 99, 255, 0.15);
  --danger: #ff4f6a;
  --danger-hover: #ff3355;
  --text: #e8eaf6;
  --text-muted: #7b7fa8;
  --tag-bg: #252a40;
  --tag-text: #a0a8d4;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --topbar-h: 56px;
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
}

/* ── Screens ── */
.screen { min-height: 100vh; }
.hidden { display: none !important; }

/* ── Auth ── */
#auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px 36px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow);
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 28px;
}

.logo-icon {
  font-size: 28px;
  color: var(--accent);
}

.logo h1 {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.3px;
}

.tab-bar {
  display: flex;
  gap: 4px;
  background: var(--surface2);
  border-radius: var(--radius-sm);
  padding: 4px;
  margin-bottom: 28px;
}

.tab {
  flex: 1;
  padding: 8px 12px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  border-radius: calc(var(--radius-sm) - 2px);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.15s;
}

.tab.active {
  background: var(--accent);
  color: #fff;
}

.auth-form { display: flex; flex-direction: column; gap: 18px; }

/* ── Form Fields ── */
.field { display: flex; flex-direction: column; gap: 6px; }

label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0.3px;
}

.hint { font-weight: 400; opacity: 0.7; }

input, textarea {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  padding: 10px 14px;
  transition: border-color 0.15s, box-shadow 0.15s;
  outline: none;
  width: 100%;
}

input::placeholder, textarea::placeholder { color: var(--text-muted); }

input:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.form-error {
  color: var(--danger);
  font-size: 12px;
  min-height: 18px;
}

/* ── Buttons ── */
button { cursor: pointer; font-family: inherit; }

.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 500;
  transition: background 0.15s, transform 0.1s;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:active { transform: scale(0.98); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-full { width: 100%; }

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  padding: 7px 14px;
  font-size: 13px;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.btn-ghost:hover { background: var(--surface2); color: var(--text); border-color: var(--accent); }

.btn-danger {
  background: transparent;
  border: 1px solid var(--danger);
  color: var(--danger);
  border-radius: var(--radius-sm);
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 500;
  transition: background 0.15s;
}
.btn-danger:hover { background: rgba(255, 79, 106, 0.12); }

.btn-icon {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 22px;
  padding: 4px 8px;
  line-height: 1;
  border-radius: var(--radius-sm);
  transition: color 0.15s, background 0.15s;
}
.btn-icon:hover { color: var(--text); background: var(--surface2); }

.btn-link {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 12px;
  padding: 4px 0;
  text-decoration: underline;
  text-decoration-color: transparent;
  transition: text-decoration-color 0.15s;
}
.btn-link:hover { text-decoration-color: var(--accent); }

/* ── Topbar ── */
.topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-left { display: flex; align-items: center; gap: 10px; }
.topbar-right { display: flex; align-items: center; gap: 10px; }

.app-title { font-size: 16px; font-weight: 600; }
.user-label { font-size: 13px; color: var(--text-muted); margin-right: 4px; }

/* ── Main Layout ── */
.layout {
  display: grid;
  grid-template-columns: 220px 1fr 420px;
  height: calc(100vh - var(--topbar-h));
  overflow: hidden;
}

/* ── Sidebar ── */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  overflow-y: auto;
}

.section-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

/* ── Tags ── */
.tag-cloud { display: flex; flex-wrap: wrap; gap: 6px; }

.tag {
  background: var(--tag-bg);
  color: var(--tag-text);
  border-radius: 20px;
  padding: 3px 10px;
  font-size: 11px;
  font-weight: 500;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s;
  user-select: none;
}
.tag:hover { border-color: var(--accent); color: var(--accent); }
.tag.active { background: var(--accent-dim); color: var(--accent); border-color: var(--accent); }

/* ── Notes List ── */
.notes-panel {
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.notes-list { display: flex; flex-direction: column; gap: 10px; }

.note-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.note-card:hover { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent-dim); }
.note-card.active { border-color: var(--accent); background: var(--accent-dim); }

.note-card-preview {
  font-size: 13px;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
  margin-bottom: 8px;
}

.note-card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.note-card-date { font-size: 11px; color: var(--text-muted); }

.empty-msg {
  text-align: center;
  color: var(--text-muted);
  padding: 48px 20px;
  font-size: 14px;
}

/* ── Editor ── */
.editor-panel {
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

.editor-header h2 { font-size: 16px; font-weight: 600; }

.note-textarea {
  flex: 1;
  resize: none;
  border: none;
  border-radius: 0;
  background: var(--surface);
  padding: 20px;
  font-size: 14px;
  line-height: 1.7;
  outline: none;
  box-shadow: none;
}

.note-textarea:focus { border: none; box-shadow: none; }

.editor-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.tag-input-row { gap: 6px; }

.editor-actions { display: flex; justify-content: flex-end; gap: 10px; }

/* ── Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
  backdrop-filter: blur(4px);
}

.modal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  max-width: 520px;
  width: 100%;
  box-shadow: var(--shadow);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.modal-header h3 { font-size: 17px; font-weight: 600; }

.random-note-text {
  font-size: 15px;
  line-height: 1.75;
  color: var(--text);
  margin-bottom: 16px;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 260px;
  overflow-y: auto;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

/* ── Scrollbars ── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Responsive ── */
@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto;
    height: auto;
    overflow: visible;
  }

  .sidebar {
    border-right: none;
    border-bottom: 1px solid var(--border);
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    padding: 12px 16px;
    gap: 12px;
  }

  .tag-filter { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
  .section-label { margin-bottom: 0; white-space: nowrap; }

  .notes-panel { height: auto; }

  .editor-panel {
    position: fixed;
    inset: 0;
    z-index: 50;
    border-left: none;
  }
}
