/* ============================================================
   TabMargin — Soft / Muji edition
   Warm paper canvas, single earth accent, no hard borders,
   Manrope throughout. Design tokens live in tokens.css.
   ============================================================ */

/* Design tokens: see tokens.css */

/* ----- Reset ----- */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100vh;
  overflow: hidden;
}

body {
  font-family: var(--font-ui);
  font-weight: 400;
  font-size: 14px;
  line-height: 1.55;
  letter-spacing: -0.005em;
  background-color: var(--bg-canvas);
  color: var(--ink-primary);
  transition: background-color 0.5s var(--ease), color 0.5s var(--ease);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Paper grain overlay — gives the canvas tactility */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1000;
  opacity: var(--grain-opacity);
  mix-blend-mode: var(--grain-blend);
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='280' height='280'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='2' stitchTiles='stitch'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
}

/* ----- Layout ----- */
.container {
  display: flex;
  height: 100vh;
  width: 100vw;
  animation: settle 0.6s var(--ease);
}

@keyframes settle {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ----- Sidebar ----- */
.sidebar {
  width: 280px;
  background-color: var(--bg-recessed);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: background-color 0.5s var(--ease);
}

.sidebar.hidden { display: none; }

.sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 32px 24px 16px;
}

.sidebar-header h2 {
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0;
  color: var(--ink-secondary);
}

.notes-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 12px 24px;
}

.note-item {
  padding: 12px;
  margin-bottom: 2px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background-color 0.25s var(--ease), color 0.25s var(--ease);
  position: relative;
}

.note-item:hover {
  background-color: var(--bg-elevated);
}

.note-item.active {
  background-color: var(--bg-elevated);
}

.note-item.active::before {
  content: '';
  position: absolute;
  left: -4px;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 18px;
  background-color: var(--accent);
  border-radius: 2px;
}

.note-item-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-primary);
  margin-bottom: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: -0.01em;
}

.note-item-preview {
  font-size: 12px;
  color: var(--ink-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 400;
}

/* ----- Main area ----- */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  min-width: 0;
}

.toggle-sidebar {
  position: absolute;
  top: 28px;
  left: 28px;
  background: transparent;
  border: none;
  padding: 6px;
  border-radius: var(--radius-sm);
  color: var(--ink-tertiary);
  transition: color 0.25s var(--ease), background-color 0.25s var(--ease);
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
}

.toggle-sidebar:hover {
  color: var(--ink-primary);
  background-color: var(--bg-recessed);
}

.toggle-sidebar svg {
  width: 18px;
  height: 18px;
}

/* ----- Editor ----- */
.editor-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 88px clamp(48px, 12vw, 140px) 32px;
  overflow: hidden;
  max-width: 880px;
  width: 100%;
  margin: 0 auto;
}

.note-title {
  font-family: var(--font-ui);
  font-weight: 500;
  font-size: 28px;
  line-height: 1.25;
  letter-spacing: -0.01em;
  border: none;
  outline: none;
  background: transparent;
  color: var(--ink-primary);
  margin-bottom: 28px;
  padding-bottom: 4px;
  width: 100%;
  position: relative;
}

.note-title::placeholder {
  color: var(--ink-tertiary);
}

/* Hairline accent that fades in on focus — a soft pen-mark */
.note-title-wrap {
  position: relative;
  margin-bottom: 28px;
}

.note-title-wrap::after {
  content: '';
  position: absolute;
  left: 0;
  bottom: 0;
  height: 1px;
  width: 0;
  background-color: var(--accent);
  transition: width 0.4s var(--ease);
}

.note-title-wrap:focus-within::after {
  width: 56px;
}

.note-title-wrap .note-title {
  margin-bottom: 0;
}

.editor {
  flex: 1;
  width: 100%;
  border: none;
  outline: none;
  resize: none;
  font-family: var(--font-ui);
  font-size: 15px;
  font-weight: 400;
  line-height: 1.7;
  letter-spacing: -0.005em;
  background: transparent;
  color: var(--ink-primary);
  caret-color: var(--accent);
}

.editor::placeholder {
  color: var(--ink-tertiary);
}

/* ----- Status bar ----- */
.status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px clamp(48px, 12vw, 140px);
  font-size: 12px;
  font-weight: 400;
  color: var(--ink-secondary);
  max-width: 880px;
  width: 100%;
  margin: 0 auto;
}

.stats {
  display: flex;
  align-items: center;
  gap: 10px;
  letter-spacing: 0.01em;
}

.separator {
  color: var(--ink-tertiary);
  font-size: 10px;
}

.actions {
  display: flex;
  gap: 4px;
  align-items: center;
}

/* Save status: a single dot + word, very quiet */
.save-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--ink-secondary);
  margin-right: 12px;
  font-size: 12px;
}

.save-status::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: var(--ink-tertiary);
  transition: background-color 0.3s var(--ease), transform 0.3s var(--ease);
}

.save-status.saving::before {
  background-color: var(--accent);
  animation: pulse 1s ease-in-out infinite;
}

.save-status.saved::before {
  background-color: var(--ink-tertiary);
}

.save-status.error::before {
  background-color: var(--danger);
}

.save-status.synced::before {
  background-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 0.6; }
  50%      { transform: scale(1.3); opacity: 1; }
}

/* ----- Buttons ----- */
button {
  cursor: pointer;
  font-family: inherit;
  color: inherit;
}

.btn-icon {
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-secondary);
  transition: color 0.25s var(--ease), background-color 0.25s var(--ease), transform 0.25s var(--ease);
}

.btn-icon:hover {
  color: var(--ink-primary);
  background-color: var(--bg-elevated);
}

.btn-icon:active { transform: scale(0.94); }

.btn-icon svg {
  width: 15px;
  height: 15px;
}

.btn-icon-action {
  background: transparent;
  border: none;
  padding: 8px;
  border-radius: var(--radius-sm);
  color: var(--ink-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.25s var(--ease), background-color 0.25s var(--ease);
  font-family: var(--font-ui);
  font-size: 12px;
  letter-spacing: 0.02em;
  min-height: 30px;
}

.btn-icon-action:hover {
  color: var(--ink-primary);
  background-color: var(--bg-recessed);
}

.btn-icon-action svg {
  width: 15px;
  height: 15px;
  stroke: currentColor;
}

/* Inline-confirm state — button stretches and shows the word */
.btn-icon-action .confirm-label { display: none; }

.btn-icon-action.confirming {
  background-color: var(--danger-soft);
  color: var(--danger);
  padding: 6px 14px;
  gap: 6px;
}

.btn-icon-action.confirming svg { display: none; }
.btn-icon-action.confirming .confirm-label { display: inline; }

/* ----- Scrollbar ----- */
::-webkit-scrollbar { width: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: transparent;
  border-radius: 5px;
  border: 3px solid transparent;
  background-clip: padding-box;
}
.notes-list:hover::-webkit-scrollbar-thumb {
  background: var(--ink-tertiary);
  background-clip: padding-box;
}

/* ----- Focus rings (accessibility) ----- */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

.editor:focus-visible,
.note-title:focus-visible {
  outline: none;
}

/* ----- Selection ----- */
::selection {
  background-color: var(--accent-soft);
  color: var(--ink-primary);
}

/* ----- Responsive ----- */
@media (max-width: 768px) {
  .editor-container {
    padding: 72px 24px 24px;
  }

  .status-bar {
    padding: 12px 24px;
    flex-direction: column;
    gap: 8px;
    align-items: flex-start;
  }

  .sidebar { width: 240px; }

  .note-title { font-size: 24px; }
}
