/* --- Variables y reset --- */
:root {
  --primary: #f97316;
  --primary-dark: #ea580c;
  --primary-light: #fb923c;
  --secondary: #f43f5e;
  --accent: #f59e0b;
  --success: #22c55e;
  --warning: #f59e0b;
  --admin: #f97316;
  --admin-dark: #ea580c;
  --bg-gradient: linear-gradient(135deg, #fed7aa 0%, #fdba74 100%);
  --card-bg: rgba(255, 255, 255, 0.95);
  --sidebar-bg: linear-gradient(180deg, var(--primary-dark) 0%, var(--primary) 100%);
  --sidebar-admin-bg: linear-gradient(180deg, var(--admin-dark) 0%, var(--admin) 100%);
  --text-dark: #431407;
  --text-light: #78716c;
  --text-white: #f8fafc;
  --border-light: rgba(255, 255, 255, 0.1);
  --shadow-sm: 0 4px 6px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 10px 15px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 20px 25px rgba(0, 0, 0, 0.15);
  --transition: all 0.3s ease;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg-gradient);
  color: var(--text-dark);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* --- Notificación integrada --- */
.notification {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  background-color: var(--secondary);
  color: white;
  padding: 16px 24px;
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  z-index: 10000;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 90%;
  animation: slideIn 0.3s ease-out;
}

.notification.hidden {
  animation: slideOut 0.3s ease-in forwards;
}

.notification i {
  font-size: 20px;
}

.notification-content {
  flex: 1;
}

.notification-close {
  background: none;
  border: none;
  color: white;
  cursor: pointer;
  font-size: 18px;
  padding: 0;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translate(-50%, -20px);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

@keyframes slideOut {
  from {
    opacity: 1;
    transform: translate(-50%, 0);
  }
  to {
    opacity: 0;
    transform: translate(-50%, -20px);
  }
}

/* --- Modal de confirmación --- */
.confirm-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10001;
  padding: 20px;
  animation: fadeIn 0.3s ease;
}

.confirm-modal.hidden {
  display: none;
}

.confirm-dialog {
  background: white;
  border-radius: 16px;
  padding: 24px;
  width: 100%;
  max-width: 500px;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.3s ease;
}

.confirm-title {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  color: var(--text-dark);
  font-size: 20px;
}

.confirm-title i {
  color: var(--secondary);
}

.confirm-message {
  margin-bottom: 24px;
  line-height: 1.5;
  color: var(--text-dark);
}

.confirm-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}

.confirm-actions .btn {
  min-width: 100px;
  justify-content: center;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* --- Editor de notas mejorado --- */
.note-editor {
  margin-bottom: 24px;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  overflow: hidden;
}

.editor-toolbar {
  display: flex;
  gap: 8px;
  padding: 12px;
  background: #f8fafc;
  border-bottom: 1px solid #e2e8f0;
  flex-wrap: wrap;
}

.toolbar-btn {
  padding: 8px;
  border: none;
  background: transparent;
  border-radius: 6px;
  cursor: pointer;
  color: var(--text-light);
  transition: var(--transition);
}

.toolbar-btn:hover {
  background: #e2e8f0;
  color: var(--primary);
}

.editor-content {
  padding: 16px;
  background: white;
}

.editor-title {
  width: 100%;
  padding: 12px 16px;
  border: none;
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 16px;
  border-bottom: 2px solid transparent;
  transition: var(--transition);
}

.editor-title:focus {
  outline: none;
  border-bottom-color: var(--primary);
}

.editor-body {
  min-height: 200px;
  padding: 12px 16px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  resize: vertical;
  width: 100%;
  font-family: inherit;
  line-height: 1.6;
}

.editor-body:focus {
  outline: none;
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px rgba(249, 115, 22, 0.2);
}

.editor-body img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  margin: 8px 0;
  cursor: pointer;
}

.editor-body img:hover {
  opacity: 0.9;
}

.image-placeholder {
  display: inline-block;
  width: 100%;
  padding: 40px;
  background: #f1f5f9;
  border: 2px dashed #cbd5e1;
  border-radius: 8px;
  text-align: center;
  color: var(--text-light);
  margin: 8px 0;
  cursor: pointer;
}

.image-placeholder:hover {
  background: #e2e8f0;
}

/* --- Selector de usuario (para admin) --- */
.user-selector {
  margin-bottom: 16px;
  padding: 12px;
  background: #f8fafc;
  border-radius: 10px;
  border: 1px solid #e2e8f0;
}

.user-selector label {
  display: block;
  margin-bottom: 8px;
  font-weight: 500;
  color: var(--text-dark);
}

.user-selector select {
  width: 100%;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid #e2e8f0;
  background: white;
  font-size: 14px;
}

/* --- Layout principal --- */
.app-container {
  display: flex;
  width: 100%;
  height: 100vh;
  overflow: hidden;
}

/* --- Sidebar --- */
.sidebar {
  width: 280px;
  background: var(--sidebar-bg);
  color: var(--text-white);
  display: flex;
  flex-direction: column;
  padding: 24px 16px;
  transition: var(--transition);
  box-shadow: var(--shadow-md);
  z-index: 10;
}

.sidebar.admin-sidebar {
  background: var(--sidebar-admin-bg);
}

.admin-badge {
  background: rgba(255, 255, 255, 0.2);
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 10px;
  margin-left: 8px;
  font-weight: 600;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 32px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border-light);
}

.logo {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), var(--primary-light));
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 700;
  font-size: 20px;
}

.admin-sidebar .logo {
  background: linear-gradient(135deg, #f97316, var(--admin));
}

.brand-text h1 {
  font-size: 18px;
  font-weight: 700;
  margin: 0;
}

.brand-text .tagline {
  font-size: 12px;
  opacity: 0.8;
  margin-top: 4px;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 16px;
  flex-grow: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: 10px;
  cursor: pointer;
  transition: var(--transition);
  color: rgba(255, 255, 255, 0.8);
  font-weight: 500;
  text-decoration: none;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-white);
}

.nav-item.active {
  background: rgba(255, 255, 255, 0.15);
  color: var(--text-white);
  box-shadow: var(--shadow-sm);
}

.nav-item i {
  width: 20px;
  text-align: center;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 20px;
  border-top: 1px solid var(--border-light);
}

.user-info {
  margin-bottom: 16px;
}

.user-info .label {
  font-size: 12px;
  opacity: 0.8;
  margin-bottom: 4px;
}

.user-info .username {
  font-weight: 600;
  font-size: 14px;
}

/* --- Main content --- */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-gradient);
}

.top-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  background: var(--card-bg);
  box-shadow: var(--shadow-sm);
  z-index: 5;
}

.page-title h2 {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-dark);
  margin-bottom: 4px;
}

.page-title .subtitle {
  font-size: 14px;
  color: var(--text-light);
}

.search-box {
  position: relative;
}

.search-box input {
  padding: 10px 16px 10px 40px;
  border-radius: 10px;
  border: 1px solid #e2e8f0;
  background: white;
  font-size: 14px;
  width: 280px;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
}

.search-box input:focus {
  outline: none;
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px rgba(249, 115, 22, 0.2);
}

.search-box i {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-light);
}

/* --- Content area --- */
.content-area {
  flex: 1;
  padding: 24px;
  overflow-y: auto;
}

.card {
  background: var(--card-bg);
  border-radius: 16px;
  padding: 24px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 24px;
  transition: var(--transition);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.5);
}

.card:hover {
  box-shadow: var(--shadow-md);
}

.card h3 {
  font-size: 20px;
  margin-bottom: 16px;
  color: var(--text-dark);
  display: flex;
  align-items: center;
  gap: 10px;
}

.card h3 i {
  color: var(--primary);
}

/* --- Home View --- */
.welcome-card ul {
  padding-left: 20px;
  margin: 16px 0;
}

.welcome-card li {
  margin-bottom: 10px;
  color: var(--text-light);
}

.welcome-card code {
  background: #f1f5f9;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: monospace;
  color: var(--primary-dark);
}

/* --- Notes View --- */
.notes-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.notes-actions {
  display: flex;
  gap: 12px;
}

.btn {
  padding: 10px 16px;
  border-radius: 10px;
  border: none;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: var(--transition);
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover {
  background: var(--primary-dark);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.btn-secondary {
  background: transparent;
  border: 1px solid #e2e8f0;
  color: var(--text-light);
}

.btn-secondary:hover {
  background: #f8fafc;
  border-color: var(--primary-light);
  color: var(--primary);
}

.btn-admin {
  background: var(--admin);
  color: white;
}

.btn-admin:hover {
  background: var(--admin-dark);
  transform: translateY(-2px);
  box-shadow: 0 10px 15px rgba(99, 102, 241, 0.2);
}

.btn-logout {
  background: var(--primary-light);
  color: white;
  width: 100%;
}

.btn-logout:hover {
  background: var(--primary-dark);
}

.note-form {
  margin-bottom: 24px;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  margin-bottom: 8px;
  font-weight: 500;
  color: var(--text-dark);
}

.form-control {
  width: 100%;
  padding: 12px 16px;
  border-radius: 10px;
  border: 1px solid #e2e8f0;
  font-size: 14px;
  transition: var(--transition);
  background: white;
}

.form-control:focus {
  outline: none;
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px rgba(249, 115, 22, 0.2);
}

textarea.form-control {
  min-height: 140px;
  resize: vertical;
}

.form-actions {
  display: flex;
  gap: 12px;
}

.notes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
  margin-top: 20px;
}

.note-card {
  background: white;
  border-radius: 12px;
  padding: 16px;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
  cursor: pointer;
  border-left: 4px solid var(--primary);
  position: relative;
}

.note-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-md);
}

.note-card h4 {
  font-size: 16px;
  margin-bottom: 8px;
  color: var(--text-dark);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-right: 20px;
}

.note-card .content-preview {
  font-size: 14px;
  color: var(--text-light);
  margin-bottom: 12px;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.note-card .image-preview {
  margin-top: 8px;
  border-radius: 8px;
  overflow: hidden;
  max-height: 120px;
}

.note-card .image-preview img {
  width: 100%;
  height: auto;
  object-fit: cover;
}

.note-meta {
  font-size: 12px;
  color: var(--text-light);
  display: flex;
  justify-content: space-between;
}

.note-author {
  font-style: italic;
  color: var(--admin);
}

.note-status {
  position: absolute;
  top: 16px;
  right: 16px;
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 10px;
}

.status-trash {
  background: #fee2e2;
  color: #ef4444;
}

/* --- Security View --- */
.field {
  margin-bottom: 20px;
}

.field label {
  display: block;
  margin-bottom: 8px;
  font-weight: 500;
  color: var(--text-dark);
}

/* --- Admin View --- */
.admin-dashboard {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 20px;
  margin-bottom: 24px;
}

.admin-stat {
  background: white;
  border-radius: 12px;
  padding: 20px;
  box-shadow: var(--shadow-sm);
  text-align: center;
}

.admin-stat .number {
  font-size: 32px;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 8px;
}

.admin-stat .label {
  font-size: 14px;
  color: var(--text-light);
}

.users-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 20px;
  background: white;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.users-table th,
.users-table td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid #e2e8f0;
}

.users-table th {
  background: #f8fafc;
  font-weight: 600;
  color: var(--text-dark);
}

.users-table tr:last-child td {
  border-bottom: none;
}

.users-table tr:hover {
  background: #f8fafc;
}

.user-actions {
  display: flex;
  gap: 8px;
}

.user-actions .btn {
  padding: 6px 10px;
  font-size: 12px;
}

.admin-badge-cell {
  background: #eef2ff;
  color: var(--admin);
  padding: 4px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
}

/* --- Login View --- */
.login-container {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: var(--bg-gradient);
  padding: 20px;
}

.login-card {
  background: var(--card-bg);
  border-radius: 16px;
  padding: 32px;
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 440px;
  text-align: center;
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.5);
}

.login-card h2 {
  margin-bottom: 12px;
  color: var(--text-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.login-card .description {
  color: var(--text-light);
  margin-bottom: 24px;
}

.login-form .form-group {
  margin-bottom: 20px;
  text-align: left;
}

.login-actions {
  display: flex;
  gap: 12px;
  margin-top: 24px;
}

.login-actions .btn {
  flex: 1;
  justify-content: center;
}

.login-note {
  font-size: 12px;
  color: var(--text-light);
  margin-top: 20px;
  line-height: 1.5;
}

.login-toggle {
  margin-top: 16px;
  font-size: 14px;
  color: var(--text-light);
}

.login-toggle a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 600;
  cursor: pointer;
}

.login-toggle a:hover {
  text-decoration: underline;
}

/* --- Modal --- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
  animation: fadeIn 0.3s ease;
}

.modal {
  background: white;
  border-radius: 16px;
  padding: 24px;
  width: 100%;
  max-width: 800px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.3s ease;
}

.modal h3 {
  margin-bottom: 16px;
  color: var(--text-dark);
  display: flex;
  align-items: center;
  gap: 10px;
}

.modal-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  margin-top: 20px;
}

.btn-danger {
  background: var(--secondary);
  color: white;
}

.btn-danger:hover {
  background: #e11d48;
  transform: translateY(-2px);
  box-shadow: 0 10px 15px rgba(244, 63, 94, 0.2);
}

/* --- Responsive --- */
@media (max-width: 968px) {
  .app-container {
    flex-direction: column;
    height: auto;
    min-height: 100vh;
  }
  
  .sidebar {
    width: 100%;
    padding: 16px;
  }
  
  .brand {
    margin-bottom: 20px;
  }
  
  .nav {
    flex-direction: row;
    overflow-x: auto;
    padding-bottom: 8px;
    margin-top: 0;
  }
  
  .nav-item {
    padding: 10px 16px;
    white-space: nowrap;
  }
  
  .sidebar-footer {
    display: none;
  }
  
  .top-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 16px;
    padding: 16px;
  }
  
  .search-box input {
    width: 100%;
  }
  
  .content-area {
    padding: 16px;
  }
  
  .notes-grid {
    grid-template-columns: 1fr;
  }

  .confirm-dialog {
    max-width: 90%;
  }

  .admin-dashboard {
    grid-template-columns: 1fr;
  }

  .users-table {
    font-size: 14px;
  }

  .users-table th,
  .users-table td {
    padding: 8px 12px;
  }
}

@media (max-width: 640px) {
  .notes-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 16px;
  }
  
  .notes-actions {
    width: 100%;
    flex-wrap: wrap;
  }
  
  .btn {
    flex: 1;
    min-width: 120px;
    justify-content: center;
  }
  
  .login-actions {
    flex-direction: column;
  }

  .confirm-actions {
    flex-direction: column;
  }

  .confirm-actions .btn {
    width: 100%;
  }

  .user-actions {
    flex-direction: column;
  }
}