/* ============================================================
   INKWELL — STYLES
   Aesthetic: Warm editorial notebook / parchment
   Fonts: Playfair Display + Crimson Pro
   ============================================================ */

:root {
  --bg:         #F2EAD8;
  --bg-dark:    #1C1510;
  --surface:    #FDFAF4;
  --surface-2:  #F5EFE0;
  --ink:        #1C1510;
  --ink-2:      #4A3F35;
  --ink-3:      #8C7A65;
  --ink-4:      #BFB09F;
  --accent:     #B85C2C;
  --accent-2:   #D4722E;
  --border:     #DDD3C2;
  --border-2:   #CFC2AE;
  --sidebar-w:  300px;
  --topbar-h:   56px;
  --radius:     12px;
  --radius-sm:  8px;
  --shadow:     0 2px 16px rgba(28,21,16,0.10);
  --shadow-lg:  0 8px 40px rgba(28,21,16,0.18);
  --font-disp:  'Playfair Display', Georgia, serif;
  --font-body:  'Crimson Pro', 'Georgia', serif;
  --ease:       cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

/* ---- RESET ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--ink);
  overflow: hidden;
  height: 100dvh;
  -webkit-font-smoothing: antialiased;
}
input, textarea, button { font-family: inherit; }
button { cursor: pointer; border: none; background: none; }

/* ============================================================
   SCREENS
   ============================================================ */
.screen {
  position: fixed; inset: 0;
  opacity: 0; pointer-events: none;
  transition: opacity 0.35s var(--ease);
}
.screen.active {
  opacity: 1; pointer-events: all;
}

/* ============================================================
   LOGIN SCREEN
   ============================================================ */
#login-screen {
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-dark);
  overflow: hidden;
}

.login-bg {
  position: absolute; inset: 0;
}
.login-noise {
  position: absolute; inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.08'/%3E%3C/svg%3E");
  opacity: 0.4;
}
.login-lines {
  position: absolute; inset: 0;
  background-image: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 39px,
    rgba(242,234,216,0.04) 39px,
    rgba(242,234,216,0.04) 40px
  );
}

.login-card {
  position: relative; z-index: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px 36px 44px;
  width: 100%; max-width: 380px;
  box-shadow: var(--shadow-lg), 0 0 0 1px rgba(255,255,255,0.05);
  animation: cardIn 0.6s var(--ease) both;
}
@keyframes cardIn {
  from { opacity: 0; transform: translateY(24px); }
  to   { opacity: 1; transform: translateY(0); }
}

.login-logo {
  color: var(--accent);
  margin-bottom: 12px;
}
.login-title {
  font-family: var(--font-disp);
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--ink);
  line-height: 1;
  margin-bottom: 6px;
}
.login-subtitle {
  font-size: 1rem;
  color: var(--ink-3);
  font-style: italic;
  margin-bottom: 32px;
}

.field-group {
  margin-bottom: 18px;
}
.field-group label {
  display: block;
  font-size: 0.78rem;
  font-family: var(--font-body);
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-2);
  margin-bottom: 6px;
}
.field-group input {
  width: 100%;
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 1rem;
  color: var(--ink);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.field-group input::placeholder { color: var(--ink-4); }
.field-group input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(184,92,44,0.12);
}

.login-error {
  background: rgba(184,92,44,0.10);
  border: 1px solid rgba(184,92,44,0.30);
  color: var(--accent);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 0.9rem;
  margin-bottom: 16px;
}

.btn-primary {
  width: 100%;
  background: var(--ink);
  color: var(--surface);
  border-radius: var(--radius-sm);
  padding: 12px 20px;
  font-size: 1rem;
  font-weight: 500;
  letter-spacing: 0.03em;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  transition: background 0.2s, transform 0.1s;
  margin-top: 8px;
}
.btn-primary:hover { background: var(--accent); }
.btn-primary:active { transform: scale(0.98); }
.btn-primary:disabled { opacity: 0.55; pointer-events: none; }

.spin { animation: spinAnim 1s linear infinite; transform-origin: center; }
@keyframes spinAnim { to { stroke-dashoffset: -30; } }

/* ============================================================
   TOPBAR
   ============================================================ */
.topbar {
  position: fixed; top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  background: var(--bg-dark);
  color: var(--bg);
  display: flex; align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 100;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.topbar-left, .topbar-right {
  display: flex; align-items: center; gap: 12px;
}
.topbar-brand {
  display: flex; align-items: center; gap: 8px;
  font-family: var(--font-disp);
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--surface);
  letter-spacing: -0.01em;
}

.icon-btn {
  color: var(--ink-4);
  width: 36px; height: 36px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s, color 0.15s;
}
.icon-btn:hover { background: rgba(255,255,255,0.08); color: var(--bg); }

/* Sync status */
.sync-status {
  display: flex; align-items: center; gap: 6px;
  font-size: 0.78rem;
  color: var(--ink-3);
  letter-spacing: 0.01em;
}
.sync-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: #6DBF87;
  transition: background 0.3s;
}
.sync-status.syncing .sync-dot {
  background: #E8B94A;
  animation: pulse 1s ease infinite;
}
.sync-status.error .sync-dot { background: #D95F5F; }
.sync-status.offline .sync-dot { background: var(--ink-4); }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.3; } }

.offline-badge {
  background: rgba(217,95,95,0.18);
  color: #D95F5F;
  border: 1px solid rgba(217,95,95,0.3);
  border-radius: 6px;
  padding: 3px 10px;
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.04em;
}

.btn-install {
  background: rgba(184,92,44,0.20);
  color: var(--accent-2);
  border: 1px solid rgba(184,92,44,0.35);
  border-radius: 8px;
  padding: 5px 14px;
  font-size: 0.82rem;
  font-weight: 500;
  transition: background 0.2s;
}
.btn-install:hover { background: rgba(184,92,44,0.32); }

.user-pill {
  display: flex; align-items: center; gap: 8px;
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 20px;
  padding: 4px 6px 4px 12px;
}
.user-pill span {
  font-size: 0.85rem;
  color: rgba(255,255,255,0.75);
  letter-spacing: 0.02em;
}
.user-pill button {
  width: 28px; height: 28px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: rgba(255,255,255,0.5);
  transition: background 0.15s, color 0.15s;
}
.user-pill button:hover { background: rgba(255,255,255,0.12); color: #fff; }

/* ============================================================
   APP BODY LAYOUT
   ============================================================ */
#app-screen {
  display: flex; flex-direction: column;
}
.app-body {
  display: flex;
  margin-top: var(--topbar-h);
  height: calc(100dvh - var(--topbar-h));
  overflow: hidden;
}

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--surface-2);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow: hidden;
  transition: transform 0.3s var(--ease), width 0.3s var(--ease);
}

.sidebar-header {
  padding: 14px 12px 10px;
  display: flex; align-items: center; gap: 8px;
  border-bottom: 1px solid var(--border);
}
.search-wrap {
  flex: 1;
  position: relative;
  display: flex; align-items: center;
}
.search-icon {
  position: absolute; left: 10px;
  color: var(--ink-3);
  pointer-events: none;
}
.search-wrap input {
  width: 100%;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px 7px 32px;
  font-size: 0.9rem;
  color: var(--ink);
  outline: none;
  transition: border-color 0.2s;
}
.search-wrap input:focus { border-color: var(--accent); }
.search-wrap input::placeholder { color: var(--ink-4); }

.btn-new-note {
  width: 36px; height: 36px; min-width: 36px;
  background: var(--accent);
  color: #fff;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.2s, transform 0.1s;
  box-shadow: 0 2px 8px rgba(184,92,44,0.30);
}
.btn-new-note:hover { background: var(--accent-2); }
.btn-new-note:active { transform: scale(0.93); }

.sidebar-filter {
  display: flex;
  padding: 8px 12px;
  gap: 4px;
  border-bottom: 1px solid var(--border);
}
.filter-tab {
  flex: 1;
  padding: 6px 8px;
  border-radius: 7px;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--ink-3);
  transition: background 0.15s, color 0.15s;
  letter-spacing: 0.01em;
}
.filter-tab.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 4px rgba(28,21,16,0.08);
}

.notes-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}
.notes-list::-webkit-scrollbar { width: 5px; }
.notes-list::-webkit-scrollbar-track { background: transparent; }
.notes-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* Note card */
.note-card {
  background: var(--surface);
  border: 1.5px solid transparent;
  border-radius: 10px;
  padding: 14px 14px 12px;
  margin-bottom: 6px;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.1s;
  position: relative;
}
.note-card:hover {
  border-color: var(--border-2);
  box-shadow: 0 2px 10px rgba(28,21,16,0.07);
}
.note-card.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(184,92,44,0.10);
}
.note-card.pending::after {
  content: '';
  position: absolute; top: 10px; right: 10px;
  width: 7px; height: 7px; border-radius: 50%;
  background: #E8B94A;
  box-shadow: 0 0 0 2px var(--surface);
}
.note-card-title {
  font-family: var(--font-disp);
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 4px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.note-card-title.untitled { color: var(--ink-4); font-style: italic; font-weight: 400; }
.note-card-preview {
  font-size: 0.85rem;
  color: var(--ink-3);
  line-height: 1.4;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  margin-bottom: 8px;
}
.note-card-meta {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 0.74rem;
  color: var(--ink-4);
}
.note-card-author {
  font-weight: 500;
  color: var(--accent);
  font-size: 0.72rem;
}

/* Empty state */
.empty-state {
  display: flex; flex-direction: column; align-items: center;
  padding: 48px 20px;
  color: var(--ink-4);
  text-align: center;
  gap: 12px;
}
.empty-state p { font-size: 0.9rem; line-height: 1.6; }

/* ============================================================
   EDITOR
   ============================================================ */
.editor-panel {
  flex: 1;
  display: flex; flex-direction: column;
  background: var(--surface);
  overflow: hidden;
  position: relative;
}

.editor-placeholder {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: var(--ink-4);
  gap: 16px;
  text-align: center;
}
.editor-placeholder p { font-size: 1rem; line-height: 1.7; font-style: italic; }

.editor-content {
  display: flex; flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.editor-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}
.color-swatches {
  display: flex; gap: 6px;
}
.color-swatch {
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 2px solid transparent;
  transition: border-color 0.15s, transform 0.1s;
  box-shadow: 0 1px 4px rgba(28,21,16,0.15);
}
.color-swatch:hover { transform: scale(1.15); }
.color-swatch.active { border-color: var(--accent); }

.editor-actions {
  display: flex; align-items: center; gap: 10px;
}
.note-author-badge {
  font-size: 0.75rem;
  color: var(--accent);
  font-weight: 500;
  letter-spacing: 0.02em;
}
.note-date {
  font-size: 0.78rem;
  color: var(--ink-4);
}
.btn-danger-sm {
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 7px;
  color: var(--ink-3);
  transition: background 0.15s, color 0.15s;
}
.btn-danger-sm:hover { background: rgba(217,95,95,0.12); color: #D95F5F; }

.editor-body {
  flex: 1;
  display: flex; flex-direction: column;
  overflow: hidden;
  padding: 28px 32px;
}

.note-title-input {
  font-family: var(--font-disp);
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--ink);
  border: none; outline: none;
  background: transparent;
  width: 100%;
  padding: 0 0 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
  letter-spacing: -0.02em;
  line-height: 1.2;
}
.note-title-input::placeholder { color: var(--ink-4); }

.note-content-input {
  flex: 1;
  font-family: var(--font-body);
  font-size: 1.05rem;
  line-height: 1.8;
  color: var(--ink-2);
  border: none; outline: none;
  background: transparent;
  resize: none;
  width: 100%;
}
.note-content-input::placeholder { color: var(--ink-4); font-style: italic; }

/* ============================================================
   DELETE MODAL
   ============================================================ */
.modal-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(28,21,16,0.55);
  display: flex; align-items: center; justify-content: center;
  animation: fadeIn 0.2s ease;
}
.modal-overlay[hidden] {
  display: none;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal-box {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 28px 28px 24px;
  max-width: 360px; width: 90%;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.25s var(--ease);
}
@keyframes slideUp { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: translateY(0); } }
.modal-box h3 {
  font-family: var(--font-disp);
  font-size: 1.2rem;
  font-weight: 600;
  margin-bottom: 8px;
}
.modal-box p { font-size: 0.95rem; color: var(--ink-3); margin-bottom: 24px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }
.btn-secondary {
  padding: 9px 20px;
  border-radius: 8px;
  font-size: 0.9rem;
  background: var(--bg);
  border: 1.5px solid var(--border);
  color: var(--ink-2);
  transition: background 0.15s;
}
.btn-secondary:hover { background: var(--border); }
.btn-danger {
  padding: 9px 20px;
  border-radius: 8px;
  font-size: 0.9rem;
  background: #D95F5F;
  color: #fff;
  transition: background 0.15s;
}
.btn-danger:hover { background: #c24e4e; }

/* ============================================================
   TOAST
   ============================================================ */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--ink);
  color: var(--surface);
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 0.88rem;
  z-index: 300;
  box-shadow: var(--shadow-lg);
  animation: toastIn 0.3s var(--ease);
}
@keyframes toastIn { from { opacity: 0; transform: translateX(-50%) translateY(12px); } }

/* ============================================================
   SCROLLBAR — notes list
   ============================================================ */
textarea {
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

/* ============================================================
   MOBILE RESPONSIVE
   ============================================================ */
@media (max-width: 700px) {
  :root { --sidebar-w: 100vw; }

  .topbar-brand span { display: none; }

  .sidebar {
    position: fixed;
    top: var(--topbar-h); left: 0;
    width: 100vw;
    height: calc(100dvh - var(--topbar-h));
    z-index: 90;
    transform: translateX(0);
  }
  .sidebar.hidden-mobile {
    transform: translateX(-100%);
  }

  .editor-panel {
    position: fixed;
    top: var(--topbar-h); left: 0;
    width: 100vw;
    height: calc(100dvh - var(--topbar-h));
    z-index: 80;
    transform: translateX(100%);
    transition: transform 0.3s var(--ease);
  }
  .editor-panel.active-mobile {
    transform: translateX(0);
  }

  .editor-body { padding: 20px 18px; }
  .note-title-input { font-size: 1.4rem; }

  .user-pill span { display: none; }
  .sync-label { display: none; }

  #editor-placeholder { display: none; }
}

@media (min-width: 701px) {
  #menu-toggle { display: none; }
}