/* ==========================================================================
   KutaNotes — Clean, Bespoke, Minimalist Typography & Layout
   Inspired by Obsidian, Bear, and Notion.
   ========================================================================== */

:root {
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;

  /* Light Theme (Neutral, Paper Clean) */
  --bg-app: #ffffff;
  --bg-sidebar: #f8f8f7;
  --bg-list: #fcfcfc;
  --bg-hover: #efefed;
  --bg-active: #eaeae7;
  --bg-input: #ffffff;
  --bg-code: #f3f3f1;

  --border: #e8e8e6;
  --border-subtle: #f0f0ee;

  --text-main: #191919;
  --text-muted: #6e6e6e;
  --text-subtle: #9c9c9c;

  --accent: #191919;
  --accent-tint: #f0f0ee;
  --danger: #d93838;
  --danger-tint: #fbebeb;

  --radius-xs: 3px;
  --radius-sm: 5px;
  --radius-md: 7px;
}

/* Dark Theme (Pure Neutral Matte Graphite, Zero Blue/Purple Tint) */
body.theme-dark {
  --bg-app: #141414;
  --bg-sidebar: #101010;
  --bg-list: #141414;
  --bg-hover: #1c1c1c;
  --bg-active: #222222;
  --bg-input: #181818;
  --bg-code: #1c1c1c;

  --border: #222222;
  --border-subtle: #191919;

  --text-main: #e8e8e8;
  --text-muted: #888888;
  --text-subtle: #555555;

  --accent: #e8e8e8;
  --accent-tint: #202020;
  --danger: #e05252;
  --danger-tint: #2a1515;
}

@media (prefers-color-scheme: dark) {
  body.theme-system {
    --bg-app: #141414;
    --bg-sidebar: #101010;
    --bg-list: #141414;
    --bg-hover: #1c1c1c;
    --bg-active: #222222;
    --bg-input: #181818;
    --bg-code: #1c1c1c;

    --border: #222222;
    --border-subtle: #191919;

    --text-main: #e8e8e8;
    --text-muted: #888888;
    --text-subtle: #555555;

    --accent: #e8e8e8;
    --accent-tint: #202020;
    --danger: #e05252;
    --danger-tint: #2a1515;
  }
}

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

html, body {
  height: 100%;
  font-family: var(--font-sans);
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--text-main);
  background-color: var(--bg-app);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: hidden;
}

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

/* Utilities */
.hidden { display: none !important; }
.text-danger { color: var(--danger) !important; }

/* Clean Minimal Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--bg-app);
  color: var(--text-main);
  transition: background 0.1s ease, border-color 0.1s ease;
  user-select: none;
}
.btn:hover {
  background: var(--bg-hover);
  border-color: var(--text-muted);
}
.btn-primary {
  background: var(--text-main);
  color: var(--bg-app);
  border-color: var(--text-main);
}
.btn-primary:hover {
  background: var(--text-muted);
  border-color: var(--text-muted);
}
.btn-secondary {
  background: var(--bg-hover);
  border-color: var(--border);
  color: var(--text-main);
}
.btn-secondary:hover {
  background: var(--bg-active);
}
.btn-danger-subtle {
  background: transparent;
  color: var(--danger);
  border-color: transparent;
  font-size: 12px;
}
.btn-danger-subtle:hover {
  background: var(--danger-tint);
}
.btn-sm {
  padding: 3px 8px;
  font-size: 11.5px;
}
.btn-block {
  width: 100%;
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-xs);
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.1s ease;
}
.btn-icon:hover {
  color: var(--text-main);
  background: var(--bg-hover);
}

.btn-icon-subtle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: var(--radius-xs);
  background: transparent;
  border: none;
  color: var(--text-subtle);
  cursor: pointer;
}
.btn-icon-subtle:hover {
  color: var(--text-main);
  background: var(--bg-active);
}

/* Simple Clean Forms */
.form-group {
  margin-bottom: 14px;
}
.form-group label {
  display: block;
  margin-bottom: 5px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  text-transform: uppercase;
}
.form-group input,
.form-group select {
  width: 100%;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-input);
  outline: none;
  color: var(--text-main);
  font-size: 13px;
  transition: border-color 0.15s;
}
.form-group input:focus,
.form-group select:focus {
  border-color: var(--text-main);
}

.error-msg {
  padding: 8px 12px;
  border-radius: var(--radius-xs);
  background: var(--danger-tint);
  color: var(--danger);
  font-size: 12px;
  margin-bottom: 12px;
}
.success-msg {
  padding: 8px 12px;
  border-radius: var(--radius-xs);
  background: var(--accent-tint);
  color: var(--text-main);
  font-size: 12px;
  margin-bottom: 12px;
}

/* Loading Screen */
.screen-center {
  height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg-app);
}
.loader-spinner {
  width: 24px;
  height: 24px;
  border: 2px solid var(--border);
  border-top-code: var(--text-main);
  border-top-color: var(--text-main);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
.loader-text {
  margin-top: 12px;
  font-size: 12px;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Auth Cards (Clean, flat, monochrome) */
.auth-card {
  width: 100%;
  max-width: 360px;
  padding: 36px 32px;
  background: var(--bg-app);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
}
.auth-header {
  margin-bottom: 24px;
}
.auth-logo {
  display: none;
}
.auth-header h2 {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text-main);
}
.auth-header p {
  color: var(--text-muted);
  font-size: 12.5px;
  margin-top: 2px;
}

/* Main 3-Column Workspace */
.main-layout {
  display: grid;
  grid-template-columns: 240px 290px 1fr;
  height: 100vh;
  overflow: hidden;
  background: var(--bg-app);
}

/* 1. Sidebar (Minimalist Tree like Obsidian / VS Code) */
.sidebar {
  display: flex;
  flex-direction: column;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  padding: 10px 8px 12px 8px;
  user-select: none;
  overflow-y: auto;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 6px 10px 8px;
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: 8px;
}
.sidebar-header .brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 13.5px;
  letter-spacing: -0.01em;
  color: var(--text-main);
}
.sidebar-header .brand svg {
  color: var(--text-main);
}

.nav-section {
  display: flex;
  flex-direction: column;
  gap: 1px;
  margin-bottom: 16px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  border-radius: var(--radius-xs);
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 12.5px;
  font-weight: 400;
  text-align: left;
  cursor: pointer;
  transition: all 0.1s ease;
}
.nav-item:hover {
  background: var(--bg-hover);
  color: var(--text-main);
}
.nav-item.active {
  background: var(--bg-active);
  color: var(--text-main);
  font-weight: 500;
}
.nav-item span:first-of-type {
  flex: 1;
}
.nav-item .badge {
  font-size: 11px;
  color: var(--text-subtle);
  font-variant-numeric: tabular-nums;
}

.sidebar-section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px 4px 8px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--text-subtle);
  text-transform: uppercase;
}

/* Groups Tree Hierarchy */
.groups-tree {
  display: flex;
  flex-direction: column;
  gap: 1px;
  margin-bottom: 16px;
}
.group-node {
  display: flex;
  flex-direction: column;
}
.group-row {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 4px 8px;
  border-radius: var(--radius-xs);
  color: var(--text-muted);
  font-size: 12.5px;
  font-weight: 400;
  cursor: pointer;
  transition: background 0.1s;
  position: relative;
}
.group-row:hover {
  background: var(--bg-hover);
  color: var(--text-main);
}
.group-row.active {
  background: var(--bg-active);
  color: var(--text-main);
  font-weight: 500;
}
.group-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
  opacity: 0.75;
}
.group-name {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.group-count {
  font-size: 10.5px;
  color: var(--text-subtle);
  font-variant-numeric: tabular-nums;
}
.group-actions {
  display: none;
  align-items: center;
  gap: 1px;
}
.group-row:hover .group-actions {
  display: flex;
}

.subgroups-container {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding-left: 12px;
  margin-top: 1px;
  border-left: 1px solid var(--border);
  margin-left: 11px;
}

/* Tags cloud */
.tags-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 4px 8px;
  margin-bottom: 16px;
}
.tag-pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 6px;
  border-radius: var(--radius-xs);
  font-size: 11px;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all 0.1s;
}
.tag-pill:hover,
.tag-pill.active {
  background: var(--bg-active);
  border-color: var(--text-muted);
  color: var(--text-main);
}

/* Sidebar Footer */
.sidebar-footer {
  margin-top: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 10px;
  border-top: 1px solid var(--border-subtle);
}
.user-profile {
  display: flex;
  align-items: center;
  gap: 7px;
  cursor: pointer;
}
.avatar {
  width: 24px;
  height: 24px;
  border-radius: var(--radius-xs);
  background: var(--border);
  color: var(--text-main);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10.5px;
  font-weight: 600;
}
.user-info {
  display: flex;
  flex-direction: column;
}
.user-name {
  font-weight: 500;
  font-size: 12px;
  color: var(--text-main);
  line-height: 1.2;
}
.user-role {
  display: none;
}
.footer-actions {
  display: flex;
  align-items: center;
  gap: 2px;
}

/* 2. Middle Column: Notes List (Clean, Apple Notes / Bear style flush list) */
.notes-panel {
  display: flex;
  flex-direction: column;
  background: var(--bg-list);
  border-right: 1px solid var(--border);
  overflow: hidden;
}
.notes-panel-header {
  padding: 12px 14px 10px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.search-box {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  border-radius: var(--radius-xs);
  background: var(--bg-sidebar);
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.search-box input {
  flex: 1;
  border: none;
  background: transparent;
  outline: none;
  font-size: 12.5px;
  color: var(--text-main);
}
.search-box input::placeholder {
  color: var(--text-subtle);
}
.view-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.view-header-row h2 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-main);
}

.notes-list-content {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

/* Flush Note Item (NOT a floating rounded card) */
.note-card {
  padding: 11px 14px;
  background: transparent;
  border-bottom: 1px solid var(--border-subtle);
  cursor: pointer;
  transition: background 0.08s ease;
  position: relative;
}
.note-card:hover {
  background: var(--bg-hover);
}
.note-card.active {
  background: var(--bg-active);
}
.note-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 3px;
}
.note-card-title {
  font-weight: 500;
  font-size: 13px;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}
.pin-badge {
  color: var(--text-muted);
  flex-shrink: 0;
  display: flex;
}
.note-card-snippet {
  font-size: 11.5px;
  color: var(--text-muted);
  line-height: 1.35;
  height: 31px;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  margin-bottom: 5px;
}
.note-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 10.5px;
  color: var(--text-subtle);
}
.note-card-meta {
  display: flex;
  align-items: center;
  gap: 5px;
}
.group-tag {
  display: inline-flex;
  align-items: center;
  font-size: 10.5px;
  font-weight: 400;
  color: var(--text-subtle);
}
.att-badge {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  font-size: 10px;
  color: var(--text-subtle);
}

/* 3. Right Column: Document Canvas (Minimalist writing experience) */
.editor-panel {
  display: flex;
  flex-direction: column;
  background: var(--bg-app);
  overflow: hidden;
  height: 100vh;
}
.editor-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 32px;
  color: var(--text-subtle);
}
.empty-illustration {
  display: none;
}
.editor-empty h3 {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 12px;
}
.editor-empty p {
  display: none;
}

.editor-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  background: var(--bg-app);
}

/* Topbar: Minimalist status & breadcrumb */
.editor-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 32px;
  border-bottom: 1px solid var(--border-subtle);
}
.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}
.group-select-wrapper {
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--text-muted);
}
.group-select-wrapper select {
  border: none;
  background: transparent;
  outline: none;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
}
.save-status {
  font-size: 11px;
  color: var(--text-subtle);
}
.save-status.saving {
  color: var(--text-muted);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 4px;
}
.mode-toggle {
  display: flex;
  background: var(--bg-hover);
  border-radius: var(--radius-xs);
  padding: 1px;
}
.mode-btn {
  padding: 2px 8px;
  border: none;
  background: transparent;
  border-radius: 2px;
  font-size: 11px;
  color: var(--text-muted);
  cursor: pointer;
}
.mode-btn.active {
  background: var(--bg-app);
  color: var(--text-main);
  font-weight: 500;
}

/* Document Title & Tags Header */
.editor-header {
  padding: 24px 48px 8px 48px;
  max-width: 860px;
  width: 100%;
  margin: 0 auto;
}
.note-title-input {
  width: 100%;
  border: none;
  outline: none;
  background: transparent;
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text-main);
  padding: 0;
  margin-bottom: 6px;
}
.note-tags-container {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
}
.tags-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.tag-pill-item {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 1px 6px;
  border-radius: var(--radius-xs);
  font-size: 11px;
  background: var(--bg-hover);
  color: var(--text-muted);
}
.tag-pill-remove {
  cursor: pointer;
  color: var(--text-subtle);
}
.tag-pill-remove:hover {
  color: var(--danger);
}
.input-tag {
  border: none;
  outline: none;
  background: transparent;
  font-size: 11px;
  color: var(--text-subtle);
  min-width: 120px;
}

/* Clean, Discreet Toolbar */
.markdown-toolbar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px 48px;
  max-width: 860px;
  width: 100%;
  margin: 0 auto;
  border-bottom: 1px solid var(--border-subtle);
  background: transparent;
  overflow-x: auto;
}
.tb-btn {
  padding: 2px 6px;
  border-radius: var(--radius-xs);
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 11.5px;
  cursor: pointer;
}
.tb-btn:hover {
  background: var(--bg-hover);
  color: var(--text-main);
}
.tb-divider {
  width: 1px;
  height: 12px;
  background: var(--border);
  margin: 0 4px;
}
.btn-attach-trigger {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--text-main);
  font-weight: 500;
}

/* Writing Area (Max width document style) */
.editor-body {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
}
.editor-pane {
  flex: 1;
  height: 100%;
  display: flex;
  justify-content: center;
}
.editor-pane textarea {
  width: 100%;
  max-width: 860px;
  height: 100%;
  padding: 16px 48px 32px 48px;
  border: none;
  outline: none;
  background: transparent;
  font-family: var(--font-sans);
  font-size: 14.5px;
  line-height: 1.75;
  color: var(--text-main);
  resize: none;
  overflow-y: auto;
}

.preview-pane {
  flex: 1;
  height: 100%;
  padding: 16px 48px 32px 48px;
  overflow-y: auto;
  border-left: 1px solid var(--border-subtle);
  background: var(--bg-app);
  max-width: 860px;
  margin: 0 auto;
  font-size: 14.5px;
  line-height: 1.75;
}

.editor-body.mode-edit .editor-pane { display: flex; }
.editor-body.mode-edit .preview-pane { display: none; }

.editor-body.mode-preview .editor-pane { display: none; }
.editor-body.mode-preview .preview-pane { display: block; border-left: none; width: 100%; max-width: 860px; }

.editor-body.mode-split .editor-pane { display: flex; width: 50%; max-width: none; }
.editor-body.mode-split .editor-pane textarea { max-width: none; padding: 16px 24px; }
.editor-body.mode-split .preview-pane { display: block; width: 50%; max-width: none; padding: 16px 24px; }

/* Clean Markdown Typography */
.preview-pane h1, .preview-pane h2, .preview-pane h3, .preview-pane h4 {
  margin: 1.4em 0 0.4em 0;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text-main);
}
.preview-pane h1 { font-size: 1.6em; }
.preview-pane h2 { font-size: 1.3em; }
.preview-pane h3 { font-size: 1.15em; }
.preview-pane p { margin: 0.8em 0; }
.preview-pane ul, .preview-pane ol { padding-left: 1.4em; margin: 0.8em 0; }
.preview-pane li { margin: 0.25em 0; }
.preview-pane blockquote {
  border-left: 2px solid var(--text-muted);
  padding: 2px 12px;
  color: var(--text-muted);
  margin: 1em 0;
}
.preview-pane code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  padding: 2px 5px;
  border-radius: var(--radius-xs);
  background: var(--bg-code);
}
.preview-pane pre code {
  display: block;
  padding: 12px;
  border-radius: var(--radius-xs);
  overflow-x: auto;
  background: var(--bg-code);
  border: 1px solid var(--border);
}
.preview-pane table {
  border-collapse: collapse;
  width: 100%;
  margin: 1em 0;
  font-size: 13px;
}
.preview-pane th, .preview-pane td {
  border: 1px solid var(--border);
  padding: 6px 10px;
  text-align: left;
}
.preview-pane th {
  background: var(--bg-sidebar);
  font-weight: 600;
}
.preview-pane img {
  max-width: 100%;
  border-radius: var(--radius-xs);
  margin: 0.8em 0;
}

/* Attachments: Minimal Chips */
.attachments-section {
  padding: 10px 48px;
  max-width: 860px;
  width: 100%;
  margin: 0 auto;
  border-top: 1px solid var(--border-subtle);
  max-height: 160px;
  overflow-y: auto;
}
.attachments-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.att-title {
  display: flex;
  align-items: center;
  gap: 5px;
  font-weight: 500;
  font-size: 11.5px;
  color: var(--text-muted);
}
.att-hint {
  font-size: 10.5px;
  color: var(--text-subtle);
}
.attachments-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.attachment-card {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: var(--radius-xs);
  background: var(--bg-sidebar);
  border: 1px solid var(--border);
  font-size: 11.5px;
}
.att-preview-thumb {
  width: 24px;
  height: 24px;
  border-radius: 2px;
  object-fit: cover;
  cursor: pointer;
}
.att-info {
  display: flex;
  align-items: center;
  gap: 6px;
}
.att-name {
  font-weight: 400;
  color: var(--text-main);
  max-width: 160px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.att-size {
  color: var(--text-subtle);
  font-size: 10px;
}
.att-del-btn {
  background: transparent;
  border: none;
  color: var(--text-subtle);
  cursor: pointer;
  padding: 1px;
}
.att-del-btn:hover {
  color: var(--danger);
}

/* Drop Zone Overlay */
.drop-zone {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.05);
  border: 1px dashed var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: var(--text-main);
  font-size: 13px;
  font-weight: 500;
  z-index: 50;
  backdrop-filter: blur(2px);
}

/* Footer Info */
.note-footer {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 6px 48px;
  max-width: 860px;
  width: 100%;
  margin: 0 auto;
  border-top: 1px solid var(--border-subtle);
  font-size: 10.5px;
  color: var(--text-subtle);
}

/* Modals */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal-dialog {
  width: 100%;
  max-width: 420px;
  background: var(--bg-app);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  overflow: hidden;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-main);
}
.modal-close {
  font-size: 18px;
  line-height: 1;
}
.modal-body {
  padding: 18px;
}
.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 10px 18px;
  border-top: 1px solid var(--border);
  background: var(--bg-sidebar);
}

.color-picker-row {
  display: flex;
  gap: 8px;
}
.color-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
}
.color-dot.active {
  border-color: var(--text-main);
}

/* Dropdown Menu */
.dropdown-wrapper {
  position: relative;
}
.dropdown-menu {
  position: absolute;
  right: 0;
  top: 100%;
  margin-top: 4px;
  min-width: 190px;
  background: var(--bg-app);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  padding: 4px;
  z-index: 100;
}
.dropdown-item {
  display: flex;
  align-items: center;
  gap: 7px;
  width: 100%;
  padding: 6px 10px;
  border-radius: var(--radius-xs);
  background: transparent;
  border: none;
  font-size: 12px;
  color: var(--text-main);
  text-align: left;
  cursor: pointer;
}
.dropdown-item:hover {
  background: var(--bg-hover);
}
.dropdown-divider {
  height: 1px;
  background: var(--border);
  margin: 3px 0;
}

/* Stats */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}
.stat-card {
  padding: 10px;
  border-radius: var(--radius-xs);
  background: var(--bg-sidebar);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}
.stat-val {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-main);
}
.stat-lbl {
  font-size: 10.5px;
  color: var(--text-muted);
}
.settings-divider {
  height: 1px;
  background: var(--border);
  margin: 14px 0;
}
.settings-section h4 {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-bottom: 10px;
  color: var(--text-muted);
}

/* Lightbox */
.lightbox-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}
.lightbox-close {
  position: absolute;
  top: 16px;
  right: 16px;
  font-size: 26px;
  background: transparent;
  border: none;
  color: #ffffff;
  cursor: pointer;
}
#lightbox-img {
  max-width: 90vw;
  max-height: 85vh;
  border-radius: var(--radius-xs);
}
.lightbox-caption {
  margin-top: 10px;
  color: #e0e0e0;
  font-size: 12px;
}

/* Desktop / Mobile Visibility Helpers */
.mobile-only {
  display: none !important;
}
.desktop-only {
  display: inline-flex !important;
}

.view-header-left {
  display: flex;
  align-items: center;
  gap: 8px;
}
.view-header-right {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Mobile Responsive Optimization (< 768px) */
@media (max-width: 768px) {
  .mobile-only {
    display: inline-flex !important;
  }
  .desktop-only {
    display: none !important;
  }

  /* Main Layout as full-screen viewport */
  .main-layout {
    display: block !important;
    position: relative;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
  }

  /* Drawer Sidebar on Mobile */
  .main-layout .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 82%;
    max-width: 310px;
    height: 100%;
    z-index: 1000;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.4);
    transform: translateX(-100%);
    transition: transform 0.22s cubic-bezier(0.16, 1, 0.3, 1);
  }
  .main-layout.mobile-sidebar-open .sidebar {
    transform: translateX(0);
  }

  /* Backdrop Overlay */
  .mobile-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 990;
    backdrop-filter: blur(2px);
  }
  .main-layout.mobile-sidebar-open .mobile-backdrop {
    display: block;
  }

  /* Notes List Panel on Mobile */
  .main-layout .notes-panel {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
    display: flex;
    border-right: none;
  }

  /* Editor Panel on Mobile */
  .main-layout .editor-panel {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 20;
    display: none;
    background: var(--bg-app);
  }

  /* When an active note is open on mobile: show editor full-screen */
  .main-layout.mobile-editor-active .editor-panel {
    display: flex;
  }

  /* Touch Targets & Padding */
  .notes-panel-header {
    padding: 10px 14px;
    gap: 8px;
  }
  .btn-icon {
    width: 36px;
    height: 36px;
  }
  .btn-icon-subtle {
    width: 28px;
    height: 28px;
  }

  .editor-topbar {
    padding: 8px 12px;
  }
  .editor-header {
    padding: 14px 16px 6px 16px;
  }
  .note-title-input {
    font-size: 20px;
  }

  .markdown-toolbar {
    padding: 4px 12px;
    gap: 4px;
  }
  .tb-btn {
    padding: 4px 8px;
    font-size: 13px;
  }

  /* iOS Auto-zoom prevention: inputs must have min 16px font-size on mobile */
  .editor-pane textarea {
    padding: 12px 16px 28px 16px;
    font-size: 16px !important;
    line-height: 1.6;
  }
  .preview-pane {
    padding: 12px 16px 28px 16px;
    font-size: 15px;
  }

  .attachments-section {
    padding: 8px 16px;
    max-height: 140px;
  }
  .attachment-card {
    max-width: 100%;
    width: 100%;
  }

  .note-footer {
    padding: 6px 16px;
    font-size: 10px;
  }

  /* Modals on Mobile */
  .modal-dialog {
    width: 92% !important;
    max-width: 92% !important;
    margin: 12px;
  }
  .auth-card {
    width: 90% !important;
    max-width: 90% !important;
    padding: 24px 20px;
  }
}

/* Print Styles */
@media print {
  .sidebar, .notes-panel, .editor-topbar, .markdown-toolbar, .attachments-section, .note-footer {
    display: none !important;
  }
  .main-layout { display: block; height: auto; }
  .editor-panel { background: #ffffff; height: auto; }
  .editor-body { display: block; }
  .editor-pane { display: none; }
  .preview-pane { display: block !important; border: none; padding: 0; color: #000000; }
}
