:root {
  --bg-primary: #0f172a;
  --bg-card: #1e293b;
  --bg-card-hover: #27354f;
  --bg-elevated: #334155;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --border-color: #334155;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --success: #10b981;
  --danger: #ef4444;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font);
  background-color: var(--bg-primary);
  color: var(--text-main);
  min-height: 100vh;
  min-height: -webkit-fill-available;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* APP SHELL */
.app-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  max-width: 800px;
  margin: 0 auto;
  width: 100%;
}

/* HEADER */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: max(14px, env(safe-area-inset-top)) 16px 14px 16px;
  background-color: rgba(15, 23, 42, 0.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 50;
}

.header-left, .header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.app-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.brand-icon {
  font-size: 22px;
}

.brand-title {
  font-size: 19px;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.3px;
}

/* LIVE STATUS BADGE */
.live-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: 20px;
  background: rgba(16, 185, 129, 0.12);
  border: 1px solid rgba(16, 185, 129, 0.3);
  font-size: 11px;
  font-weight: 600;
  color: var(--success);
  transition: all 0.3s ease;
}

.live-badge.disconnected {
  background: rgba(239, 68, 68, 0.12);
  border-color: rgba(239, 68, 68, 0.3);
  color: var(--danger);
}

.live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background-color: var(--success);
  box-shadow: 0 0 8px var(--success);
  animation: pulse 2s infinite;
}

.live-badge.disconnected .live-dot {
  background-color: var(--danger);
  box-shadow: none;
  animation: none;
}

@keyframes pulse {
  0% { transform: scale(0.95); opacity: 0.8; }
  50% { transform: scale(1.2); opacity: 1; }
  100% { transform: scale(0.95); opacity: 0.8; }
}

/* BUTTONS */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: background-color 0.2s, transform 0.1s;
}

.btn:active {
  transform: scale(0.97);
}

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

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

.btn-sm {
  padding: 7px 12px;
  font-size: 13px;
  gap: 4px;
}

.btn-block {
  width: 100%;
}

.btn-ghost {
  background: transparent;
  color: var(--text-main);
  border: 1px solid var(--border-color);
}

.btn-icon {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  padding: 0;
  font-size: 16px;
}

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

/* SEARCH BAR */
.search-bar-wrap {
  padding: 14px 16px 8px 16px;
}

#search-input {
  width: 100%;
  padding: 12px 16px;
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-main);
  font-size: 15px;
  outline: none;
}

#search-input:focus {
  border-color: var(--primary);
}

/* VIEWS */
.view {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.view.hidden {
  display: none !important;
}

/* NOTES LIST GRID */
.notes-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px 16px 80px 16px;
}

.note-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px;
  cursor: pointer;
  transition: transform 0.15s, background-color 0.15s, border-color 0.15s;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.note-card:hover, .note-card:active {
  background-color: var(--bg-card-hover);
  border-color: #475569;
}

.note-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

.note-card-title {
  font-size: 17px;
  font-weight: 700;
  color: #fff;
  line-height: 1.3;
}

.note-card-date {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}

.note-card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 4px;
}

.note-filename {
  font-size: 12px;
  color: #64748b;
  font-family: monospace;
}

.task-progress-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.task-progress-badge {
  font-size: 12px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 12px;
  background: var(--bg-elevated);
  color: var(--text-muted);
}

.task-progress-badge.done {
  background: rgba(16, 185, 129, 0.15);
  color: var(--success);
}

.progress-mini-bar {
  width: 50px;
  height: 5px;
  background-color: var(--bg-elevated);
  border-radius: 3px;
  overflow: hidden;
}

.progress-mini-fill {
  height: 100%;
  background-color: var(--primary);
  border-radius: 3px;
}

/* EMPTY STATE */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 24px;
  text-align: center;
  gap: 12px;
}

.empty-icon {
  font-size: 48px;
}

.empty-state h3 {
  color: #fff;
  font-size: 20px;
}

.empty-state p {
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 12px;
}

/* EDITOR VIEW */
.editor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border-color);
  background: rgba(15, 23, 42, 0.8);
  gap: 8px;
}

.editor-tabs {
  display: flex;
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  padding: 3px;
  border: 1px solid var(--border-color);
}

.tab-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
}

.tab-btn.active {
  background: var(--primary);
  color: #fff;
}

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

.save-badge {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}

.editor-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 16px;
  overflow-y: auto;
  gap: 16px;
  padding-bottom: max(60px, env(safe-area-inset-bottom));
}

.editor-panel.hidden {
  display: none;
}

/* QUICK ADD TASK */
.quick-add-task {
  display: flex;
  gap: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 6px 8px;
}

#new-task-input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-main);
  font-size: 15px;
  outline: none;
  padding: 8px;
}

/* MARKDOWN BODY */
.markdown-body {
  font-size: 16px;
  line-height: 1.6;
  color: #e2e8f0;
}

.markdown-body h1, .markdown-body h2, .markdown-body h3 {
  color: #fff;
  margin: 18px 0 10px 0;
  font-weight: 700;
}

.markdown-body h1 { font-size: 22px; border-bottom: 1px solid var(--border-color); padding-bottom: 8px; }
.markdown-body h2 { font-size: 19px; }
.markdown-body h3 { font-size: 17px; }

.markdown-body p {
  margin-bottom: 12px;
}

.markdown-body ul {
  list-style-type: none;
  padding-left: 0;
  margin-bottom: 16px;
}

.markdown-body li {
  margin-bottom: 6px;
}

/* INTERACTIVE TASKS */
.task-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 10px 12px;
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  cursor: pointer;
  user-select: none;
  transition: all 0.15s ease;
}

.task-item:hover {
  background-color: var(--bg-card-hover);
}

.task-item.completed {
  opacity: 0.65;
  background-color: rgba(30, 41, 59, 0.4);
}

.task-checkbox-custom {
  width: 24px;
  height: 24px;
  min-width: 24px;
  border-radius: 6px;
  border: 2px solid #475569;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  margin-top: 1px;
}

.task-item.completed .task-checkbox-custom {
  background-color: var(--success);
  border-color: var(--success);
}

.task-checkbox-custom::after {
  content: "";
  display: none;
  width: 6px;
  height: 11px;
  border: solid #ffffff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
  margin-bottom: 2px;
}

.task-item.completed .task-checkbox-custom::after {
  display: block;
}

.task-label {
  flex: 1;
  font-size: 15px;
  color: var(--text-main);
  line-height: 1.4;
  word-break: break-word;
}

.task-item.completed .task-label {
  text-decoration: line-through;
  color: var(--text-muted);
}

/* RAW MARKDOWN EDITOR */
.markdown-toolbar {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 6px;
}

.tool-btn {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

#raw-editor {
  flex: 1;
  min-height: 380px;
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 14px;
  color: var(--text-main);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 14px;
  line-height: 1.6;
  resize: vertical;
  outline: none;
}

#raw-editor:focus {
  border-color: var(--primary);
}

/* MODALS */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.pin-box {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 28px 24px;
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.5);
}

.pin-icon {
  font-size: 40px;
  margin-bottom: 12px;
}

.pin-subtitle {
  color: var(--text-muted);
  font-size: 13px;
  margin: 6px 0 20px 0;
}

.pin-input-wrap input, #new-note-title {
  width: 100%;
  padding: 14px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: #fff;
  font-size: 20px;
  text-align: center;
  letter-spacing: 4px;
  outline: none;
  margin-bottom: 16px;
}

#new-note-title {
  font-size: 16px;
  letter-spacing: normal;
  text-align: left;
}

.error-msg {
  color: var(--danger);
  font-size: 13px;
  margin-bottom: 12px;
}

.hidden {
  display: none !important;
}
