:root {
  --primary: #0284c7;
  --primary-dark: #0369a1;
  --secondary: #64748b;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --bg: #f8fafc;
  --surface: #ffffff;
  --text: #1e293b;
  --text-light: #64748b;
  --border: #e2e8f0;
  --shadow: 0 1px 3px rgba(0,0,0,0.1);
  --shadow-lg: 0 10px 25px rgba(0,0,0,0.1);
  --sidebar-width: 260px;
  --header-height: 64px;
}

[data-theme="dark"] {
  --bg: #0f172a;
  --surface: #1e293b;
  --text: #f1f5f9;
  --text-light: #94a3b8;
  --border: #334155;
  --shadow: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-lg: 0 10px 25px rgba(0,0,0,0.5);
}

[data-theme="dark"] .modal {
  background: rgba(0,0,0,0.7);
}

[data-theme="dark"] .sidebar-overlay {
  background: rgba(0,0,0,0.7);
}

[data-theme="dark"] .error-message {
  background: rgba(239, 68, 68, 0.2);
  border-color: var(--danger);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

.screen {
  display: none !important;
}
.screen.active {
  display: block !important;
}

/* Login */
.login-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.login-card {
  background: var(--surface);
  padding: 2.5rem;
  border-radius: 1rem;
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 400px;
}
@media (max-width: 768px) {
  .login-card {
    padding: 1.5rem;
  }
  .login-header h1 {
    font-size: 1.5rem;
  }
}
@media (max-width: 480px) {
  .login-card {
    padding: 1.25rem;
  }
  .login-logo {
    max-width: 150px;
  }
}
.login-header {
  text-align: center;
  margin-bottom: 2rem;
}
.login-logo {
  max-width: 200px;
  height: auto;
  margin-bottom: 1rem;
}
.login-header h1 {
  font-size: 1.75rem;
  color: var(--primary);
  margin-bottom: 0.5rem;
}
.login-header p {
  color: var(--text-light);
}
.sidebar-logo {
  max-width: 100%;
  width: auto;
  height: auto;
  max-height: 60px;
  margin-bottom: 0.5rem;
  object-fit: contain;
}
.sidebar-header h2 {
  font-size: 0.9rem;
}
.login-form {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}
.error-message {
  color: var(--danger);
  font-size: 0.875rem;
  padding: 0.75rem;
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid var(--danger);
  border-radius: 0.5rem;
  margin-top: 0.5rem;
  display: none;
}
.error-message.show {
  display: block;
}

/* Main App Layout */
#main-app {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  overflow-y: auto;
  z-index: 1000;
  transition: transform 0.3s ease-in-out;
  -webkit-overflow-scrolling: touch;
}
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    box-shadow: 2px 0 8px rgba(0,0,0,0.1);
  }
  .sidebar.open {
    transform: translateX(0);
  }
}
.sidebar-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 999;
  opacity: 0;
  transition: opacity 0.3s ease-in-out;
}
.sidebar-overlay.active {
  display: block;
  opacity: 1;
}
@media (min-width: 769px) {
  .sidebar-overlay {
    display: none !important;
  }
}
.sidebar-header {
  padding: 1.5rem;
  border-bottom: 1px solid var(--border);
}
.sidebar-header h2 {
  color: var(--primary);
  font-size: 1.5rem;
}
.sidebar-nav {
  flex: 1;
  padding: 1rem 0;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.875rem 1.5rem;
  color: var(--text);
  text-decoration: none;
  transition: all 0.2s;
  touch-action: manipulation;
  min-height: 44px;
}
.nav-item:hover,
.nav-item:active {
  background: var(--bg);
  color: var(--primary);
}
.nav-item.active {
  background: rgba(2,132,199,0.1);
  color: var(--primary);
  border-left: 3px solid var(--primary);
}
@media (max-width: 768px) {
  .nav-item {
    padding: 1rem 1.5rem;
  }
}
.nav-icon {
  width: 20px;
  height: 20px;
}
.sidebar-footer {
  padding: 1rem;
  border-top: 1px solid var(--border);
}

/* Main Content */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  height: 100vh;
  min-height: 100vh;
  overflow: hidden;
}
@media (max-width: 768px) {
  .main-content {
    margin-left: 0;
  }
}
.main-header {
  height: var(--header-height);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  position: sticky;
  top: 0;
  z-index: 10;
}
.header-left {
  display: flex;
  align-items: center;
  gap: 1rem;
}
.main-header h1 {
  font-size: 1.5rem;
  color: var(--text);
  margin: 0;
}
.sidebar-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: 0.5rem;
  touch-action: manipulation;
  min-width: 44px;
  min-height: 44px;
  border-radius: 0.25rem;
  transition: background 0.2s;
}
.sidebar-toggle:hover,
.sidebar-toggle:active {
  background: var(--bg);
}
.sidebar-toggle svg {
  width: 24px;
  height: 24px;
}
@media (max-width: 768px) {
  .sidebar-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
  }
}
.section-content {
  flex: 1;
  min-height: 0;
  padding: 2rem;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
@media (max-width: 768px) {
  .section-content {
    padding: 1rem;
  }
}
@media (max-width: 480px) {
  .section-content {
    padding: 0.75rem;
  }
}

/* Buttons */
.btn {
  padding: 0.625rem 1.25rem;
  border: none;
  border-radius: 0.5rem;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}
.btn-primary {
  background: var(--primary);
  color: white;
}
.btn-primary:hover {
  background: var(--primary-dark);
}
.btn-secondary {
  background: var(--secondary);
  color: white;
}
.btn-secondary:hover {
  background: #475569;
}
.btn-success {
  background: var(--success);
  color: white;
}
.btn-danger {
  background: var(--danger);
  color: white;
}
.btn-block {
  width: 100%;
}
.btn-sm {
  padding: 0.375rem 0.75rem;
  font-size: 0.8125rem;
}

/* Forms */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.form-group label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text);
}
.form-group input,
.form-group select,
.form-group textarea {
  padding: 0.625rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  font-size: 0.875rem;
  font-family: inherit;
  transition: border-color 0.2s;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
}

/* Table */
.table-container {
  background: var(--surface);
  border-radius: 0.5rem;
  overflow: hidden;
  box-shadow: var(--shadow);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.table {
  width: 100%;
  border-collapse: collapse;
  min-width: 600px;
}
.table thead {
  background: var(--bg);
}
.table th,
.table td {
  padding: 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table th {
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--text-light);
  text-transform: uppercase;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 1;
}
.th-sortable { cursor: pointer; user-select: none; position: relative; padding-right: 1.5rem; }
.sort-indicator { display: inline-block; margin-left: 0.25rem; vertical-align: middle; }
.table tbody tr:hover {
  background: var(--bg);
}
.table-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.td-ellipsis {
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
}
@media (max-width: 768px) {
  .table th,
  .table td {
    padding: 0.75rem 0.5rem;
    font-size: 0.8125rem;
  }
  .table-actions {
    gap: 0.25rem;
  }
}

/* Tabla responsive que se ajusta a la pantalla */
.table-responsive-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.table-responsive-wrap .table-container {
  flex: 1;
  min-height: 0;
  overflow: auto;
}
/* Paginación */
.pagination-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  padding: 0.5rem 0;
}
.pagination-info {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  color: var(--text-light);
}
.pagination-info select {
  padding: 0.35rem 0.5rem;
  border-radius: 0.35rem;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}
.pagination-btns {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.pagination-btns .btn:disabled { opacity: 0.5; cursor: not-allowed; }
.pagination-page { font-size: 0.875rem; color: var(--text-light); }
@media (max-width: 600px) {
  .pagination-bar { flex-direction: column; align-items: stretch; }
  .pagination-btns { justify-content: center; }
}

/* Cards */
.card {
  background: var(--surface);
  border-radius: 0.5rem;
  padding: 1.5rem;
  box-shadow: var(--shadow);
}
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}
.card-title {
  font-size: 1.25rem;
  font-weight: 600;
}

/* Modal */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 2000;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.modal.active {
  display: flex;
}
.modal-content {
  background: var(--surface);
  border-radius: 0.5rem;
  max-width: 600px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  margin: auto;
}
.modal-large {
  max-width: 900px;
}
@media (max-width: 768px) {
  .modal {
    padding: 0.5rem;
    align-items: flex-start;
  }
  .modal-content {
    max-height: 95vh;
    margin-top: 1rem;
    border-radius: 0.75rem 0.75rem 0 0;
  }
  .modal-large {
    max-width: 100%;
  }
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.5rem;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 {
  font-size: 1.5rem;
}
.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-light);
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 0.25rem;
}
.modal-close:hover {
  background: var(--bg);
}
.modal-body {
  padding: 1.5rem;
}
.modal-footer {
  padding: 1.5rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
}

/* Grid */
.grid {
  display: grid;
  gap: 1.5rem;
}
.grid-2 {
  grid-template-columns: repeat(2, 1fr);
}
.grid-3 {
  grid-template-columns: repeat(3, 1fr);
}
@media (max-width: 768px) {
  .grid-2,
  .grid-3 {
    grid-template-columns: 1fr;
  }
}

/* Actions Bar */
.actions-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  gap: 1rem;
}
.search-box {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex: 1;
  max-width: 400px;
  min-width: 0;
}
.search-box input {
  flex: 1;
  padding: 0.625rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  font-size: 0.875rem;
  min-width: 0;
}
@media (max-width: 768px) {
  .actions-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
  }
  .search-box {
    max-width: 100%;
  }
  .actions-bar .btn {
    width: 100%;
  }
}

/* AI Assistant Button */
.ai-assistant-btn {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  border: none;
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  transition: transform 0.2s;
  touch-action: manipulation;
}
.ai-assistant-btn:hover,
.ai-assistant-btn:active {
  transform: scale(1.1);
}
.ai-assistant-btn svg {
  width: 24px;
  height: 24px;
}
@media (max-width: 768px) {
  .ai-assistant-btn {
    width: 48px;
    height: 48px;
    bottom: 1rem;
    right: 1rem;
  }
  .ai-assistant-btn svg {
    width: 20px;
    height: 20px;
  }
}

/* AI Chat */
.ai-chat {
  min-height: 400px;
  max-height: 500px;
  overflow-y: auto;
  padding: 1rem;
  background: var(--bg);
  border-radius: 0.5rem;
  margin-bottom: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.ai-message {
  padding: 0.75rem 1rem;
  border-radius: 0.5rem;
  max-width: 80%;
}
.ai-message.user {
  align-self: flex-end;
  background: var(--primary);
  color: white;
}
.ai-message.assistant {
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
}
.ai-input-container {
  display: flex;
  gap: 0.5rem;
}
.ai-input {
  flex: 1;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  font-size: 0.875rem;
}
.ai-send-btn {
  padding: 0.75rem 1rem;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 0.5rem;
  cursor: pointer;
  display: flex;
  align-items: center;
}
.ai-send-btn svg {
  width: 20px;
  height: 20px;
}

/* Badge */
.badge {
  display: inline-block;
  padding: 0.25rem 0.5rem;
  border-radius: 0.25rem;
  font-size: 0.75rem;
  font-weight: 500;
}
.badge-success {
  background: rgba(16,185,129,0.1);
  color: var(--success);
}
.badge-danger {
  background: rgba(239,68,68,0.1);
  color: var(--danger);
}
.badge-warning {
  background: rgba(245,158,11,0.1);
  color: var(--warning);
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-light);
}
.empty-state svg {
  width: 64px;
  height: 64px;
  margin-bottom: 1rem;
  opacity: 0.5;
}

/* Utilities */
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.text-sm { font-size: 0.875rem; }
.text-center { text-align: center; }

/* File Upload */
.file-upload-container {
  position: relative;
  display: inline-block;
  width: 100%;
}
.file-input {
  display: none;
}
.file-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.625rem;
  border: 2px dashed var(--border);
  border-radius: 0.5rem;
  cursor: pointer;
  transition: all 0.2s;
  background: var(--bg);
}
.file-label:hover {
  border-color: var(--primary);
  background: rgba(2,132,199,0.05);
}
.file-preview {
  margin-top: 0.75rem;
  padding: 0.75rem;
  background: var(--bg);
  border-radius: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.file-preview img {
  max-width: 100px;
  max-height: 100px;
  border-radius: 0.25rem;
  object-fit: cover;
}
.file-preview-info {
  flex: 1;
}
.file-preview-name {
  font-size: 0.875rem;
  color: var(--text);
  margin-bottom: 0.25rem;
}
.file-preview-size {
  font-size: 0.75rem;
  color: var(--text-light);
}
.file-remove-btn {
  padding: 0.25rem 0.5rem;
  background: var(--danger);
  color: white;
  border: none;
  border-radius: 0.25rem;
  cursor: pointer;
  font-size: 0.75rem;
}

/* Dashboard */
.dashboard {
  padding: 1.5rem;
}
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 1.5rem;
  margin-bottom: 2rem;
}
.stat-card {
  background: var(--surface);
  border-radius: 0.75rem;
  padding: 1.5rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  box-shadow: var(--shadow);
  transition: transform 0.2s, box-shadow 0.2s;
}
.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}
.stat-icon {
  width: 56px;
  height: 56px;
  border-radius: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.stat-icon svg {
  width: 28px;
  height: 28px;
}
.stat-content h3 {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 0.25rem;
}
.stat-content p {
  font-size: 0.875rem;
  color: var(--text-light);
  margin: 0;
}
.dashboard-sections {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 1.5rem;
}
.dashboard-section {
  background: var(--surface);
  border-radius: 0.75rem;
  padding: 1.5rem;
  box-shadow: var(--shadow);
}
.dashboard-section h2 {
  font-size: 1.25rem;
  color: var(--text);
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 2px solid var(--border);
}
.section-content {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.info-box {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem;
  background: var(--bg);
  border-radius: 0.5rem;
}
.info-box span {
  color: var(--text-light);
  font-size: 0.875rem;
}
.info-box strong {
  color: var(--text);
  font-size: 1rem;
}
.list-box {
  padding: 0.75rem;
  background: var(--bg);
  border-radius: 0.5rem;
}
.list-box strong {
  display: block;
  color: var(--text);
  font-size: 0.875rem;
  margin-bottom: 0.5rem;
}
.list-box ul {
  list-style: none;
  padding: 0;
  margin: 0;
}
.list-box li {
  padding: 0.5rem 0;
  color: var(--text);
  font-size: 0.875rem;
  border-bottom: 1px solid var(--border);
}
.list-box li:last-child {
  border-bottom: none;
}
.text-muted {
  color: var(--text-light) !important;
  font-style: italic;
}
.user-menu-container {
  position: relative;
}
.user-menu-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  background: none;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  color: var(--text);
  cursor: pointer;
  transition: all 0.2s;
  font-size: 0.875rem;
  touch-action: manipulation;
}
.user-menu-btn:hover {
  background: var(--bg);
  border-color: var(--primary);
}
.user-icon {
  width: 20px;
  height: 20px;
}
.dropdown-icon {
  width: 16px;
  height: 16px;
  transition: transform 0.2s;
}
.user-menu-btn.active .dropdown-icon {
  transform: rotate(180deg);
}
.user-menu {
  display: none;
  position: absolute;
  top: calc(100% + 0.5rem);
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  box-shadow: var(--shadow-lg);
  min-width: 200px;
  z-index: 1000;
  overflow: hidden;
}
.user-menu.active {
  display: block;
}
.user-menu-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  color: var(--text);
  text-decoration: none;
  transition: background 0.2s;
  border-bottom: 1px solid var(--border);
  font-size: 0.875rem;
  touch-action: manipulation;
}
.user-menu-item:last-child {
  border-bottom: none;
}
.user-menu-item svg {
  width: 18px;
  height: 18px;
}
.user-menu-item:hover {
  background: var(--bg);
  color: var(--primary);
}
.user-menu-item:active {
  background: var(--bg);
}

@media (max-width: 768px) {
  .dashboard {
    padding: 1rem;
  }
  .stats-grid {
    grid-template-columns: 1fr;
  }
  .dashboard-sections {
    grid-template-columns: 1fr;
  }
  .main-header {
    padding: 0 1rem;
  }
  .main-header h1 {
    font-size: 1.25rem;
  }
  .user-menu-btn span {
    display: none;
  }
  .user-menu {
    right: 0;
    min-width: 180px;
  }
}