/* ═══════════════════════════════════════════════════
   TOKENS & RESET
════════════════════════════════════════════════════ */
:root {
  /* Brand */
  --accent: #EC5B13;
  --accent-hover: #D55211;
  --accent-soft: #FEF0E7;

  /* Surfaces */
  --bg: #F5F4F0;
  --surface: #FFFFFF;
  --surface-alt: #F9F8F6;
  --sidebar-bg: #1A1A1A;
  --sidebar-text: #E8E5DF;
  --sidebar-muted: #9A9590;
  --sidebar-hover: #2A2A2A;
  --sidebar-active: #333330;

  /* Text */
  --text-primary: #111210;
  --text-secondary: #6B6860;
  --text-muted: #A8A49E;

  /* Borders */
  --border: #E4E2DC;
  --border-focus: #EC5B13;

  /* Sizing */
  --sidebar-w: 300px;
  --header-h: 64px;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, .08), 0 1px 2px rgba(0, 0, 0, .06);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, .10), 0 2px 4px rgba(0, 0, 0, .06);
  --shadow-lg: 0 20px 40px rgba(0, 0, 0, .18), 0 8px 16px rgba(0, 0, 0, .10);

  /* Typography */
  --font-sans: 'DM Sans', sans-serif;
  --font-serif: 'DM Serif Display', serif;

  /* Transitions */
  --ease: cubic-bezier(.4, 0, .2, 1);
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text-primary);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

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

img {
  display: block;
  max-width: 100%;
}


/* ═══════════════════════════════════════════════════
   APP SHELL  — side-by-side on desktop
════════════════════════════════════════════════════ */
.app-shell {
  display: flex;
  height: 100vh;
  overflow: hidden;
}


/* ═══════════════════════════════════════════════════
   SIDEBAR
════════════════════════════════════════════════════ */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  max-width: var(--sidebar-w);
  height: 100vh;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
  transition: transform .3s var(--ease);
  z-index: 50;
}

.sidebar-inner {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

/* ── Sidebar Header ── */
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.25rem 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, .06);
  flex-shrink: 0;
}

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

.brand-title {
  font-family: var(--font-serif);
  font-size: 1.5rem;
  font-weight: 400;
  letter-spacing: -.01em;
  color: var(--sidebar-text);
}

/* ── Search ── */
.search-wrap {
  position: relative;
  padding: 1rem 1.25rem .75rem;
  flex-shrink: 0;
}

.search-icon {
  position: absolute;
  left: 2rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--sidebar-muted);
  pointer-events: none;
}

.search-input {
  width: 100%;
  background: rgba(255, 255, 255, .07);
  border: 1px solid rgba(255, 255, 255, .10);
  border-radius: var(--radius-md);
  padding: .6rem 1rem .6rem 2.4rem;
  font-size: .875rem;
  color: var(--sidebar-text);
  outline: none;
  transition: border-color .2s, background .2s;
}

.search-input::placeholder {
  color: var(--sidebar-muted);
}

.search-input:focus {
  border-color: var(--accent);
  background: rgba(255, 255, 255, .10);
}

/* Hide browser "X" in search inputs */
.search-input::-webkit-search-cancel-button {
  display: none;
}

/* ── Notes meta ── */
.notes-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .25rem 1.25rem .75rem;
  flex-shrink: 0;
}

.notes-label {
  font-size: .7rem;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--sidebar-muted);
}

.notes-count {
  font-size: .7rem;
  font-weight: 600;
  background: rgba(236, 91, 19, .25);
  color: var(--accent);
  border-radius: 20px;
  padding: .15rem .5rem;
  min-width: 1.5rem;
  text-align: center;
}

/* ── Notes list ── */
.notes-list {
  flex: 1;
  overflow-y: auto;
  padding: .25rem 0 5rem;
  /* bottom room for FAB on mobile */
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, .12) transparent;
}

.notes-list::-webkit-scrollbar {
  width: 4px;
}

.notes-list::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, .12);
  border-radius: 4px;
}

/* Note card in sidebar */
.note-card {
  display: flex;
  flex-direction: column;
  gap: .25rem;
  padding: .875rem 1.25rem;
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: background .15s, border-color .15s;
  position: relative;
}

.note-card:hover {
  background: var(--sidebar-hover);
  border-left-color: rgba(236, 91, 19, .4);
}

.note-card.active {
  background: var(--sidebar-active);
  border-left-color: var(--accent);
}

.note-card-title {
  font-size: .9rem;
  font-weight: 500;
  color: var(--sidebar-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.note-card-snippet {
  font-size: .78rem;
  color: var(--sidebar-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.note-card-date {
  font-size: .7rem;
  color: var(--sidebar-muted);
  opacity: .7;
}

/* Divider between cards */
.note-card+.note-card {
  border-top: 1px solid rgba(255, 255, 255, .04);
}

/* Empty list message */
.list-empty {
  padding: 2.5rem 1.25rem;
  text-align: center;
  color: var(--sidebar-muted);
  font-size: .85rem;
  line-height: 1.6;
}

.list-empty strong {
  display: block;
  font-size: .9rem;
  color: var(--sidebar-text);
  margin-bottom: .35rem;
}


/* ═══════════════════════════════════════════════════
   DETAIL PANEL
════════════════════════════════════════════════════ */
.detail-panel {
  flex: 1;
  height: 100vh;
  overflow-y: auto;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  min-width: 0;
  /* prevents overflow in flex */
}

/* ── Empty state ── */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .85rem;
  padding: 3rem 2rem;
  text-align: center;
}

.empty-title {
  font-family: var(--font-serif);
  font-size: 1.5rem;
  font-weight: 400;
  color: var(--text-primary);
}

.empty-sub {
  font-size: .9rem;
  color: var(--text-secondary);
  max-width: 22rem;
  line-height: 1.6;
}

/* ── Note viewer ── */
.note-viewer {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.viewer-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 2rem;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 10;
  gap: 1rem;
}

.viewer-actions {
  display: flex;
  gap: .75rem;
  align-items: center;
}

.viewer-body {
  flex: 1;
  padding: 2.5rem 2.5rem 4rem;
  overflow-y: auto;
}

.viewer-title {
  font-family: var(--font-serif);
  font-size: 2rem;
  font-weight: 400;
  color: var(--text-primary);
  line-height: 1.2;
  letter-spacing: -.02em;
  margin-bottom: .4rem;
}

.viewer-date {
  font-size: .78rem;
  color: var(--text-muted);
  margin-bottom: 2rem;
  letter-spacing: .02em;
}

.viewer-content {
  width: 100%;
  font-size: 1rem;
  line-height: 1.85;
  color: var(--text-secondary);
  white-space: pre-wrap;
  word-break: break-word;
  background: transparent;
  border: 1.5px solid transparent;
  outline: none;
  resize: none;
  font-family: var(--font-sans);
  cursor: default;
  min-height: 300px;
  border-radius: var(--radius-md);
  padding: .25rem 0;
  transition: background .2s, border-color .2s, padding .2s, box-shadow .2s;
}

.viewer-content.editing {
  background: var(--surface-alt);
  border-color: var(--accent);
  padding: .875rem 1rem;
  cursor: text;
  box-shadow: 0 0 0 3px rgba(236, 91, 19, .12);
}


/* ═══════════════════════════════════════════════════
   SHARED BUTTON STYLES
════════════════════════════════════════════════════ */
.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: .65rem 1.4rem;
  font-size: .875rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .2s, transform .1s;
  white-space: nowrap;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-primary:active {
  transform: scale(.97);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .65rem 1.4rem;
  font-size: .875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background .2s, color .2s;
  white-space: nowrap;
}

.btn-ghost:hover {
  background: var(--surface-alt);
  color: var(--text-primary);
}

.btn-danger {
  background: transparent;
  color: #DC2626;
  border: 1px solid #FECACA;
  border-radius: var(--radius-sm);
  padding: .65rem 1.2rem;
  font-size: .875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background .2s;
  white-space: nowrap;
}

.btn-danger:hover {
  background: #FEF2F2;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border: none;
  background: rgba(255, 255, 255, .08);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--sidebar-text);
  transition: background .2s;
  flex-shrink: 0;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, .14);
}

/* Icon btn in light context (toolbar) */
.viewer-toolbar .icon-btn {
  background: var(--surface-alt);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.viewer-toolbar .icon-btn:hover {
  background: var(--border);
  color: var(--text-primary);
}


/* ═══════════════════════════════════════════════════
   FAB  (floating action button, mobile only)
════════════════════════════════════════════════════ */
.fab {
  display: none;
  /* hidden on desktop */
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(236, 91, 19, .5);
  z-index: 200;
  transition: background .2s, transform .2s;
}

.fab:hover {
  background: var(--accent-hover);
  transform: scale(1.07);
}

.fab:active {
  transform: scale(.94);
}


/* ═══════════════════════════════════════════════════
   MODAL — Add / Edit Note
════════════════════════════════════════════════════ */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .55);
  backdrop-filter: blur(4px);
  z-index: 500;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-overlay.open {
  display: flex;
}

.modal-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 540px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 2rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  box-shadow: var(--shadow-lg);
  animation: modalIn .22s var(--ease);
}

@keyframes modalIn {
  from {
    opacity: 0;
    transform: translateY(12px) scale(.97);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

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

.modal-heading {
  font-family: var(--font-serif);
  font-size: 1.4rem;
  font-weight: 400;
  color: var(--text-primary);
}

/* In modal, icon-btn is in light context */
.modal-card .icon-btn {
  background: var(--surface-alt);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.modal-card .icon-btn:hover {
  background: var(--border);
  color: var(--text-primary);
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: .5rem;
}

.form-label {
  font-size: .78rem;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.form-input {
  width: 100%;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  padding: .75rem 1rem;
  font-size: .95rem;
  color: var(--text-primary);
  background: var(--surface-alt);
  outline: none;
  transition: border-color .2s, box-shadow .2s;
}

.form-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(236, 91, 19, .12);
}

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

.form-textarea {
  width: 100%;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  padding: .875rem 1rem;
  font-size: .95rem;
  line-height: 1.7;
  color: var(--text-primary);
  background: var(--surface-alt);
  outline: none;
  resize: vertical;
  min-height: 200px;
  transition: border-color .2s, box-shadow .2s;
}

.form-textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(236, 91, 19, .12);
}

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

.modal-footer {
  display: flex;
  gap: .75rem;
  justify-content: flex-end;
  margin-top: .25rem;
}


/* ═══════════════════════════════════════════════════
   MOBILE  (≤ 768px) — single-column, show sidebar OR detail
════════════════════════════════════════════════════ */
.mobile-back {
  display: none;
}

@media (max-width: 768px) {

  .app-shell {
    position: relative;
    overflow: hidden;
  }

  /* Both panels fill the full screen */
  .sidebar {
    position: absolute;
    inset: 0;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    transform: translateX(0);
    transition: transform .3s var(--ease);
    z-index: 40;
  }

  .detail-panel {
    position: absolute;
    inset: 0;
    transform: translateX(100%);
    transition: transform .3s var(--ease);
    z-index: 41;
  }

  /* When detail is "open" on mobile */
  .app-shell.detail-open .sidebar {
    transform: translateX(-30%);
  }

  .app-shell.detail-open .detail-panel {
    transform: translateX(0);
  }

  /* Show FAB on mobile */
  .fab {
    display: flex;
  }

  /* Hide the header "+ button" on mobile (FAB replaces it) */
  .sidebar-header .icon-btn {
    display: none;
  }

  /* Show back button in viewer toolbar */
  .mobile-back {
    display: flex;
  }

  .notes-list {
    padding-bottom: 6rem;
  }

  /* extra room for FAB */

  .viewer-body {
    padding: 1.5rem 1.25rem 5rem;
  }

  .viewer-title {
    font-size: 1.5rem;
  }

  .viewer-toolbar {
    padding: .875rem 1.25rem;
  }

  .modal-card {
    padding: 1.5rem 1.25rem;
    border-radius: var(--radius-md);
  }

  /* Full-screen modal on very small phones */
  @media (max-width: 480px) {
    .modal-overlay {
      align-items: flex-end;
      padding: 0;
    }

    .modal-card {
      max-height: 95vh;
      border-bottom-left-radius: 0;
      border-bottom-right-radius: 0;
      border-radius: var(--radius-lg) var(--radius-lg) 0 0;
      animation: slideUp .25s var(--ease);
    }

    @keyframes slideUp {
      from {
        transform: translateY(100%);
      }

      to {
        transform: translateY(0);
      }
    }
  }
}

/* Slightly narrower sidebar on medium tablets */
@media (min-width: 769px) and (max-width: 1024px) {
  :root {
    --sidebar-w: 260px;
  }
}

/* Wider sidebar on large screens */
@media (min-width: 1400px) {
  :root {
    --sidebar-w: 340px;
  }

  .viewer-body {
    padding: 3rem 4rem 5rem;
  }
}


/* ═══════════════════════════════════════════════════
   SCROLLBAR — detail panel
════════════════════════════════════════════════════ */
.detail-panel::-webkit-scrollbar {
  width: 5px;
}

.detail-panel::-webkit-scrollbar-track {
  background: transparent;
}

.detail-panel::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

.detail-panel {
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}


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