:root {
  --paper: #faf8f4;
  --paper-pure: #ffffff;
  --sidebar-bg: #f3efe7;
  --list-bg: #f7f4ec;
  --ink: #1f2421;
  --ink-soft: #59615b;
  --border: #e4ded2;
  --border-strong: #d3cbbd;
  --green: #1f5c47;
  --green-hover: #174938;
  --green-tint: #e8f1ed;
  --amber: #b86227;
  --amber-tint: #faeee4;
  --danger: #b43b3b;
  --danger-tint: #fcecec;
  --radius: 10px;
  --font-sans: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
  --font-serif: 'Newsreader', Georgia, serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

[hidden] {
  display: none !important;
}

/* Shared Buttons & Controls */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 9px 14px;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.btn-primary {
  background: var(--green);
  color: #ffffff;
}

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

.btn-secondary {
  background: var(--paper-pure);
  color: var(--ink);
  border-color: var(--border-strong);
}

.btn-secondary:hover {
  border-color: var(--green);
  color: var(--green);
}

.btn-ghost {
  background: transparent;
  color: var(--ink-soft);
  border-color: transparent;
}

.btn-ghost:hover {
  background: rgba(31, 36, 33, 0.06);
  color: var(--ink);
}

.btn-danger-ghost {
  background: transparent;
  color: var(--danger);
}

.btn-danger-ghost:hover {
  background: var(--danger-tint);
}

.btn-sm {
  font-size: 13px;
  padding: 6px 10px;
}

.btn-full {
  width: 100%;
}

.icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  width: 34px;
  height: 34px;
  cursor: pointer;
  color: var(--ink);
  font-size: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.lang-toggle {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  padding: 5px 9px;
  border-radius: 6px;
  background: var(--paper-pure);
  border: 1px solid var(--border-strong);
  color: var(--ink);
  cursor: pointer;
}

.lang-toggle:hover {
  border-color: var(--green);
  color: var(--green);
}

.muted {
  color: var(--ink-soft);
}

.mono {
  font-family: var(--font-mono);
  font-size: 12px;
}

/* Brand Lockup */
.brand-lockup {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-emblem {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: var(--green);
  color: #faf8f4;
  font-family: var(--font-serif);
  font-weight: 600;
  font-size: 15px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.brand-name {
  display: block;
  font-family: var(--font-serif);
  font-size: 19px;
  line-height: 1.15;
  color: var(--ink);
}

.brand-sub {
  display: block;
  font-size: 12px;
  color: var(--ink-soft);
}

/* Access Code Gate */
.gate-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
  background:
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 31px,
      rgba(211, 203, 189, 0.28) 31px,
      rgba(211, 203, 189, 0.28) 32px
    ),
    var(--paper);
}

.gate-card {
  width: 100%;
  max-width: 440px;
  background: var(--paper-pure);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 32px 28px 24px;
  box-shadow: 0 12px 32px rgba(31, 36, 33, 0.06);
}

.gate-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.gate-heading {
  font-family: var(--font-serif);
  font-size: 28px;
  font-weight: 600;
  margin: 0 0 8px;
  letter-spacing: -0.01em;
}

.gate-desc {
  margin: 0 0 18px;
  color: var(--ink-soft);
  font-size: 14px;
}

.gate-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  background: var(--sidebar-bg);
  padding: 4px;
  border-radius: 9px;
  margin-bottom: 18px;
}

.gate-tab {
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 8px 10px;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
}

.gate-tab.active {
  background: var(--paper-pure);
  color: var(--green);
  box-shadow: 0 1px 4px rgba(31, 36, 33, 0.08);
}

.text-input {
  width: 100%;
  font-family: inherit;
  font-size: 14px;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--paper);
  color: var(--ink);
  margin-bottom: 12px;
}

.text-input:focus {
  outline: 2px solid var(--green);
  outline-offset: 1px;
  background: var(--paper-pure);
}

.reg-result {
  text-align: center;
  padding: 14px;
  border-radius: 10px;
  background: var(--green-tint);
  border: 1px solid rgba(31, 92, 71, 0.25);
}

.reg-result-label {
  margin: 0 0 8px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--green);
}

.generated-code-box {
  font-family: var(--font-mono);
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--ink);
  background: var(--paper-pure);
  border: 1px dashed var(--green);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 8px;
}

.small-note {
  margin: 0 0 12px;
  font-size: 12px;
}

.reg-result-actions {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

.field-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
}

.code-input {
  width: 100%;
  font-family: var(--font-mono);
  font-size: 16px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--paper);
  color: var(--ink);
  margin-bottom: 12px;
}

.code-input:focus {
  outline: 2px solid var(--green);
  outline-offset: 1px;
  background: var(--paper-pure);
}

.gate-error {
  margin: 0 0 12px;
  padding: 8px 11px;
  border-radius: 6px;
  background: var(--danger-tint);
  color: var(--danger);
  font-size: 13px;
  font-weight: 500;
}

.gate-footer {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  text-align: center;
  font-size: 12px;
  color: var(--ink-soft);
}

/* Main 3-Pane Workspace */
.app-shell {
  display: grid;
  grid-template-columns: 245px 300px 1fr;
  height: 100vh;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  overflow-y: auto;
}

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

.section-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
  padding: 0 8px 6px;
}

.folder-nav, .template-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.folder-btn, .template-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  text-align: left;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  color: var(--ink);
  background: transparent;
  border: none;
  border-radius: 8px;
  padding: 8px 10px;
  cursor: pointer;
}

.template-btn {
  justify-content: flex-start;
  font-size: 13px;
}

.folder-btn:hover, .template-btn:hover {
  background: rgba(31, 36, 33, 0.06);
}

.folder-btn.active {
  background: var(--green-tint);
  color: var(--green);
  font-weight: 600;
}

.folder-count {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-soft);
}

.folder-btn.active .folder-count {
  color: var(--green);
}

.tpl-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.dot-green { background: var(--green); }
.dot-amber { background: var(--amber); }
.dot-slate { background: #5a6672; }

.sidebar-footer {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.footer-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

/* Middle Column: Notes List */
.notes-pane {
  background: var(--list-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.notes-topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 12px 10px;
}

.search-wrap {
  flex: 1;
}

.search-input {
  width: 100%;
  font-family: inherit;
  font-size: 14px;
  padding: 8px 11px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--paper-pure);
  color: var(--ink);
}

.search-input:focus {
  outline: 2px solid var(--green);
  border-color: transparent;
}

.notes-subheader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 14px 10px;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
}

.notes-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.note-item {
  width: 100%;
  text-align: left;
  background: var(--paper-pure);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 11px 12px;
  cursor: pointer;
  font-family: inherit;
  transition: border-color 0.12s ease, background 0.12s ease;
}

.note-item:hover {
  border-color: var(--border-strong);
}

.note-item.active {
  border-color: var(--green);
  background: #ffffff;
  box-shadow: 0 2px 10px rgba(31, 92, 71, 0.08);
}

.note-item-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 3px;
}

.note-item-title {
  font-weight: 600;
  font-size: 14px;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pin-badge {
  font-size: 11px;
  color: var(--amber);
  font-weight: 700;
  flex-shrink: 0;
}

.note-item-preview {
  font-size: 12.5px;
  color: var(--ink-soft);
  margin: 0 0 6px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.note-item-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  font-size: 11.5px;
  color: var(--ink-soft);
}

.tag-pill {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--green-tint);
  color: var(--green);
}

/* Right Column: Editor */
.editor-pane {
  background: var(--paper);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.editor-empty {
  margin: auto;
  text-align: center;
  padding: 32px;
  max-width: 360px;
}

.empty-title {
  font-family: var(--font-serif);
  font-size: 22px;
  margin: 0 0 6px;
}

.editor-wrap {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.editor-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  padding: 12px 20px;
  background: var(--paper-pure);
  border-bottom: 1px solid var(--border);
}

.toolbar-left, .toolbar-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.select-control, .meta-input {
  font-family: inherit;
  font-size: 13px;
  padding: 6px 10px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--paper);
  color: var(--ink);
}

.meta-input {
  width: 155px;
}

.icon-pill {
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--paper);
  color: var(--ink-soft);
  cursor: pointer;
}

.icon-pill.pinned {
  background: var(--amber-tint);
  border-color: var(--amber);
  color: var(--amber);
}

.paper-sheet {
  flex: 1;
  overflow-y: auto;
  max-width: 820px;
  width: 100%;
  margin: 20px auto;
  background: var(--paper-pure);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px 34px 40px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 4px 18px rgba(31, 36, 33, 0.04);
}

.paper-meta-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.paper-title {
  width: 100%;
  border: none;
  outline: none;
  font-family: var(--font-serif);
  font-size: 30px;
  font-weight: 600;
  color: var(--ink);
  background: transparent;
  margin-bottom: 14px;
  padding: 0;
}

.paper-body {
  flex: 1;
  min-height: 420px;
  width: 100%;
  border: none;
  outline: none;
  resize: none;
  font-family: var(--font-sans);
  font-size: 15.5px;
  line-height: 1.72;
  color: var(--ink);
  background: transparent;
}

/* Share Read-Only View */
.share-shell {
  min-height: 100vh;
  padding: 32px 16px;
  background: var(--paper);
}

.share-paper {
  max-width: 760px;
  margin: 0 auto;
  background: var(--paper-pure);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px 32px;
}

.share-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 16px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--border);
}

.brand-mark {
  font-family: var(--font-serif);
  font-size: 20px;
  font-weight: 600;
  color: var(--green);
}

.share-actions {
  display: flex;
  gap: 8px;
}

.share-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.share-title {
  font-family: var(--font-serif);
  font-size: 30px;
  margin: 0 0 16px;
}

.share-body {
  white-space: pre-wrap;
  font-size: 15.5px;
  line-height: 1.75;
}

/* Toast */
.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  background: var(--ink);
  color: #faf8f4;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 500;
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 999;
}

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

.mobile-only {
  display: none;
}

@media (max-width: 960px) {
  .mobile-only {
    display: inline-flex;
  }

  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 270px;
    z-index: 200;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: 6px 0 24px rgba(0, 0, 0, 0.12);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .notes-pane {
    max-height: 290px;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .paper-sheet {
    margin: 12px;
    width: auto;
    padding: 20px;
  }
}

/* Clean A4 Print Layout for RPH & Lesson Notes */
@media print {
  body {
    background: #ffffff;
  }

  .sidebar, .notes-pane, .editor-toolbar, .toast, .share-topbar {
    display: none !important;
  }

  .app-shell, .editor-pane, .editor-wrap {
    display: block !important;
    height: auto !important;
    overflow: visible !important;
  }

  .paper-sheet, .share-paper {
    border: none !important;
    box-shadow: none !important;
    margin: 0 !important;
    padding: 0 !important;
    max-width: 100% !important;
  }

  .paper-body {
    overflow: visible !important;
    height: auto !important;
  }
}
