/* =====================
   CSS VARIABLES
   ===================== */
:root {
  color-scheme: dark;
  --bg: #10131a;
  --bg-soft: #171c25;
  --panel: #1f2632;
  --panel-strong: #293241;
  --text: #f6f7fb;
  --muted: #aeb7c7;
  --line: rgba(255, 255, 255, 0.1);
  --primary: #2dd4bf;
  --primary-dark: #0f766e;
  --warning: #f59e0b;
  --danger: #fb7185;
  --shadow: 0 22px 70px rgba(0, 0, 0, 0.28);
}

body.light {
  color-scheme: light;
  --bg: #f4f7fb;
  --bg-soft: #e9eef6;
  --panel: #ffffff;
  --panel-strong: #edf2f7;
  --text: #111827;
  --muted: #5b6472;
  --line: rgba(17, 24, 39, 0.11);
  --primary: #0f766e;
  --primary-dark: #115e59;
  --shadow: 0 22px 60px rgba(53, 70, 94, 0.15);
}

/* =====================
   RESET & BASE
   ===================== */
* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  background:
    radial-gradient(
      circle at 10% 0%,
      rgba(45, 212, 191, 0.18),
      transparent 30rem
    ),
    radial-gradient(
      circle at 95% 10%,
      rgba(245, 158, 11, 0.15),
      transparent 28rem
    ),
    var(--bg);
  color: var(--text);
  font-family:
    "Inter",
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
label.file-action {
  border: 0;
  cursor: pointer;
}

/* =====================
   UTILITIES
   ===================== */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* =====================
   BACK LINK
   ===================== */
.back-link {
  position: fixed;
  top: 1rem;
  left: 1rem;
  z-index: 20;
  display: inline-flex;
  align-items: center;
  min-height: 2.5rem;
  padding: 0 0.9rem;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  color: var(--text);
  text-decoration: none;
  box-shadow: var(--shadow);
}

/* =====================
   APP SHELL (sidebar + workspace grid)
   ===================== */
.app-shell {
  display: grid;
  grid-template-columns: 18rem minmax(0, 1fr);
  min-height: 100vh;
  overflow-x: hidden;
}

/* =====================
   SIDEBAR
   ===================== */
.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  height: 100vh;
  padding: 4.75rem 1.25rem 1.25rem;
  border-right: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel) 80%, transparent);
  backdrop-filter: blur(20px);
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.9rem;
}

.brand-logo {
  width: 3.2rem;
  height: 3.2rem;
  border-radius: 0.8rem;
  object-fit: cover;
  flex-shrink: 0;
  box-shadow: 0 12px 30px rgba(45, 212, 191, 0.18);
}

.eyebrow {
  display: block;
  margin-bottom: 0.25rem;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.brand h1,
.topbar h2,
.note-modal h2 {
  margin: 0;
  letter-spacing: 0;
}

.brand h1 {
  font-size: 1.35rem;
}

/* =====================
   BUTTONS (shared)
   ===================== */
.primary-action,
.secondary-action,
.ghost-action,
.theme-toggle,
.icon-button,
.card-button {
  min-height: 2.65rem;
  border-radius: 0.5rem;
  font-weight: 800;
  transition:
    transform 180ms ease,
    border-color 180ms ease,
    background 180ms ease;
}

.primary-action {
  padding: 0 1rem;
  background: var(--primary);
  color: #06221f;
}

body.light .primary-action {
  color: #ffffff;
}

.primary-action:hover,
.secondary-action:hover,
.ghost-action:hover,
.theme-toggle:hover,
.icon-button:hover,
.card-button:hover {
  transform: translateY(-1px);
}

.compact {
  display: none;
}

/* =====================
   SIDEBAR NAV
   ===================== */
.nav-list {
  display: grid;
  gap: 0.55rem;
}

.nav-item,
.ghost-action {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 0.85rem;
  border: 1px solid transparent;
  border-radius: 0.5rem;
  background: transparent;
  color: var(--muted);
  text-align: left;
}

.nav-item.active,
.nav-item:hover,
.ghost-action:hover {
  border-color: var(--line);
  background: var(--panel-strong);
  color: var(--text);
}

.nav-item strong {
  min-width: 1.9rem;
  padding: 0.2rem 0.45rem;
  border-radius: 999px;
  background: var(--bg-soft);
  color: var(--text);
  font-size: 0.8rem;
  text-align: center;
}

/* =====================
   TAGS
   ===================== */
.tag-panel {
  padding-top: 0.25rem;
}

.panel-title {
  margin-bottom: 0.7rem;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.tag-chip {
  min-height: 2rem;
  padding: 0 0.7rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg-soft);
  color: var(--text);
  font-size: 0.85rem;
}

.tag-chip.active {
  border-color: var(--primary);
  color: var(--primary);
}

/* =====================
   SIDEBAR ACTIONS
   ===================== */
.sidebar-actions {
  display: grid;
  gap: 0.55rem;
  margin-top: auto;
  padding-top: 0.5rem;
}

#importInput {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

/* =====================
   WORKSPACE
   ===================== */
.workspace {
  min-width: 0;
  padding: 2rem;
}

/* =====================
   TOPBAR
   ===================== */
.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1.25rem;
  margin-bottom: 1.25rem;
}

.topbar h2 {
  font-size: clamp(1.75rem, 3.5vw, 3.8rem);
  line-height: 1.1;
  word-break: break-word;
}

.topbar p {
  margin: 0.6rem 0 0;
  color: var(--muted);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  flex-shrink: 0;
}

/* =====================
   SEARCH BOX
   ===================== */
.search-box {
  display: grid;
  gap: 0.25rem;
  width: min(24rem, 42vw);
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: var(--panel);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.search-box input {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-size: 0.98rem;
  font-weight: 500;
  text-transform: none;
}

/* =====================
   SECONDARY / THEME BUTTONS
   ===================== */
.theme-toggle,
.secondary-action,
.icon-button,
.card-button {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
}

.theme-toggle {
  padding: 0 0.9rem;
  white-space: nowrap;
}

/* =====================
   QUICK STATS
   ===================== */
.quick-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.8rem;
  margin-bottom: 1.5rem;
}

.quick-stats article {
  min-height: 5.4rem;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: var(--panel);
}

.quick-stats span {
  display: block;
  margin-bottom: 0.5rem;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.quick-stats strong {
  display: block;
  overflow: hidden;
  color: var(--text);
  font-size: clamp(1.35rem, 2vw, 2rem);
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* =====================
   NOTES GRID
   ===================== */
.notes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(17rem, 1fr));
  gap: 1rem;
}

/* =====================
   NOTE CARD
   ===================== */
.note-card,
.empty-state {
  min-height: 17rem;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.note-card {
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
  padding: 1rem;
}

.note-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 0.35rem;
  background: var(--accent, var(--primary));
}

/* =====================
   THEME COLORS (12 total)
   ===================== */
.note-card[data-color="teal"] {
  --accent: #2dd4bf;
}

.note-card[data-color="violet"] {
  --accent: #8b5cf6;
}

.note-card[data-color="amber"] {
  --accent: #f59e0b;
}

.note-card[data-color="rose"] {
  --accent: #fb7185;
}

.note-card[data-color="blue"] {
  --accent: #3b82f6;
}

.note-card[data-color="green"] {
  --accent: #22c55e;
}

.note-card[data-color="purple"] {
  --accent: #a855f7;
}

.note-card[data-color="orange"] {
  --accent: #f97316;
}

.note-card[data-color="pink"] {
  --accent: #ec4899;
}

.note-card[data-color="yellow"] {
  --accent: #eab308;
}

.note-card[data-color="indigo"] {
  --accent: #6366f1;
}

.note-card[data-color="red"] {
  --accent: #ef4444;
}

/* =====================
   NOTE CARD BODY
   ===================== */
.card-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  min-height: 0;
}

.card-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.35rem;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.card-meta span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.note-card h3 {
  margin: 0.75rem 0 0.5rem;
  font-size: 1.2rem;
  letter-spacing: 0;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.note-card p {
  display: -webkit-box;
  flex: 1;
  overflow: hidden;
  margin: 0;
  color: color-mix(in srgb, var(--text) 82%, var(--muted));
  line-height: 1.6;
  word-break: break-word;
  overflow-wrap: anywhere;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 6;
}

/* =====================
   NOTE CARD FOOTER
   ===================== */
.note-card footer {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  margin-top: auto;
  padding-top: 0.75rem;
  border-top: 1px solid var(--line);
}

.badge {
  max-width: 8rem;
  overflow: hidden;
  padding: 0.35rem 0.65rem;
  border-radius: 999px;
  background: var(--bg-soft);
  color: var(--text);
  font-size: 0.78rem;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex-shrink: 0;
}

/* =====================
   CARD ACTIONS
   ===================== */
.card-actions {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.5rem;
  flex: 1;
  min-width: 0;
}

.card-button {
  width: 100%;
  justify-content: center;
  font-size: 0.82rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-button.active {
  border-color: color-mix(in srgb, var(--warning) 80%, transparent);
  color: var(--warning);
}

.card-button.danger {
  color: var(--danger);
}

/* =====================
   EMPTY STATE
   ===================== */
.empty-state {
  grid-column: 1 / -1;
  display: grid;
  place-items: center;
  padding: 2rem;
  color: var(--muted);
  text-align: center;
}

/* =====================
   LOCK STYLES
   ===================== */
.lock-badge {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  z-index: 2;
  font-size: 1rem;
  line-height: 1;
}

.note-card.is-locked {
  border-color: color-mix(
    in srgb,
    var(--accent, var(--primary)) 40%,
    transparent
  );
}

.locked-overlay {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem 0;
}

.locked-message {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
  text-align: center;
  color: var(--muted);
}

.locked-message .lock-icon-big {
  font-size: 2rem;
  line-height: 1;
}

.locked-message p {
  margin: 0;
  font-size: 0.88rem;
  display: block !important;
  -webkit-line-clamp: unset !important;
}

.unlock-btn {
  min-height: 2rem !important;
  padding: 0 0.8rem !important;
  font-size: 0.82rem;
}

/* =====================
   MODAL STYLES
   ===================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(4, 8, 15, 0.68);
  backdrop-filter: blur(12px);
}

.modal-overlay[hidden] {
  display: none;
}

.note-modal {
  width: min(42rem, 100%);
  max-height: calc(100vh - 2rem);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 0.6rem;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.note-modal form {
  display: grid;
  gap: 0.8rem;
  padding: 1.5rem;
}

.modal-header,
.modal-actions,
.checkbox-row,
.form-row {
  display: flex;
  gap: 0.8rem;
}

.modal-header,
.modal-actions {
  align-items: center;
  justify-content: space-between;
}

.icon-button {
  width: 2.5rem;
  padding: 0;
  flex-shrink: 0;
}

.note-modal label {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}

.note-modal input[type="text"],
.note-modal input[type="password"],
.note-modal textarea,
.note-modal select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  outline: 0;
  background: var(--bg-soft);
  color: var(--text);
}

.note-modal input[type="text"],
.note-modal input[type="password"],
.note-modal select {
  min-height: 2.8rem;
  padding: 0 0.75rem;
}

.note-modal textarea {
  min-height: 12rem;
  padding: 0.75rem;
  resize: vertical;
}

.note-modal input:focus,
.note-modal textarea:focus,
.note-modal select:focus {
  border-color: var(--primary);
}

.form-row > div {
  flex: 1;
  min-width: 0;
}

.checkbox-row {
  flex-wrap: wrap;
}

.checkbox-row label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 2.5rem;
  padding: 0 0.75rem;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: var(--bg-soft);
  color: var(--text);
  white-space: nowrap;
  flex: 1 1 auto;
  min-width: max-content;
}

.secondary-action {
  padding: 0 1rem;
}

/* Password field in editor */
.password-field {
  display: grid;
  gap: 0.4rem;
}

/* =====================
   UNLOCK MODAL
   ===================== */
.unlock-modal {
  width: min(26rem, 100%);
}

.unlock-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  padding: 2rem 1.5rem;
  text-align: center;
}

.unlock-body .lock-icon-big {
  font-size: 2.5rem;
  line-height: 1;
}

.unlock-body h2 {
  margin: 0;
  font-size: 1.3rem;
}

.unlock-body p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.unlock-body input[type="password"] {
  width: 100%;
  min-height: 2.8rem;
  padding: 0 0.75rem;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  outline: 0;
  background: var(--bg-soft);
  color: var(--text);
  text-align: center;
  font-size: 1rem;
}

.unlock-body input[type="password"]:focus {
  border-color: var(--primary);
}

.unlock-actions {
  display: flex;
  gap: 0.8rem;
  width: 100%;
  justify-content: center;
}

.unlock-error {
  color: var(--danger);
  font-size: 0.85rem;
  min-height: 1.2rem;
  margin: 0;
}

/* =====================
   TOAST
   ===================== */
.toast {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 40;
  max-width: min(24rem, calc(100vw - 2rem));
  padding: 0.9rem 1rem;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(0.75rem);
  pointer-events: none;
  transition:
    opacity 180ms ease,
    transform 180ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

/* =====================
   RESPONSIVE — TABLET (≤980px)
   ===================== */
@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    padding: 4.5rem 1rem 1rem;
    overflow-y: visible;
  }

  .workspace {
    padding: 1.25rem;
  }

  .topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .topbar-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .search-box {
    width: 100%;
  }

  .compact {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .topbar h2 {
    font-size: clamp(1.5rem, 5vw, 2.5rem);
  }

  .notes-grid {
    grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
  }
}

/* =====================
   RESPONSIVE — SMALL TABLET (≤768px)
   ===================== */
@media (max-width: 768px) {
  .quick-stats {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.6rem;
  }

  .quick-stats article {
    min-height: 4.5rem;
    padding: 0.75rem;
  }

  .quick-stats strong {
    font-size: 1.2rem;
  }

  .notes-grid {
    grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr));
    gap: 0.8rem;
  }

  .note-card {
    min-height: 14rem;
  }

  .card-actions {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.4rem;
  }

  .card-button {
    min-height: 2.3rem;
    font-size: 0.78rem;
  }
}

/* =====================
   RESPONSIVE — MOBILE (≤640px)
   ===================== */
@media (max-width: 640px) {
  .workspace {
    padding: 1rem;
  }

  .quick-stats {
    grid-template-columns: 1fr;
  }

  .form-row {
    flex-direction: column;
  }

  .modal-actions {
    flex-direction: column;
  }

  .modal-actions button {
    width: 100%;
  }

  .notes-grid {
    grid-template-columns: 1fr;
  }

  .note-card {
    min-height: auto;
  }

  .note-card footer {
    flex-direction: column;
    align-items: stretch;
  }

  .card-actions {
    grid-template-columns: repeat(2, 1fr);
    width: 100%;
  }

  .checkbox-row {
    flex-direction: column;
  }

  .checkbox-row label {
    width: 100%;
    min-width: 0;
  }

  .note-modal form {
    padding: 1rem;
  }

  .topbar h2 {
    font-size: 1.5rem;
  }

  .sidebar {
    padding: 4rem 0.75rem 0.75rem;
  }

  .back-link {
    top: 0.5rem;
    left: 0.5rem;
    min-height: 2.2rem;
    padding: 0 0.7rem;
    font-size: 0.88rem;
  }
}
