/* ============ Design tokens ============
   Motyw: introligatorska oprawa notatnika.
   ink      - tekst główny, prawie-czerń z lekkim chłodem
   paper    - tło strony, ciepła biel papieru (nie kremowy #F4F1EA)
   cover    - głęboka butelkowa zieleń, jak płótnowa oprawa zeszytu
   cover-lt - jaśniejszy wariant do hoverów/akcentów
   line     - linie liniatury / obramowania
   danger   - czerwień do usuwania
=========================================== */
:root {
  --ink: #21231F;
  --ink-soft: #5B5E56;
  --paper: #FBFAF6;
  --paper-raised: #FFFFFF;
  --cover: #2F4A3C;
  --cover-lt: #3E6350;
  --cover-soft: #E7EEE8;
  --line: #DDD8C8;
  --danger: #A8402F;
  --danger-soft: #F6E6E2;

  --font-display: "Fraunces", Georgia, serif;
  --font-body: "Inter", -apple-system, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;

  --radius: 10px;
  --shadow-card: 0 1px 2px rgba(33,35,31,0.06), 0 8px 24px -12px rgba(33,35,31,0.15);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
}

a { color: inherit; }

button { font-family: inherit; cursor: pointer; }

/* ============ Flash messages ============ */
.flash-stack {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.flash {
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 13.5px;
  font-weight: 500;
  box-shadow: var(--shadow-card);
  background: var(--paper-raised);
  border-left: 3px solid var(--cover);
  animation: flash-in 0.25s ease;
}
.flash--error { border-left-color: var(--danger); color: var(--danger); }
.flash--success { border-left-color: var(--cover); }
.flash--info { border-left-color: var(--ink-soft); }
@keyframes flash-in {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ============ Buttons & fields ============ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-size: 14px;
  font-weight: 600;
  transition: transform 0.06s ease, background 0.15s ease, border-color 0.15s ease;
}
.btn:active { transform: translateY(1px); }
.btn--primary { background: var(--cover); color: #fff; }
.btn--primary:hover { background: var(--cover-lt); }
.btn--block { width: 100%; }
.btn--ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.btn--ghost:hover { border-color: var(--cover); color: var(--cover); }
.btn--danger-ghost { background: transparent; border-color: var(--line); color: var(--danger); }
.btn--danger-ghost:hover { background: var(--danger-soft); border-color: var(--danger); }

.field { display: block; margin-bottom: 16px; }
.field__label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-soft);
  margin-bottom: 6px;
  letter-spacing: 0.01em;
}
.field__input {
  width: 100%;
  padding: 11px 13px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--paper-raised);
  font-size: 14.5px;
  color: var(--ink);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.field__input:focus {
  border-color: var(--cover);
  box-shadow: 0 0 0 3px var(--cover-soft);
}

.checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13.5px;
  color: var(--ink-soft);
  margin-bottom: 20px;
  user-select: none;
}
.checkbox input { accent-color: var(--cover); width: 15px; height: 15px; }

/* ============ Auth pages ============ */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at 15% 20%, rgba(47,74,60,0.06), transparent 40%),
    var(--paper);
}
.auth-shell {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 64px;
  align-items: center;
  max-width: 880px;
  width: 100%;
  padding: 24px;
}
.auth-brand__mark {
  width: 52px; height: 52px;
  border-radius: 12px;
  background: var(--cover);
  color: #fff;
  font-family: var(--font-display);
  font-size: 26px;
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 20px;
}
.auth-brand__title {
  font-family: var(--font-display);
  font-size: 40px;
  font-weight: 600;
  margin: 0 0 12px;
}
.auth-brand__tagline {
  color: var(--ink-soft);
  font-size: 15.5px;
  line-height: 1.6;
}
.auth-card {
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 32px;
  box-shadow: var(--shadow-card);
}
.auth-card__title {
  font-family: var(--font-display);
  font-size: 24px;
  margin: 0 0 4px;
}
.auth-card__sub {
  color: var(--ink-soft);
  font-size: 13.5px;
  margin: 0 0 24px;
}
.auth-card__footer {
  text-align: center;
  font-size: 13.5px;
  color: var(--ink-soft);
  margin: 18px 0 0;
}
.auth-card__footer a { color: var(--cover); font-weight: 600; text-decoration: none; }
.auth-card__footer a:hover { text-decoration: underline; }

@media (max-width: 760px) {
  .auth-shell { grid-template-columns: 1fr; gap: 32px; text-align: center; }
  .auth-brand__mark { margin-inline: auto; }
}

/* ============ App shell (spine + workspace) ============ */
.app-page { height: 100vh; overflow: hidden; }
.shell { display: flex; height: 100vh; }

.spine {
  width: 64px;
  flex-shrink: 0;
  background: var(--cover);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 18px 0;
  gap: 18px;
}
.spine__mark {
  font-family: var(--font-display);
  color: #fff;
  font-size: 20px;
  text-decoration: none;
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 8px;
  background: rgba(255,255,255,0.1);
}
.spine__user {
  margin-top: auto;
  width: 34px; height: 34px;
  border-radius: 50%;
  background: rgba(255,255,255,0.15);
  color: #fff;
  font-size: 11.5px;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.spine__action {
  width: 34px; height: 34px;
  border-radius: 8px;
  color: rgba(255,255,255,0.75);
  text-decoration: none;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
}
.spine__action:hover { background: rgba(255,255,255,0.12); color: #fff; }

.workspace {
  flex: 1;
  overflow-y: auto;
  padding: 40px 48px;
}
.workspace__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 32px;
}
.workspace__title {
  font-family: var(--font-display);
  font-size: 30px;
  margin: 0 0 4px;
}
.workspace__sub { color: var(--ink-soft); font-size: 13.5px; margin: 0; }

/* ============ Notes grid ============ */
.note-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
}
.note-card {
  display: block;
  text-decoration: none;
  color: var(--ink);
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 18px;
  min-height: 140px;
  box-shadow: var(--shadow-card);
  transition: transform 0.12s ease, border-color 0.12s ease;
}
.note-card:hover { transform: translateY(-2px); border-color: var(--cover); }
.note-card__title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 17px;
  margin-bottom: 8px;
}
.note-card__preview {
  font-size: 13px;
  color: var(--ink-soft);
  line-height: 1.5;
  margin-bottom: 14px;
}
.note-card__meta {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-soft);
  opacity: 0.8;
}

.empty-state {
  text-align: center;
  padding: 80px 20px;
  color: var(--ink-soft);
}
.empty-state__mark { font-size: 40px; margin-bottom: 12px; }
.empty-state h2 { font-family: var(--font-display); color: var(--ink); margin: 0 0 6px; }
.empty-state p { margin: 0 0 20px; }

/* ============ Editor ============ */
.workspace--editor { padding: 24px 48px 60px; position: relative; }

.editor-topbar {
  display: flex;
  align-items: center;
  gap: 20px;
  margin-bottom: 20px;
}
.editor-topbar__back {
  text-decoration: none;
  color: var(--ink-soft);
  font-size: 13.5px;
  font-weight: 500;
}
.editor-topbar__back:hover { color: var(--cover); }

.editor-topbar__status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--ink-soft);
}
.editor-topbar__status .dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--cover);
}
.editor-topbar__status[data-state="saving"] .dot { background: #C9A227; animation: pulse 1s infinite; }
.editor-topbar__status[data-state="error"] .dot { background: var(--danger); }
@keyframes pulse { 50% { opacity: 0.3; } }

.editor-topbar__actions { margin-left: auto; display: flex; gap: 10px; }

.editor-title {
  display: block;
  width: 100%;
  border: none;
  outline: none;
  background: transparent;
  font-family: var(--font-display);
  font-size: 32px;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 18px;
  padding: 0;
}
.editor-title::placeholder { color: #B9B4A2; }

.editor-paper {
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow-card);
  overflow: hidden;
}
.ql-toolbar.ql-snow {
  border: none;
  border-bottom: 1px solid var(--line);
  font-family: var(--font-body);
  padding: 10px 16px;
}
.ql-container.ql-snow { border: none; font-family: var(--font-body); font-size: 15.5px; }
#editor { min-height: 55vh; }
.ql-editor { padding: 32px 40px; line-height: 1.7; }
.ql-editor.ql-blank::before { color: #B9B4A2; font-style: normal; left: 40px; }

/* ============ History panel ============ */
.history-panel {
  position: fixed;
  top: 0; right: 0;
  width: 320px;
  height: 100vh;
  background: var(--paper-raised);
  border-left: 1px solid var(--line);
  box-shadow: -8px 0 24px -12px rgba(33,35,31,0.2);
  padding: 24px;
  overflow-y: auto;
  z-index: 100;
}
.history-panel__header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 6px;
}
.history-panel__header h3 { font-family: var(--font-display); margin: 0; font-size: 19px; }
.icon-btn {
  border: none; background: transparent; font-size: 15px; color: var(--ink-soft);
  width: 28px; height: 28px; border-radius: 6px;
}
.icon-btn:hover { background: var(--cover-soft); color: var(--cover); }
.history-panel__hint { font-size: 12.5px; color: var(--ink-soft); line-height: 1.5; margin-bottom: 18px; }
.history-panel__empty { font-size: 13px; color: var(--ink-soft); }

.history-item {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: border-color 0.12s ease, background 0.12s ease;
}
.history-item:hover { border-color: var(--cover); background: var(--cover-soft); }
.history-item__title { font-weight: 600; font-size: 13.5px; margin-bottom: 3px; }
.history-item__time { font-family: var(--font-mono); font-size: 11px; color: var(--ink-soft); }

@media (max-width: 900px) {
  .workspace { padding: 28px 20px; }
  .workspace--editor { padding: 20px 16px 60px; }
  .ql-editor { padding: 20px; }
  .history-panel { width: 100%; }
}
