/* ── Base & CSS Variables ── */
:root {
  --bg-primary: #ffffff;
  --bg-secondary: #f8fafc;
  --bg-elevated: #ffffff;
  --border-color: #e2e8f0;
  --border-focus: #94a3b8;
  
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  
  --tree-line: #e2e8f0;
  --tree-hover: #f1f5f9;
  
  --level-0: #0f172a;
  --level-1: #1e293b;
  --level-2: #334155;
  --level-3: #475569;
  --level-4: #64748b;

  /* Highlight & Note styling */
  --highlight-bg: #fef08a;
  --highlight-text: #713f12;
  --note-bg: #f8fafc;
  --note-border: #cbd5e1;
  --note-text: #64748b;

  /* Speaking highlight */
  --speaking-bg: rgba(59, 130, 246, 0.12);
  --speaking-border: #3b82f6;

  /* Google Keep Card Styling */
  --card-bg: #ffffff;
  --card-border: #e2e8f0;
  --card-shadow: 0 1px 3px rgba(0,0,0,0.05);
  --card-hover-shadow: 0 4px 12px rgba(0,0,0,0.08);

  --topic-bg: #f8fafc;
  --topic-border: #cbd5e1;
  --topic-badge-bg: #0f172a;
  --topic-badge-text: #ffffff;

  --btn-bg: #f1f5f9;
  --btn-hover: #e2e8f0;
  --btn-border: #cbd5e1;
  --btn-active: #0f172a;
  --btn-active-text: #ffffff;

  --badge-bg: #e2e8f0;
  --badge-text: #334155;
  
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Code", "Fira Code", Menlo, Monaco, Consolas, monospace;
}

[data-theme="dark"] {
  --bg-primary: #0c0e12;
  --bg-secondary: #14171f;
  --bg-elevated: #1a1e28;
  --border-color: #262b38;
  --border-focus: #475569;
  
  --text-primary: #f1f5f9;
  --text-secondary: #cbd5e1;
  --text-muted: #64748b;
  
  --tree-line: #2d3444;
  --tree-hover: #1e2330;
  
  --level-0: #ffffff;
  --level-1: #f8fafc;
  --level-2: #e2e8f0;
  --level-3: #cbd5e1;
  --level-4: #94a3b8;

  --highlight-bg: #854d0e;
  --highlight-text: #fef08a;
  --note-bg: #14171f;
  --note-border: #2d3444;
  --note-text: #94a3b8;

  --speaking-bg: rgba(59, 130, 246, 0.25);
  --speaking-border: #60a5fa;

  --card-bg: #14171f;
  --card-border: #262b38;
  --card-shadow: 0 2px 6px rgba(0,0,0,0.3);
  --card-hover-shadow: 0 6px 16px rgba(0,0,0,0.45);

  --topic-bg: #1a1e28;
  --topic-border: #333a4d;
  --topic-badge-bg: #f1f5f9;
  --topic-badge-text: #0c0e12;

  --btn-bg: #1a1e28;
  --btn-hover: #262b38;
  --btn-border: #2d3444;
  --btn-active: #f1f5f9;
  --btn-active-text: #0c0e12;

  --badge-bg: #262b38;
  --badge-text: #94a3b8;
}

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

html, body {
  height: 100%;
  font-family: var(--font-sans);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

ul, ol, li {
  list-style: none !important;
  margin: 0;
  padding: 0;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* ── Header ── */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background-color: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-title {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text-primary);
}

.header-badge-btn {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  background-color: var(--badge-bg);
  color: var(--badge-text);
  border: 1px solid var(--border-color);
  border-radius: 5px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: all 0.15s ease;
  font-family: inherit;
}

.header-badge-btn:hover {
  background-color: var(--btn-hover);
  color: var(--text-primary);
  border-color: var(--border-focus);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ── Google Auth & User Profile ── */
.user-auth-box {
  display: inline-flex;
  align-items: center;
}

.btn-google-login {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background-color: var(--bg-primary);
  border-color: var(--border-color);
  color: var(--text-primary);
  font-weight: 600;
}

.btn-google-login:hover {
  background-color: var(--btn-hover);
  border-color: var(--border-focus);
}

.user-profile-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  padding: 2px 6px 2px 3px;
  border-radius: 20px;
  font-size: 11.5px;
  color: var(--text-primary);
}

.user-avatar {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  object-fit: cover;
}

.user-name {
  max-width: 110px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
}

.user-logout-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  padding: 0 2px;
  border-radius: 50%;
}

.user-logout-btn:hover {
  color: #ef4444;
}

/* ── Navigation / View Modes ── */
.nav-tabs {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  background-color: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  padding: 6px 16px;
  flex-shrink: 0;
}

.view-mode-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
}

/* View Mode Selector */
.view-mode-selector {
  display: flex;
  align-items: center;
  gap: 2px;
  background-color: var(--btn-bg);
  padding: 2px;
  border-radius: 6px;
  border: 1px solid var(--border-color);
}

.view-mode-btn {
  padding: 4px 10px;
  font-size: 11.5px;
  font-weight: 500;
  background: none;
  border: none;
  color: var(--text-secondary);
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.12s ease;
}

.view-mode-btn:hover {
  color: var(--text-primary);
}

.view-mode-btn.active {
  background-color: var(--bg-elevated);
  color: var(--text-primary);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

/* ── Main Content Single Scroll View ── */
.main-content {
  flex: 1;
  position: relative;
  overflow-y: auto;
  padding: 16px;
  -webkit-overflow-scrolling: touch;
}

.main-scroll-view {
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
}

/* ── Quick Note / Topic Creator Bar ── */
.keep-quick-box {
  max-width: 680px;
  margin: 0 auto 20px auto;
  background-color: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 10px;
  padding: 10px 14px;
  box-shadow: var(--card-shadow);
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.keep-quick-box:focus-within {
  border-color: var(--border-focus);
  box-shadow: var(--card-hover-shadow);
}

.keep-quick-input {
  width: 100%;
  border: none;
  outline: none;
  background: transparent;
  font-size: 13.5px;
  color: var(--text-primary);
  font-family: inherit;
  resize: none;
  min-height: 24px;
  max-height: 200px;
  line-height: 1.5;
  box-sizing: border-box;
}

.keep-quick-input::placeholder {
  color: var(--text-muted);
}

.quick-box-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
}

.btn-ai-quick {
  background-color: var(--badge-bg);
  color: var(--text-primary);
  font-weight: 600;
}

.btn-ai-quick:hover {
  background-color: var(--btn-active);
  color: var(--btn-active-text);
}

/* ── Common Tree Container ── */
.tree-container {
  padding-bottom: 70px;
  width: 100%;
}

/* ── 1. GOOGLE KEEP CARDS VIEW ── */
.keep-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
  align-items: start;
}

.keep-card {
  background-color: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 8px;
  padding: 12px 14px;
  box-shadow: var(--card-shadow);
  transition: box-shadow 0.15s ease, border-color 0.15s ease, background-color 0.15s ease;
  display: flex;
  flex-direction: column;
}

.keep-card:hover {
  box-shadow: var(--card-hover-shadow);
}

.keep-card.is-speaking-target {
  border-color: var(--speaking-border);
  background-color: var(--speaking-bg);
}

.keep-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 8px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--border-color);
  gap: 6px;
}

.keep-card-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding-bottom: 8px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--border-color);
  position: relative;
}

.keep-card.collapsed .keep-card-header {
  border-bottom: none;
  padding-bottom: 0;
  margin-bottom: 0;
}

.keep-card.collapsed .keep-card-body {
  display: none;
}

.keep-card-title {
  font-size: 14.5px;
  font-weight: 700;
  color: var(--text-primary);
  outline: none;
  flex: 1;
  min-width: 0;
  word-break: break-word;
}

.keep-card-actions {
  display: flex;
  align-items: center;
  gap: 3px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
  margin-left: auto;
}

.keep-card:hover .keep-card-actions,
.keep-card:focus-within .keep-card-actions {
  opacity: 1;
  pointer-events: auto;
}

.keep-card-body ul {
  padding-left: 18px !important;
}

.keep-card-body > ul {
  padding-left: 0 !important;
}

/* ── 2. CÂY PHÂN CẤP (Classic Tree View) ── */
.view-tree ul {
  padding-left: 22px !important;
}

.view-tree > ul {
  padding-left: 0 !important;
}

.view-tree li {
  position: relative;
  padding: 3px 0;
}

.view-tree ul li::before {
  content: '';
  position: absolute;
  left: -12px;
  top: 0;
  bottom: 0;
  width: 1px;
  background-color: var(--tree-line);
}

.view-tree ul li:last-child::before {
  bottom: calc(100% - 14px);
}

.view-tree ul li::after {
  content: '';
  position: absolute;
  left: -12px;
  top: 14px;
  width: 10px;
  height: 1px;
  background-color: var(--tree-line);
}

/* ── 3. KIỂU CHECKLIST (Clean & Elegant Task List) ── */
.view-checklist ul {
  padding-left: 24px !important;
  margin-top: 2px;
}

.view-checklist > ul {
  padding-left: 0 !important;
}

.view-checklist li {
  position: relative;
  padding: 4px 0;
}

.view-checklist ul li::before {
  content: '';
  position: absolute;
  left: -13px;
  top: 0;
  bottom: 0;
  width: 1.5px;
  background-color: var(--border-color);
}

.view-checklist ul li:last-child::before {
  bottom: calc(100% - 15px);
}

.view-checklist .node-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px;
  border-radius: 5px;
  background-color: transparent;
  transition: background-color 0.12s;
  width: 100%;
}

.view-checklist .node-item:hover {
  background-color: var(--tree-hover);
}

.view-checklist .node-item.is-topic {
  background-color: var(--topic-bg);
  border: 1px solid var(--topic-border);
  padding: 8px 12px;
  border-radius: 6px;
  margin: 10px 0 4px 0;
}

.view-checklist .node-item.is-topic .node-text {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
}

/* ── Highlight & In Đậm & Ghi Chú ── */
strong, b {
  font-weight: 700;
  color: var(--text-primary);
}

mark, .node-highlight {
  background-color: var(--highlight-bg);
  color: var(--highlight-text);
  padding: 1px 4px;
  border-radius: 3px;
  font-weight: 500;
}

/* Khối ghi chú phụ (Note container & box) */
.note-container {
  display: flex;
  align-items: flex-start;
  gap: 4px;
  margin-top: 4px;
  margin-left: 24px;
}

.node-note-box {
  flex: 1;
  padding: 5px 8px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--note-text);
  background-color: var(--note-bg);
  border-left: 2.5px solid var(--note-border);
  border-radius: 0 4px 4px 0;
  outline: none;
  font-family: inherit;
}

.node-note-box:hover,
.node-note-box:focus {
  background-color: var(--bg-elevated);
  border-color: var(--border-focus);
}

/* ── Checkbox Tinh Tế ── */
.task-checkbox {
  appearance: none;
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  min-width: 16px;
  border: 1.5px solid var(--border-focus);
  border-radius: 4px;
  background-color: var(--bg-elevated);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin: 0;
  position: relative;
  transition: all 0.12s ease;
}

.task-checkbox:hover {
  border-color: var(--text-primary);
}

.task-checkbox:checked {
  background-color: var(--btn-active);
  border-color: var(--btn-active);
}

.task-checkbox:checked::after {
  content: '✓';
  font-size: 11px;
  color: var(--btn-active-text);
  font-weight: bold;
  line-height: 1;
}

.node-item.is-completed .node-text {
  text-decoration: line-through;
  opacity: 0.5;
}

/* ── Node Item & Text ── */
.node-item {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  padding: 3px 6px;
  border-radius: 4px;
  cursor: default;
  width: 100%;
  word-break: break-word;
  position: relative;
  transition: background-color 0.15s ease;
}

.node-item.is-speaking-target {
  background-color: var(--speaking-bg);
  box-shadow: 0 0 0 1.5px var(--speaking-border);
}

.node-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  min-width: 18px;
  font-size: 10px;
  font-family: var(--font-mono);
  border: 1px solid var(--border-color);
  background-color: var(--bg-elevated);
  color: var(--text-secondary);
  border-radius: 3px;
  cursor: pointer;
  user-select: none;
  flex-shrink: 0;
  margin-top: 2px;
}

.node-toggle:hover {
  border-color: var(--border-focus);
  color: var(--text-primary);
}

.node-text {
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--text-primary);
  outline: none;
  padding: 1px 4px;
  border-radius: 3px;
  border: 1px solid transparent;
  cursor: text;
  flex: 1;
  min-width: 0;
  width: 100%;
}

.node-text:hover {
  border-color: var(--border-color);
  background-color: var(--bg-primary);
}

.node-text:focus {
  border-color: var(--border-focus);
  background-color: var(--bg-primary);
  box-shadow: 0 0 0 2px rgba(148, 163, 184, 0.2);
}

/* Node action buttons on hover (stays cleanly on the right, never covers text) */
.node-actions {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  opacity: 0;
  pointer-events: none;
  margin-left: auto;
  flex-shrink: 0;
  padding-left: 6px;
  transition: opacity 0.15s ease;
}

.node-item:hover .node-actions,
.node-item:focus-within .node-actions {
  opacity: 1;
  pointer-events: auto;
}

.node-action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 18px;
  font-size: 10.5px;
  font-family: var(--font-mono);
  background-color: var(--bg-elevated);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  border-radius: 3px;
  cursor: pointer;
  padding: 0 4px;
  min-width: 18px;
  line-height: 1;
}

.node-action-btn:hover {
  color: var(--text-primary);
  border-color: var(--border-focus);
  background-color: var(--btn-hover);
}

.node-action-btn.ai-btn {
  font-weight: 700;
  color: var(--text-primary);
  background-color: var(--btn-bg);
  border-color: var(--border-color);
}

.node-action-btn.ai-btn:hover {
  background-color: var(--btn-active);
  color: var(--btn-active-text);
  border-color: var(--btn-active);
}

/* Speaking State on buttons */
.node-action-btn.speak-btn.is-active-speaker,
#btnSpeakAll.is-active-speaker {
  background-color: var(--btn-active);
  color: var(--btn-active-text);
  border-color: var(--btn-active);
  animation: pulse 1s infinite alternate;
}

/* Mic / Voice Recording State */
.btn-mic {
  color: var(--text-primary);
  font-weight: 500;
}

.btn-mic.is-recording {
  background-color: #ef4444 !important;
  color: #ffffff !important;
  border-color: #dc2626 !important;
  animation: mic-pulse 0.8s infinite alternate !important;
}

@keyframes mic-pulse {
  from { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.6); transform: scale(1); }
  to { box-shadow: 0 0 0 6px rgba(239, 68, 68, 0); transform: scale(1.04); }
}

.node-action-btn.active-topic-btn {
  color: var(--topic-badge-text);
  background-color: var(--topic-badge-bg);
  border-color: var(--topic-badge-bg);
}

.node-action-btn.delete-btn:hover {
  color: #ef4444;
  border-color: #ef4444;
}

@media (hover: none) {
  .node-actions {
    opacity: 0.85;
  }
}

.collapsed > ul,
.collapsed > .note-container,
.collapsed > .node-note-box {
  display: none !important;
}

/* Topic Badge & Header */
.topic-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  font-family: var(--font-mono);
  background-color: var(--topic-badge-bg);
  color: var(--topic-badge-text);
  padding: 1px 5px;
  border-radius: 3px;
  flex-shrink: 0;
  user-select: none;
}

/* Floating Formatting Toolbar */
#formatFloatingBar {
  position: absolute;
  display: none;
  background-color: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 3px 4px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  z-index: 1000;
  gap: 3px;
  align-items: center;
}

#formatFloatingBar.show {
  display: flex;
}

/* ── Topic List Modal ── */
.topics-list-container {
  max-height: 380px;
  overflow-y: auto;
  margin: 12px 0 16px 0;
}

.topic-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.topic-list-item:hover {
  background-color: var(--btn-hover);
  border-color: var(--border-focus);
}

.topic-list-title {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 6px;
}

.topic-list-count {
  font-size: 11px;
  color: var(--text-muted);
  background-color: var(--badge-bg);
  padding: 2px 7px;
  border-radius: 4px;
}

/* ── Empty State ── */
.empty-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
  padding: 30px;
  gap: 8px;
}

/* ── Bottom Action Toolbar ── */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: 8px 16px;
  background-color: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
  flex-shrink: 0;
  gap: 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

/* ── Standard Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 11px;
  font-size: 12px;
  font-weight: 500;
  font-family: inherit;
  color: var(--text-secondary);
  background-color: var(--btn-bg);
  border: 1px solid var(--btn-border);
  border-radius: 5px;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
  user-select: none;
}

.btn:hover {
  background-color: var(--btn-hover);
  color: var(--text-primary);
  border-color: var(--border-focus);
}

.btn:active {
  transform: translateY(1px);
}

.btn.btn-primary {
  background-color: var(--btn-active);
  color: var(--btn-active-text);
  border-color: var(--btn-active);
}

.btn.btn-primary:hover {
  opacity: 0.92;
}

.btn.btn-sm {
  padding: 4px 8px;
  font-size: 11px;
}

/* ── Cloudflare Status Indicator ── */
.cloud-status {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--text-muted);
}

.cloud-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: var(--border-focus);
}

.cloud-dot.connected {
  background-color: #10b981;
}

.cloud-dot.syncing {
  background-color: #f59e0b;
  animation: pulse 1s infinite alternate;
}

.cloud-dot.error {
  background-color: #ef4444;
}

@keyframes pulse {
  from { opacity: 0.4; }
  to { opacity: 1; }
}

/* ── Modal Dialogs ── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
  padding: 16px;
}

.modal-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.modal-box {
  background-color: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  width: 100%;
  max-width: 480px;
  padding: 20px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.modal-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}

.modal-close {
  background: none;
  border: none;
  font-size: 16px;
  cursor: pointer;
  color: var(--text-muted);
}

.modal-close:hover {
  color: var(--text-primary);
}

.form-group {
  margin-bottom: 14px;
}

.form-label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 5px;
}

.form-input {
  width: 100%;
  padding: 8px 10px;
  font-size: 13px;
  font-family: var(--font-mono);
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 5px;
  color: var(--text-primary);
  outline: none;
}

.form-input:focus {
  border-color: var(--border-focus);
}

.form-hint {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
  line-height: 1.4;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
}

/* ── Tools & Settings Grid Menu ── */
.tools-grid-menu {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.tool-menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  color: var(--text-primary);
  text-align: left;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s ease;
  width: 100%;
}

.tool-menu-item:hover {
  background-color: var(--btn-hover);
  border-color: var(--border-focus);
}

.tool-item-icon {
  font-size: 20px;
  flex-shrink: 0;
}

.tool-item-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.tool-item-sub {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.tool-divider {
  height: 1px;
  background-color: var(--border-color);
  margin: 6px 0;
}

.btn-danger {
  background-color: rgba(239, 68, 68, 0.1);
  color: #ef4444;
  border-color: rgba(239, 68, 68, 0.3);
}

.btn-danger:hover {
  background-color: #ef4444;
  color: #ffffff;
}

/* ── Action Sheet (Mobile Touch Actions) ── */
.sheet-box {
  max-width: 420px;
  border-radius: 16px;
  padding: 18px 16px;
  background-color: var(--bg-elevated);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 14px;
}

.sheet-target-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
  max-width: 85%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sheet-actions-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.sheet-item-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 6px;
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  color: var(--text-primary);
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s ease;
}

.sheet-item-btn:hover,
.sheet-item-btn:active {
  background-color: var(--btn-hover);
  border-color: var(--border-focus);
}

.sheet-icon {
  font-size: 20px;
}

.sheet-btn-danger {
  color: #ef4444;
  background-color: rgba(239, 68, 68, 0.08);
  border-color: rgba(239, 68, 68, 0.2);
}

.sheet-btn-danger:hover,
.sheet-btn-danger:active {
  background-color: #ef4444;
  color: #ffffff;
}

/* ── Toast Notifications ── */
#toast {
  position: fixed;
  bottom: 60px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background-color: var(--text-primary);
  color: var(--bg-primary);
  padding: 6px 14px;
  font-size: 12px;
  font-weight: 500;
  border-radius: 6px;
  opacity: 0;
  pointer-events: none;
  transition: all 0.2s ease;
  z-index: 1000;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── Global Header Fix ── */
.header-left {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  white-space: nowrap;
}

.header-title {
  white-space: nowrap;
}

.header-badge-btn {
  white-space: nowrap;
}

/* ── Empty State ── */
.empty-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 48px 16px;
  color: var(--text-muted);
  user-select: none;
}

.empty-icon {
  font-size: 38px;
  margin-bottom: 10px;
  opacity: 0.9;
}

.empty-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.empty-sub {
  font-size: 12.5px;
  line-height: 1.5;
  max-width: 320px;
  color: var(--text-secondary);
}

/* ── Mobile Optimization & Responsive Refinement ── */
@media (max-width: 640px) {
  header {
    height: 48px;
    padding: max(6px, env(safe-area-inset-top)) 10px 6px 10px;
  }

  .header-title {
    font-size: 14px;
    font-weight: 700;
  }

  .header-badge-btn {
    font-size: 10.5px;
    padding: 2px 6px;
  }

  .header-right {
    gap: 4px;
  }

  .header-right .btn {
    padding: 4px 7px;
    font-size: 11px;
  }

  .btn-icon-btn {
    padding: 4px 6px !important;
    font-size: 13px !important;
  }

  /* Nav View Modes */
  .nav-tabs {
    padding: 6px 10px;
  }

  .view-mode-selector {
    width: 100%;
    display: flex;
    background-color: var(--bg-tertiary);
    padding: 3px;
    border-radius: 8px;
  }

  .view-mode-btn {
    flex: 1;
    text-align: center;
    padding: 6px 0;
    font-size: 11.5px;
    border-radius: 6px;
  }

  /* Main View */
  .main-content {
    padding: 10px 8px 80px 8px;
  }

  .keep-quick-box {
    margin-bottom: 12px;
    padding: 8px 10px;
    border-radius: 8px;
  }

  .keep-quick-input {
    font-size: 14px;
    min-height: 40px;
    line-height: 1.4;
  }

  .quick-box-actions {
    gap: 4px;
  }

  .quick-box-actions .btn {
    padding: 4px 8px;
    font-size: 11px;
  }

  /* Card Grid on Mobile */
  .keep-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .keep-card {
    padding: 10px 10px;
    border-radius: 10px;
  }

  .keep-card-header {
    display: flex;
    align-items: center;
    flex-wrap: nowrap;
    gap: 6px;
    padding-bottom: 6px;
    margin-bottom: 6px;
  }

  .keep-card-title {
    font-size: 14px;
    font-weight: 700;
  }

  /* Hide messy inline buttons on mobile, show only [+] and [⋯] */
  .keep-card-actions .speak-btn,
  .keep-card-actions .ai-btn,
  .keep-card-actions .card-add-note-btn,
  .keep-card-actions .card-delete-btn,
  .node-actions .speak-btn,
  .node-actions .ai-btn,
  .node-actions .add-note-btn,
  .node-actions .topic-toggle-btn,
  .node-actions .add-sibling-btn,
  .node-actions .delete-btn {
    display: none !important;
  }

  .keep-card-actions,
  .node-actions {
    display: inline-flex !important;
    align-items: center;
    gap: 4px;
    margin-left: auto;
    flex-shrink: 0;
    opacity: 0.9;
  }

  .node-action-btn {
    width: 28px !important;
    height: 28px !important;
    min-width: 28px !important;
    font-size: 14px !important;
    border-radius: 6px;
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--text-primary);
    padding: 0;
  }

  .node-action-btn:active {
    background-color: var(--btn-hover);
    border-color: var(--border-focus);
  }

  /* Node Items on Mobile */
  .node-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 2px;
    width: 100%;
    flex-wrap: nowrap;
  }

  .node-text {
    font-size: 13.5px;
    padding: 2px 4px;
    flex: 1;
    min-width: 0;
  }

  .task-checkbox {
    width: 17px;
    height: 17px;
    min-width: 17px;
  }

  .node-toggle {
    width: 18px;
    height: 18px;
    min-width: 18px;
    font-size: 10px;
  }

  /* Tree & Checklist Indentation on Mobile */
  .view-tree ul,
  .view-checklist ul {
    padding-left: 12px !important;
  }

  .note-container {
    margin-left: 12px;
    margin-top: 3px;
    gap: 3px;
  }

  .node-note-box {
    font-size: 12px;
    padding: 4px 6px;
  }

  /* Bottom Toolbar on Mobile */
  .toolbar {
    padding: 6px 8px max(6px, env(safe-area-inset-bottom)) 8px;
    gap: 5px;
    scrollbar-width: none;
    overflow-x: auto;
    flex-wrap: nowrap;
    white-space: nowrap;
  }

  .toolbar::-webkit-scrollbar {
    display: none;
  }

  .toolbar-group {
    gap: 4px;
    flex-shrink: 0;
  }

  .btn {
    padding: 5px 8px;
    font-size: 11px;
    white-space: nowrap;
  }

  /* Modals on Mobile */
  .modal-backdrop {
    padding: 8px;
  }

  .modal-box {
    max-width: 100%;
    border-radius: 12px;
    padding: 16px 14px;
  }
}
