/* ========== RESET & BASE ========== */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --primary-light: #e0e7ff;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --success: #22c55e;
  --warning: #f59e0b;
  --bg: #f8fafc;
  --bg-card: #ffffff;
  --bg-hover: #f1f5f9;
  --text: #1e293b;
  --text-secondary: #64748b;
  --text-light: #94a3b8;
  --border: #e2e8f0;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px rgba(0,0,0,0.1), 0 4px 6px rgba(0,0,0,0.05);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-xs: 6px;
  --transition: 0.2s ease;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ========== PAGES ========== */
.page {
  display: none;
  min-height: 100vh;
}
.page.active {
  display: block;
}

/* ========== BUTTONS ========== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
  white-space: nowrap;
}
.btn:active { transform: scale(0.97); }

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

.btn-secondary {
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--bg-hover); border-color: var(--text-light); }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}
.btn-ghost:hover { background: var(--bg-hover); color: var(--text); }

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

.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-lg { padding: 14px 28px; font-size: 16px; }
.btn-full { width: 100%; justify-content: center; }

.btn-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 14px;
  cursor: pointer;
  padding: 4px 0;
  margin-bottom: 20px;
  transition: color var(--transition);
}
.btn-back:hover { color: var(--text); }

/* ========== LANDING PAGE ========== */
.landing-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.landing-card {
  background: var(--bg-card);
  border-radius: 20px;
  padding: 48px 40px;
  text-align: center;
  box-shadow: var(--shadow-lg);
  max-width: 420px;
  width: 100%;
  animation: fadeUp 0.5s ease;
}

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

.logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 80px;
  height: 80px;
  background: var(--primary-light);
  border-radius: 20px;
  color: var(--primary);
  margin-bottom: 20px;
}

.landing-card h1 {
  font-size: 32px;
  font-weight: 700;
  margin-bottom: 8px;
}

.subtitle {
  color: var(--text-secondary);
  margin-bottom: 32px;
  font-size: 15px;
}

.landing-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ========== AUTH PAGE ========== */
.auth-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
  background: var(--bg);
}

.auth-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 36px 32px;
  box-shadow: var(--shadow-md);
  max-width: 400px;
  width: 100%;
  animation: fadeUp 0.3s ease;
}

.auth-card h2 {
  font-size: 24px;
  font-weight: 600;
  margin-bottom: 24px;
}

/* ========== FORM ========== */
.form-group {
  margin-bottom: 16px;
}
.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}
.form-group input[type="text"],
.form-group input[type="password"] {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  font-family: inherit;
  font-size: 15px;
  color: var(--text);
  background: var(--bg-card);
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}
.form-group input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}
.form-group input::placeholder {
  color: var(--text-light);
}

.error-message {
  background: #fef2f2;
  color: var(--danger);
  padding: 10px 14px;
  border-radius: var(--radius-xs);
  font-size: 13px;
  margin-bottom: 16px;
  border: 1px solid #fecaca;
}

.success-message {
  background: #f0fdf4;
  color: #15803d;
  padding: 10px 14px;
  border-radius: var(--radius-xs);
  font-size: 13px;
  margin-bottom: 16px;
  border: 1px solid #bbf7d0;
}

/* ========== DASHBOARD HEADER ========== */
.dashboard-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--primary);
}

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

.user-name {
  font-size: 13px;
  color: var(--text-secondary);
  margin-right: 8px;
}

/* ========== DASHBOARD NAV ========== */
.dashboard-content {
  max-width: 960px;
  margin: 0 auto;
  padding: 24px 20px;
}

.dashboard-nav {
  display: flex;
  gap: 8px;
  margin-bottom: 24px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 12px;
}

.nav-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: none;
  border: none;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
}
.nav-btn:hover { background: var(--bg-hover); color: var(--text); }
.nav-btn.active { background: var(--primary-light); color: var(--primary); }

/* ========== TABS ========== */
.tab-content {
  display: none;
  animation: fadeUp 0.3s ease;
}
.tab-content.active { display: block; }

/* ========== NOTES LIST ========== */
.notes-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.notes-header h2 { font-size: 20px; font-weight: 600; }

.notes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.note-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
  overflow: hidden;
}
.note-card:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--primary);
  transform: translateY(-2px);
}

.note-card h3 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.note-card .note-preview {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 12px;
}

.note-card .note-date {
  font-size: 12px;
  color: var(--text-light);
}

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-light);
}
.empty-state svg { margin-bottom: 16px; }
.empty-state p { margin-bottom: 20px; font-size: 15px; }

/* ========== EDITOR ========== */
.editor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.editor-header h2 { font-size: 20px; font-weight: 600; }
.editor-actions { display: flex; gap: 8px; }

.editor-form {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}

#quill-editor {
  min-height: 300px;
  font-size: 15px;
}

.ql-toolbar.ql-snow {
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  border-color: var(--border);
}
.ql-container.ql-snow {
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  border-color: var(--border);
}

.editor-footer {
  margin-top: 20px;
  display: flex;
  justify-content: flex-end;
}

/* ========== MODAL ========== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
}

.modal-content {
  position: relative;
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  max-width: 500px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  animation: fadeUp 0.3s ease;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 18px; font-weight: 600; }

.btn-close {
  background: none;
  border: none;
  font-size: 24px;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 0;
  line-height: 1;
}
.btn-close:hover { color: var(--text); }

.modal-body {
  padding: 24px;
}

.settings-section {
  margin-bottom: 28px;
}
.settings-section:last-child { margin-bottom: 0; }
.settings-section h4 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 12px;
}

.help-text {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.devices-list {
  margin-top: 16px;
}

.device-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.device-item:last-child { border-bottom: none; }
.device-name { font-weight: 500; }
.device-date { color: var(--text-light); font-size: 12px; }

/* ========== TOAST ========== */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  color: white;
  box-shadow: var(--shadow-lg);
  animation: slideIn 0.3s ease;
  max-width: 360px;
}
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.info { background: var(--primary); }

@keyframes slideIn {
  from { opacity: 0; transform: translateX(40px); }
  to { opacity: 1; transform: translateX(0); }
}

/* ========== LOADING ========== */
.loading {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255,255,255,0.3);
  border-radius: 50%;
  border-top-color: white;
  animation: spin 0.6s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ========== RESPONSIVE ========== */
@media (max-width: 768px) {
  .landing-card {
    padding: 36px 24px;
  }

  .dashboard-header {
    padding: 10px 16px;
    flex-wrap: wrap;
    gap: 8px;
  }

  .header-right {
    flex-wrap: wrap;
  }

  .user-name {
    display: none;
  }

  .dashboard-content {
    padding: 16px 12px;
  }

  .dashboard-nav {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .notes-grid {
    grid-template-columns: 1fr;
  }

  .editor-form {
    padding: 16px;
  }

  .notes-header {
    flex-direction: column;
    gap: 12px;
    align-items: flex-start;
  }

  .editor-header {
    flex-direction: column;
    gap: 12px;
    align-items: flex-start;
  }

  .modal-content {
    max-height: 90vh;
    margin: 10px;
  }

  .toast-container {
    left: 16px;
    right: 16px;
    bottom: 16px;
  }

  .toast {
    max-width: 100%;
  }
}

@media (max-width: 480px) {
  .landing-card h1 {
    font-size: 26px;
  }

  .btn-lg {
    padding: 12px 24px;
    font-size: 15px;
  }
}
