:root {
  --bg: #060b16;
  --surface: #0e1628;
  --surface-muted: #131f36;
  --surface-soft: #1a2742;
  --text: #e6eefc;
  --text-muted: #93a8cc;
  --primary: #22d3ee;
  --primary-strong: #06b6d4;
  --danger: #f43f5e;
  --danger-strong: #e11d48;
  --border: #28406a;
  --shadow: 0 18px 46px rgba(2, 10, 29, 0.65);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Space Grotesk", "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 10% 5%, rgba(34, 211, 238, 0.18), transparent 34%),
    radial-gradient(circle at 80% 10%, rgba(59, 130, 246, 0.2), transparent 38%),
    radial-gradient(circle at 80% 80%, rgba(168, 85, 247, 0.2), transparent 36%),
    linear-gradient(150deg, #060b16 0%, #0a1222 52%, #070d1b 100%);
  color: var(--text);
}

a {
  color: #8be9ff;
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.topbar {
  background: rgba(11, 20, 36, 0.82);
  border-bottom: 1px solid rgba(59, 130, 246, 0.22);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.brand {
  font-weight: 700;
  font-size: 1.2rem;
  letter-spacing: 0.4px;
  margin-right: auto;
  color: #d2ebff;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 12px;
}

.theme-icon-btn {
  border: 1px solid rgba(93, 123, 177, 0.45);
  background: rgba(16, 31, 54, 0.9);
  color: #e6f2ff;
  border-radius: 999px;
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 0.95rem;
}

.btn-link {
  border: 0;
  background: transparent;
  color: #ff8fa4;
  font-weight: 600;
  cursor: pointer;
}

.app-content {
  max-width: 1320px;
  margin: 0 auto;
  padding: 24px;
}

.card {
  background: linear-gradient(145deg, rgba(14, 22, 40, 0.95), rgba(9, 16, 30, 0.95));
  border: 1px solid rgba(71, 115, 179, 0.5);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 18px;
}

.flash {
  margin-bottom: 14px;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid transparent;
}

.flash-success {
  color: #b9ffd9;
  background: rgba(16, 185, 129, 0.18);
  border-color: rgba(16, 185, 129, 0.44);
}

.flash-error {
  color: #ffd3dc;
  background: rgba(244, 63, 94, 0.16);
  border-color: rgba(244, 63, 94, 0.44);
}

.muted {
  color: var(--text-muted);
}

.page-title h1 {
  margin: 0;
}

.page-title p {
  margin-top: 6px;
  color: var(--text-muted);
}

.auth-page {
  min-height: calc(100vh - 160px);
  display: grid;
  place-items: center;
}

.auth-card {
  width: min(460px, 100%);
}

.form-grid {
  display: grid;
  gap: 14px;
}

label {
  font-weight: 600;
  display: grid;
  gap: 6px;
}

input,
textarea,
button {
  font: inherit;
}

input,
textarea {
  border: 1px solid var(--border);
  background: var(--surface-muted);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text);
}

input:focus,
textarea:focus {
  outline: 2px solid rgba(15, 118, 110, 0.2);
  border-color: var(--primary);
}

textarea {
  resize: vertical;
}

.field-error {
  color: #b91c1c;
  font-weight: 400;
}

.btn-primary,
.btn-secondary,
.btn-danger {
  border: 0;
  border-radius: 8px;
  padding: 10px 14px;
  cursor: pointer;
  font-weight: 600;
}

.btn-primary {
  color: #052231;
  background: linear-gradient(135deg, #22d3ee 0%, #67e8f9 100%);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.12) inset, 0 8px 18px rgba(34, 211, 238, 0.28);
}

.btn-primary:hover {
  background: linear-gradient(135deg, #06b6d4 0%, #22d3ee 100%);
}

.btn-primary.icon-only {
  width: 42px;
  height: 42px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-primary.icon-only img {
  width: 18px;
  height: 18px;
  display: block;
}

.btn-secondary {
  background: rgba(59, 130, 246, 0.14);
  color: #d4e8ff;
  border: 1px solid rgba(59, 130, 246, 0.4);
}

.btn-small {
  padding: 8px 10px;
  font-size: 0.82rem;
}

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

.btn-danger:hover {
  background: var(--danger-strong);
}

.btn-danger-soft {
  border: 1px solid #fecaca;
  border-radius: 8px;
  padding: 10px 14px;
  cursor: pointer;
  font-weight: 600;
  color: #b91c1c;
  background: #fff5f5;
}

.btn-danger-soft:hover {
  background: #fee2e2;
  border-color: #fda4af;
}

.btn-danger-soft.icon-only {
  width: 42px;
  height: 42px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-danger-soft.icon-only img {
  width: 18px;
  height: 18px;
  display: block;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 14px;
  margin: 16px 0;
}

.stat-card {
  display: grid;
  gap: 10px;
}

.stat-card h2 {
  margin: 0;
  font-size: 1rem;
}

.stat-value {
  font-size: 2rem;
}

.list-clean {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 10px;
}

.notes-page {
  display: grid;
  grid-template-columns: 310px 1fr;
  gap: 0;
  min-height: calc(100vh - 148px);
  border: 1px solid rgba(71, 115, 179, 0.55);
  border-radius: 18px;
  overflow: hidden;
  background: linear-gradient(145deg, rgba(12, 21, 38, 0.95), rgba(8, 14, 27, 0.95));
  box-shadow: var(--shadow);
}

.notes-sidebar {
  border-right: 1px solid rgba(71, 115, 179, 0.45);
  background:
    linear-gradient(180deg, rgba(28, 43, 70, 0.72), rgba(16, 27, 46, 0.72)),
    radial-gradient(circle at -20% -10%, rgba(34, 211, 238, 0.25), transparent 45%);
  padding: 20px 14px;
  min-height: 100%;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.sidebar-head h1 {
  margin: 0;
  font-size: 1.3rem;
  color: #dbebff;
  letter-spacing: 0.3px;
}

.notes-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: calc(100vh - 220px);
  overflow-y: auto;
}

.notes-search-box {
  position: relative;
  display: flex;
  margin-bottom: 12px;
}

.notes-search-box input {
  flex: 1;
  min-width: 0;
  border: 1px solid rgba(93, 123, 177, 0.5);
  background: rgba(16, 31, 54, 0.85);
  color: #e8f2ff;
  padding-right: 36px;
}

.notes-search-box input::placeholder {
  color: #8ea7cf;
}

.notes-search-empty {
  margin-top: 10px;
  font-size: 0.9rem;
}

.search-clear-btn {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  border: 0;
  background: transparent;
  color: #9fb5d8;
  font-size: 1rem;
  width: 24px;
  height: 24px;
  border-radius: 999px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.search-clear-btn:hover {
  color: #d4e6ff;
  background: rgba(93, 123, 177, 0.22);
}

.notes-list-item {
  border: 1px solid rgba(126, 166, 231, 0.2);
  border-radius: 10px;
  background: rgba(18, 31, 53, 0.72);
  transition: all 0.2s ease;
}

.notes-list-item:hover {
  border-color: rgba(126, 166, 231, 0.52);
  transform: translateY(-1px);
}

.notes-list-item.active {
  border-color: rgba(103, 232, 249, 0.8);
  background: linear-gradient(135deg, rgba(34, 211, 238, 0.25), rgba(59, 130, 246, 0.18));
  box-shadow: 0 0 0 1px rgba(34, 211, 238, 0.3) inset;
}

.notes-list-item.pinned {
  border-color: rgba(250, 204, 21, 0.55);
}

.note-row-head {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: start;
}

.note-link {
  display: grid;
  gap: 4px;
  padding: 10px;
  color: inherit;
}

.note-link strong {
  color: #e7f2ff;
}

.note-link small {
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pin-note-btn {
  margin: 8px 8px 0 0;
  border: 1px solid rgba(126, 166, 231, 0.38);
  background: rgba(15, 26, 44, 0.8);
  color: #ffd972;
  border-radius: 8px;
  width: 28px;
  height: 28px;
  cursor: pointer;
}

.pin-note-btn.is-pinned {
  border-color: rgba(250, 204, 21, 0.75);
  background: rgba(250, 204, 21, 0.18);
}

.notes-main {
  min-height: 100%;
}

.notes-main-open {
  background:
    linear-gradient(160deg, rgba(10, 20, 38, 0.98), rgba(9, 17, 31, 0.98)),
    radial-gradient(circle at 80% 12%, rgba(59, 130, 246, 0.16), transparent 36%);
  padding: 0;
  display: flex;
  flex-direction: column;
  min-height: 100%;
  width: 100%;
  position: relative;
}

.notes-main-open::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(93, 123, 177, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(93, 123, 177, 0.08) 1px, transparent 1px);
  background-size: 28px 28px;
  opacity: 0.35;
  pointer-events: none;
}

.open-tabs-bar {
  display: flex;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid rgba(71, 115, 179, 0.35);
  overflow-x: auto;
  background: rgba(13, 24, 43, 0.72);
  z-index: 1;
  min-height: 58px;
  align-items: center;
}

.open-tabs-bar.empty {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.note-tab-pill {
  border: 1px solid rgba(93, 123, 177, 0.45);
  background: rgba(16, 31, 54, 0.9);
  color: #dce9ff;
  border-radius: 999px;
  padding: 7px 10px 7px 12px;
  white-space: nowrap;
  cursor: pointer;
  font-size: 0.88rem;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.note-tab-pill.active {
  border-color: rgba(103, 232, 249, 0.75);
}

.note-tab-close {
  border: 0;
  background: transparent;
  color: #a8bddf;
  cursor: pointer;
  line-height: 1;
}

.editor-form-open {
  display: flex;
  flex-direction: column;
  min-height: 100%;
  flex: 1;
}

.editor-topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid rgba(71, 115, 179, 0.48);
  padding: 12px 14px;
  background: rgba(13, 24, 43, 0.78);
  backdrop-filter: blur(5px);
  z-index: 1;
}

.editor-topbar input {
  border: 0;
  background: transparent;
  font-size: 1.1rem;
  font-weight: 600;
  padding: 8px 4px;
  width: 100%;
  max-width: 520px;
  color: #ecf4ff;
}

.editor-topbar input:focus {
  outline: none;
  border-bottom: 2px solid rgba(34, 211, 238, 0.8);
  border-radius: 0;
}

.editor-buttons {
  display: flex;
  gap: 8px;
  align-items: center;
}

.editor-right-tools {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}

.note-action-btn {
  display: inline-flex;
  align-items: center;
  min-width: 108px;
  text-align: center;
  justify-content: center;
}

.editor-buttons-mobile {
  display: none;
}

.editor-workspace {
  display: grid;
  grid-template-columns: 1fr 190px;
  min-height: calc(100vh - 235px);
  z-index: 1;
}

.editor-content {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.note-side-actions {
  border-left: 1px solid rgba(71, 115, 179, 0.4);
  background: rgba(13, 24, 43, 0.55);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.note-side-actions .note-action-btn {
  width: 100%;
}

.autosave-control {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: #a9c0e6;
  font-weight: 600;
}

.autosave-control select {
  border: 1px solid rgba(93, 123, 177, 0.5);
  border-radius: 8px;
  background: rgba(16, 31, 54, 0.92);
  color: #e8f2ff;
  padding: 8px 10px;
  min-width: 96px;
}

.btn-secondary {
  text-decoration: none;
}

.editor-form-open textarea {
  border: 0;
  border-radius: 0;
  background: transparent;
  color: #e7f0ff;
  padding: 26px 28px;
  line-height: 1.85;
  font-size: 1.05rem;
  flex: 1;
  min-height: 100%;
  resize: none;
  z-index: 1;
}

.editor-form-open textarea::placeholder {
  color: #7f96bd;
}

.notes-editor-textarea {
  width: 100% !important;
  min-height: 100% !important;
  height: 100%;
}

.markdown-preview {
  padding: 26px 28px;
  line-height: 1.85;
  font-size: 1.02rem;
  color: #e7f0ff;
  z-index: 1;
  min-height: 100%;
  overflow-y: auto;
}

.markdown-preview h1,
.markdown-preview h2,
.markdown-preview h3 {
  margin: 12px 0;
}

.markdown-preview code {
  background: rgba(148, 163, 184, 0.2);
  border-radius: 6px;
  padding: 2px 6px;
}

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

.empty-state {
  border: 1px dashed rgba(103, 232, 249, 0.4);
  border-radius: 8px;
  background: rgba(14, 23, 39, 0.5);
  padding: 24px;
}

@media (max-width: 980px) {
  .notes-page {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .notes-sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--border);
    min-height: auto;
  }

  .editor-topbar {
    flex-wrap: wrap;
  }

  .editor-right-tools {
    margin-left: 0;
    width: 100%;
    flex-wrap: wrap;
    gap: 8px;
  }

  .editor-workspace {
    width: 100%;
    grid-template-columns: 1fr;
    min-height: 52vh;
  }

  .note-side-actions {
    border-left: 0;
    border-top: 1px solid rgba(71, 115, 179, 0.4);
    flex-direction: row;
    flex-wrap: wrap;
  }

  .note-side-actions .note-action-btn {
    width: auto;
    flex: 1;
    min-width: 130px;
  }

  .editor-buttons {
    display: none;
  }

  .editor-buttons-mobile {
    display: flex;
  }

  .editor-form-open textarea {
    min-height: 52vh;
  }

  .notes-editor-textarea {
    min-height: 52vh !important;
  }
}

html[data-theme='light'] {
  --bg: #eff4ff;
  --surface: #ffffff;
  --surface-muted: #f4f8ff;
  --surface-soft: #eaf1fb;
  --text: #16263f;
  --text-muted: #64779c;
  --border: #bfd0ea;
}

html[data-theme='light'] body {
  background:
    radial-gradient(circle at 10% 5%, rgba(34, 211, 238, 0.14), transparent 34%),
    radial-gradient(circle at 80% 10%, rgba(59, 130, 246, 0.16), transparent 38%),
    linear-gradient(145deg, #eef3ff 0%, #f4f8ff 52%, #edf3ff 100%);
  color: var(--text);
}

html[data-theme='light'] .topbar {
  background: rgba(255, 255, 255, 0.88);
  border-bottom: 1px solid rgba(191, 208, 234, 0.8);
}

html[data-theme='light'] .theme-icon-btn {
  background: #eef4ff;
  color: #17355a;
  border-color: #bfd0ea;
}

html[data-theme='light'] .brand {
  color: #10345a;
}

html[data-theme='light'] .notes-page {
  background: #ffffff;
  border-color: #bfd0ea;
}

html[data-theme='light'] .notes-sidebar {
  background: linear-gradient(180deg, #f7faff, #eef4ff);
  border-right-color: #bfd0ea;
}

html[data-theme='light'] .notes-main-open {
  background: linear-gradient(160deg, #ffffff, #f6f9ff);
}

html[data-theme='light'] .open-tabs-bar,
html[data-theme='light'] .editor-topbar {
  background: rgba(245, 250, 255, 0.95);
  border-bottom-color: #bfd0ea;
}

html[data-theme='light'] .note-link strong {
  color: #10233f;
}

html[data-theme='light'] .note-link small {
  color: #6079a3;
}

html[data-theme='light'] .note-tab-pill {
  background: #e8f0ff;
  color: #1f3a63;
}

html[data-theme='light'] .notes-search-box input,
html[data-theme='light'] .autosave-control select {
  background: #ffffff;
  color: #193055;
  border-color: #bfd0ea;
}

html[data-theme='light'] .search-clear-btn {
  color: #5b7298;
}

html[data-theme='light'] .editor-topbar input,
html[data-theme='light'] .editor-form-open textarea,
html[data-theme='light'] .markdown-preview {
  color: #1a2f4f;
}
