/* =========================================
   Autoriza OC — Mobile-First Design
   ========================================= */

/* === Design Tokens === */
:root {
  --role-color: #6366f1;
  --bg: #f1f5f9;
  --bg-card: #ffffff;
  --text: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --border: #e2e8f0;
  --danger: #ef4444;
  --success: #22c55e;
  --warning: #eab308;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --radius-full: 9999px;
  --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 -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* === Base === */
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* === Login Page === */
.login-page {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse at top left, rgba(99, 102, 241, 0.12), transparent 50%),
    radial-gradient(ellipse at bottom right, rgba(139, 92, 246, 0.08), transparent 50%),
    var(--bg);
  padding: 1rem;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 2.5rem 2rem;
}

.login-header {
  text-align: center;
  margin-bottom: 2rem;
}

.login-icon {
  width: 56px;
  height: 56px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  border-radius: var(--radius);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 1rem;
  color: white;
}

.login-header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  margin: 0 0 0.25rem;
}

.login-header p {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin: 0;
}

.alert-banner {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #dc2626;
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  font-size: 0.875rem;
  margin-bottom: 1rem;
}

.btn-microsoft {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 0.875rem 1.5rem;
  background: var(--bg-card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  transition: var(--transition);
}

.btn-microsoft:hover {
  background: #f8fafc;
  border-color: #cbd5e1;
  box-shadow: var(--shadow);
}

.btn-microsoft:active {
  transform: scale(0.98);
}

.login-card .form-group {
  margin-bottom: 1.5rem;
}

.login-card .form-group label {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
}

.login-card .form-select {
  padding: 0.75rem 1rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  transition: var(--transition);
}

.login-card .form-select:focus {
  border-color: var(--role-color);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.btn-continue {
  width: 100%;
  padding: 0.875rem;
  background: var(--role-color);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.btn-continue:hover { filter: brightness(0.9); }
.btn-continue:active { transform: scale(0.98); }
.btn-continue:disabled { opacity: 0.6; cursor: not-allowed; }

/* === App Header === */
.app-header {
  background: var(--role-color);
  color: white;
  padding: 0.875rem 1rem;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 1px 8px rgba(0, 0, 0, 0.15);
}

.header-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 1400px;
  margin: 0 auto;
}

.header-brand {
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.role-switcher {
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: white;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2.5'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 6px center;
  padding-right: 24px;
}

.role-switcher:focus {
  outline: 2px solid rgba(255, 255, 255, 0.5);
  outline-offset: 1px;
}

.role-switcher option {
  color: #0f172a;
  background: white;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.user-name {
  font-size: 0.85rem;
  opacity: 0.9;
}

.btn-header-logout {
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: white;
  padding: 5px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  cursor: pointer;
  transition: var(--transition);
}

.btn-header-logout:hover {
  background: rgba(255, 255, 255, 0.25);
}

/* === Empresa Bar === */
.empresa-bar {
  display: flex;
  gap: 8px;
  padding: 12px 1rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.empresa-bar::-webkit-scrollbar {
  display: none;
}

.empresa-chip {
  flex-shrink: 0;
  padding: 8px 18px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-full);
  background: var(--bg-card);
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}

.empresa-chip:hover {
  border-color: var(--role-color);
  color: var(--role-color);
  background: var(--bg);
}

.empresa-chip.active {
  background: var(--role-color);
  border-color: var(--role-color);
  color: white;
  box-shadow: var(--shadow-sm);
}

/* === Main Content === */
.main-content {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1rem;
}

.section-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 1rem;
}

/* === Data Table (Desktop) === */
.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.88rem;
  background: var(--bg-card);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
}

.data-table thead th {
  background: var(--bg);
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.875rem 1rem;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 2;
  white-space: nowrap;
}

.data-table tbody tr {
  transition: background var(--transition);
}

.data-table tbody tr:hover {
  background: #f8fafc;
}

.data-table td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.data-table tbody tr:last-child td {
  border-bottom: none;
}

.font-monospace {
  font-family: 'SF Mono', 'Cascadia Code', 'Fira Code', monospace;
  font-size: 0.85em;
}

/* === Authorize Button === */
.btn-autorizar {
  background: var(--role-color);
  color: white;
  border: none;
  padding: 7px 18px;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}

.btn-autorizar:hover {
  filter: brightness(0.9);
  box-shadow: var(--shadow);
}

.btn-autorizar:active {
  transform: scale(0.96);
}

/* === Loading === */
.loading-bar .progress {
  height: 3px;
  border-radius: 3px;
  background: var(--border);
  overflow: hidden;
}

.loading-bar .progress-bar {
  background: var(--role-color);
}

/* === Empty State === */
.empty-state {
  text-align: center;
  padding: 4rem 1rem;
}

.empty-state-icon {
  width: 80px;
  height: 80px;
  background: var(--bg);
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 1rem;
}

.empty-state-icon svg {
  width: 36px;
  height: 36px;
  color: var(--text-muted);
}

.empty-state p {
  color: var(--text-muted);
  font-size: 1rem;
  margin: 0;
}

/* === Toast === */
.toast-container { z-index: 1100; }

.toast {
  border-radius: var(--radius-sm) !important;
  box-shadow: var(--shadow-md) !important;
  border: 1px solid var(--border) !important;
}

.toast.border-success {
  border-left: 4px solid var(--success) !important;
}

.toast.border-danger {
  border-left: 4px solid var(--danger) !important;
}

/* === Modal → Bottom Sheet (Mobile) === */
.modal-content {
  border-radius: var(--radius) !important;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
}

.modal-header { border-bottom: 1px solid var(--border); }
.modal-footer { border-top: 1px solid var(--border); }

@media (max-width: 767.98px) {
  .modal-dialog {
    position: fixed !important;
    bottom: 0;
    left: 0;
    right: 0;
    margin: 0 !important;
    max-width: 100% !important;
  }

  .modal.fade .modal-dialog {
    transform: translateY(100%) !important;
    transition: transform 0.3s ease !important;
  }

  .modal.show .modal-dialog {
    transform: translateY(0) !important;
  }

  .modal-content {
    border-radius: var(--radius-lg) var(--radius-lg) 0 0 !important;
    border: none !important;
  }

  .modal-footer .btn {
    flex: 1;
    padding: 0.75rem;
  }

  .modal-footer {
    padding: 1rem;
    gap: 0.5rem;
  }
}

/* === Admin Header === */
.admin-header {
  background: #1e293b;
  color: white;
  padding: 0.875rem 1rem;
  box-shadow: 0 1px 8px rgba(0, 0, 0, 0.15);
}

.admin-header .header-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* Admin tabs */
.admin-tabs {
  border-bottom: 1px solid var(--border) !important;
  margin-bottom: 1.5rem;
}

.admin-tabs .nav-link {
  color: var(--text-secondary);
  font-weight: 500;
  border: none !important;
  border-bottom: 2px solid transparent !important;
  padding: 0.75rem 1.25rem;
  transition: var(--transition);
  border-radius: 0 !important;
}

.admin-tabs .nav-link.active {
  color: var(--text);
  border-bottom-color: #6366f1 !important;
  background: none !important;
}

.admin-tabs .nav-link:hover:not(.active) {
  color: var(--text);
  border-bottom-color: var(--border) !important;
}

/* Filter toolbar */
.filter-toolbar {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
}

/* Admin tables */
#users-table, #companies-table {
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.88rem;
  background: var(--bg-card);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
}

#users-table thead th, #companies-table thead th {
  background: var(--bg);
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.875rem 1rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

#users-table td, #companies-table td {
  padding: 0.75rem 1rem;
  vertical-align: middle;
  border-bottom: 1px solid var(--border);
}

#users-table tbody tr:last-child td,
#companies-table tbody tr:last-child td {
  border-bottom: none;
}

/* Admin add company card */
.add-company-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.add-company-card .card-header {
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 0.9rem;
  padding: 0.875rem 1rem;
  color: var(--text-secondary);
}

/* === Mobile Card Layout for Tables === */
@media (max-width: 767.98px) {
  /* Data table → cards */
  .data-table,
  .data-table thead,
  .data-table tbody,
  .data-table tr,
  .data-table th,
  .data-table td {
    display: block;
  }

  .data-table {
    background: none;
    border: none;
    box-shadow: none;
    border-radius: 0;
  }

  .data-table thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
  }

  .data-table tbody tr {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    margin-bottom: 12px;
    padding: 1rem;
  }

  .data-table tbody tr:hover {
    background: var(--bg-card);
  }

  .data-table td {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 5px 0;
    border: none;
    font-size: 0.9rem;
    gap: 1rem;
  }

  .data-table td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.78rem;
    flex-shrink: 0;
    min-width: 80px;
  }

  .data-table td.td-authorize {
    margin-top: 10px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
    display: block;
  }

  .data-table td.td-authorize::before {
    display: none;
  }

  .data-table td.td-authorize .btn-autorizar {
    width: 100%;
    padding: 12px;
    font-size: 0.95rem;
    border-radius: var(--radius-sm);
  }

  /* Admin tables → cards */
  #users-table, #companies-table {
    background: none;
    border: none;
    box-shadow: none;
  }

  #users-table, #users-table thead, #users-table tbody,
  #users-table tr, #users-table th, #users-table td,
  #companies-table, #companies-table thead, #companies-table tbody,
  #companies-table tr, #companies-table th, #companies-table td {
    display: block;
  }

  #users-table thead, #companies-table thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
  }

  #users-table tbody tr, #companies-table tbody tr {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    margin-bottom: 12px;
    padding: 1rem;
  }

  #users-table td, #companies-table td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 5px 0;
    border: none;
    font-size: 0.9rem;
  }

  #users-table td::before, #companies-table td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.78rem;
    flex-shrink: 0;
    min-width: 80px;
  }

  .td-actions {
    margin-top: 8px;
    padding-top: 10px !important;
    border-top: 1px solid var(--border);
    display: flex !important;
    flex-wrap: wrap;
    gap: 8px;
  }

  .td-actions::before {
    display: none !important;
  }

  .td-actions .btn {
    flex: 1;
    min-width: 0;
    font-size: 0.8rem;
    padding: 8px 6px;
  }

  /* Admin filter stack on mobile */
  .filter-toolbar .row {
    gap: 0.5rem;
  }

  .section-title {
    font-size: 1rem;
  }

  .user-name {
    display: none;
  }
}

/* Small touch devices */
@media (max-width: 374px) {
  .login-card {
    padding: 2rem 1.25rem;
  }

  .empresa-chip {
    padding: 7px 14px;
    font-size: 0.8rem;
  }
}
