/* ============================================
   MCV-USCIS — Residencia Permanente Platform
   Design: CRM-LEGISLATIVO exact match
   ============================================ */

* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --primary: #1E3A5F;
  --primary-light: #2D5A8E;
  --accent: #FFD700;
  --accent-dark: #D4A800;
  --success: #10B981;
  --warning: #F59E0B;
  --danger: #EF4444;
  --bg: #F0F4F8;
  --card: #FFFFFF;
  --text: #1F2937;
  --text-light: #6B7280;
  --border: #E5E7EB;
  --sidebar-w: 240px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

/* LOGIN */
.login-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
}

.login-card {
  background: white;
  border-radius: 16px;
  padding: 48px 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.login-logo {
  text-align: center;
  margin-bottom: 32px;
}

.login-logo img { width: 120px; height: auto; margin-bottom: 16px; }
.login-logo h1 { font-size: 24px; color: var(--primary); margin-bottom: 4px; }
.login-logo p { color: var(--text-light); font-size: 14px; }

.form-group { margin-bottom: 20px; }

.form-group label {
  display: block;
  font-weight: 600;
  font-size: 13px;
  margin-bottom: 6px;
  color: var(--text);
}

.form-group input, .form-group select, .form-group textarea {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
  transition: border-color 0.2s;
  font-family: inherit;
}

.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
}

.error-text { color: var(--danger); font-size: 13px; margin-top: 12px; text-align: center; }

.password-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.password-wrapper input { flex: 1; padding-right: 44px; }

.btn-eye {
  position: absolute;
  right: 8px;
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  opacity: 0.5;
  padding: 4px;
  line-height: 1;
}
.btn-eye:hover { opacity: 1; }

.login-footer { text-align: center; margin-top: 16px; font-size: 13px; color: var(--text-light); }
.login-footer a { color: var(--primary); font-weight: 600; text-decoration: none; }
.login-footer a:hover { text-decoration: underline; }

/* BUTTONS */
.btn {
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-light); }
.btn-accent { background: var(--accent); color: var(--primary); }
.btn-accent:hover { background: var(--accent-dark); }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text-light); }
.btn-outline:hover { background: var(--bg); }
.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #059669; }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #DC2626; }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-full { width: 100%; padding: 14px; font-size: 16px; }

/* LAYOUT */
#main-app {
  display: flex;
  min-height: 100vh;
}

/* SIDEBAR */
.sidebar {
  width: var(--sidebar-w);
  background: var(--primary);
  color: white;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  z-index: 100;
}

.sidebar-header {
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  flex-shrink: 0;
}

.sidebar-header img { height: 32px; }
.sidebar-title { font-size: 16px; font-weight: 700; }

.nav-menu {
  list-style: none;
  padding: 12px 0;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.nav-separator {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: rgba(255,255,255,0.35);
  padding: 16px 16px 6px;
  list-style: none;
}

.nav-item {
  padding: 12px 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
  transition: background 0.2s;
  border-left: 3px solid transparent;
  list-style: none;
}

.nav-item:hover { background: rgba(255,255,255,0.08); }

.nav-item.active {
  background: rgba(255,255,255,0.12);
  border-left-color: var(--accent);
  font-weight: 600;
}

.nav-icon { font-size: 18px; width: 24px; text-align: center; }

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid rgba(255,255,255,0.1);
  flex-shrink: 0;
}

.user-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
}

.user-info .btn-outline { color: rgba(255,255,255,0.7); border-color: rgba(255,255,255,0.3); }

.user-role-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 8px;
  font-size: 10px;
  font-weight: 600;
  background: rgba(255,255,255,0.15);
  color: rgba(255,255,255,0.8);
  margin-left: 4px;
}

/* CONTENT */
.content {
  margin-left: var(--sidebar-w);
  flex: 1;
  padding: 32px;
  max-width: 1200px;
}

.section { display: none; }
.section.active { display: block; }

.section h2 {
  font-size: 24px;
  color: var(--primary);
  margin-bottom: 24px;
  padding-bottom: 12px;
  border-bottom: 2px solid var(--accent);
}

/* STATS GRID */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--card);
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  border-left: 4px solid var(--primary);
}

.stat-card.gold { border-left-color: var(--accent); }
.stat-card.green { border-left-color: var(--success); }
.stat-card.red { border-left-color: var(--danger); }
.stat-card.blue { border-left-color: #2563EB; }

.stat-value { font-size: 32px; font-weight: 800; color: var(--primary); }
.stat-label { font-size: 13px; color: var(--text-light); margin-top: 4px; }

/* CARDS */
.card {
  background: var(--card);
  border-radius: 12px;
  padding: 24px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  margin-bottom: 16px;
}

.card h3 {
  font-size: 16px;
  color: var(--primary);
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

/* TOOLBAR */
.toolbar {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
  align-items: center;
}

.input-search, .input-select {
  padding: 10px 14px;
  border: 2px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  background: white;
}

.input-search { flex: 1; min-width: 200px; }
.input-search:focus, .input-select:focus { outline: none; border-color: var(--primary); }

/* TABLES */
.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.data-table th {
  background: var(--primary);
  color: white;
  padding: 12px 16px;
  text-align: left;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}

.data-table td {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

.data-table tr:hover td { background: #F8FAFC; }
.data-table tr:last-child td { border-bottom: none; }

.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* STATUS BADGES */
.status-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
  color: white;
}

.status-draft { background: var(--text-light); }
.status-submitted { background: #2563EB; }
.status-in_review { background: var(--warning); color: var(--text); }
.status-approved { background: var(--success); }
.status-rejected { background: var(--danger); }
.status-returned { background: #7C3AED; }

/* PAGINATION */
.pagination {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 20px;
}

.pagination button {
  padding: 8px 14px;
  border: 1px solid var(--border);
  background: white;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}

.pagination button.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.pagination button:disabled { opacity: 0.5; cursor: not-allowed; }

/* MODAL */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-content {
  background: white;
  border-radius: 16px;
  padding: 32px;
  width: 100%;
  max-width: 540px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.modal-header h3 {
  font-size: 20px;
  color: var(--primary);
  border: none;
  margin: 0;
  padding: 0;
}

.btn-close {
  background: none;
  border: none;
  font-size: 28px;
  cursor: pointer;
  color: var(--text-light);
  line-height: 1;
}
.btn-close:hover { color: var(--danger); }

.form-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* LOADING */
.loading {
  text-align: center;
  padding: 40px;
  color: var(--text-light);
}

.spinner {
  display: inline-block;
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* NOT FOUND */
.not-found {
  text-align: center;
  padding: 40px;
  color: var(--text-light);
}

.not-found-icon { font-size: 48px; margin-bottom: 12px; }

/* ============================================
   USCIS-SPECIFIC STYLES
   ============================================ */

/* FORM WIZARD */
.wizard-container {
  background: var(--card);
  border-radius: 12px;
  padding: 32px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.wizard-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 2px solid var(--accent);
}

.wizard-header h2 {
  font-size: 20px;
  color: var(--primary);
  margin: 0;
  padding: 0;
  border: none;
}

#form-step-indicator {
  font-size: 14px;
  color: var(--text-light);
  font-weight: 600;
}

.lang-toggle {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
}

.lang-btn {
  padding: 8px 16px;
  border: 2px solid var(--border);
  background: white;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text-light);
  transition: all 0.2s;
}

.lang-btn.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.step-section { margin-bottom: 24px; }

.step-section h3 {
  font-size: 18px;
  color: var(--primary);
  margin-bottom: 20px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.step-section label {
  display: block;
  margin-bottom: 16px;
  font-weight: 600;
  font-size: 13px;
  color: var(--text);
}

.step-section input,
.step-section select,
.step-section textarea {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px 14px;
  border: 2px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  transition: border-color 0.2s;
}

.step-section input:focus,
.step-section select:focus,
.step-section textarea:focus {
  outline: none;
  border-color: var(--primary);
}

.step-section input[type="file"] {
  padding: 10px;
  background: var(--bg);
}

.field-en {
  display: block;
  font-size: 11px;
  font-weight: 400;
  color: var(--text-light);
  font-style: italic;
  margin-top: 2px;
}

.file-uploaded {
  display: inline-block;
  margin-top: 6px;
  padding: 2px 10px;
  background: #D1FAE5;
  color: #065F46;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
}

.wizard-nav {
  display: flex;
  gap: 12px;
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.autosave-indicator {
  margin-top: 12px;
  font-size: 12px;
  color: var(--text-light);
  text-align: right;
}

/* APP CARDS GRID */
.apps-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.app-card {
  background: var(--card);
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  border-left: 4px solid var(--primary);
  cursor: pointer;
  transition: box-shadow 0.2s;
}

.app-card:hover { box-shadow: 0 4px 12px rgba(0,0,0,0.12); }

.app-card h3 {
  font-size: 18px;
  color: var(--primary);
  margin-bottom: 8px;
  border: none;
  padding: 0;
}

.app-card .meta {
  font-size: 13px;
  color: var(--text-light);
  margin-top: 10px;
  line-height: 1.6;
}

/* NEW APP SELECTOR */
#new-app-selector {
  background: var(--card);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

#new-app-selector p {
  font-weight: 600;
  color: var(--text);
  font-size: 14px;
}

/* AGENT DASHBOARD */
.agent-header {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
  color: white;
  border-radius: 12px;
  padding: 32px;
  margin-bottom: 24px;
}

.agent-header h3 { color: var(--accent); border: none; margin-bottom: 8px; font-size: 20px; }
.agent-header p { opacity: 0.9; }

/* REVIEW PANEL */
.review-panel {
  background: var(--card);
  border-radius: 12px;
  padding: 24px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.review-field {
  display: flex;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

.review-field:last-child { border-bottom: none; }
.review-field .field-label { color: var(--text-light); font-weight: 600; }
.review-field .field-value { color: var(--text); }

/* PROGRESS BAR */
.progress-container {
  background: #E5E7EB;
  border-radius: 12px;
  height: 24px;
  overflow: hidden;
  margin: 12px 0;
}

.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--accent) 0%, #F59E0B 100%);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--primary);
  transition: width 0.5s;
}

/* MOBILE HEADER (hidden on desktop) */
.mobile-header {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 56px;
  background: var(--primary);
  color: white;
  align-items: center;
  padding: 0 16px;
  z-index: 200;
  gap: 12px;
}

.btn-hamburger {
  background: none; border: none; color: white;
  font-size: 24px; cursor: pointer; padding: 4px 8px;
}

.mobile-title { font-weight: 700; font-size: 16px; flex: 1; }
.mobile-user { font-size: 12px; opacity: 0.8; }

.sidebar-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 99;
}

.sidebar-overlay.open { display: block; }

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 768px) {
  .mobile-header { display: flex; }

  .sidebar {
    width: 260px;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    z-index: 150;
    top: 0; left: 0; bottom: 0;
    height: 100vh;
    height: 100dvh;
  }
  .sidebar.open { transform: translateX(0); }

  .nav-menu {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 20px;
  }

  .nav-item { padding: 10px 16px; font-size: 13px; gap: 10px; }
  .nav-icon { font-size: 16px; }
  .nav-separator { padding: 8px 16px; font-size: 10px; }
  .sidebar-header { padding: 14px 16px; }
  .sidebar-footer { padding: 12px 16px; flex-shrink: 0; }

  .content {
    margin-left: 0;
    padding: 16px;
    padding-top: 72px;
    max-width: 100vw;
    overflow-x: hidden;
  }

  .grid-2 { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat-value { font-size: 24px; }
  .stat-label { font-size: 11px; }
  .stat-card { padding: 14px; }

  .section h2 { font-size: 18px; margin-bottom: 16px; }

  .data-table { font-size: 12px; min-width: 600px; }
  .data-table th, .data-table td { padding: 8px 10px; white-space: nowrap; }

  .toolbar { flex-direction: column; gap: 8px; }
  .input-search { min-width: 100%; }
  .input-select { width: 100%; }

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

  .login-card { padding: 32px 24px; margin: 16px; }

  .card { padding: 16px; }
  .card h3 { font-size: 14px; margin-bottom: 12px; }

  .modal-content { padding: 20px; max-width: 100%; }

  .wizard-container { padding: 20px; }
  .wizard-header { flex-direction: column; gap: 8px; text-align: center; }
  .wizard-header h2 { font-size: 16px; }

  .pagination { flex-wrap: wrap; }
  .pagination button { padding: 6px 10px; font-size: 12px; }

  body, .content { overflow-x: hidden !important; max-width: 100vw !important; }
}

@media (max-width: 420px) {
  .stats-grid { grid-template-columns: 1fr; }
  .stat-value { font-size: 22px; }
}

/* AUTO-ZOOM ADJUST */
html { overflow-x: hidden; }
.content { max-width: 100%; overflow-x: hidden; }

@media (min-resolution: 120dpi) and (max-width: 1400px) {
  :root { --sidebar-w: 200px; }
  .content { padding: 20px; }
  .section h2 { font-size: 18px; }
  .stats-grid { gap: 10px; }
  .stat-card { padding: 12px; }
  .stat-value { font-size: 22px; }
  .stat-label { font-size: 10px; }
  .card { padding: 14px; }
  .data-table { font-size: 12px; }
  .data-table th, .data-table td { padding: 6px 8px; }
  .toolbar { gap: 6px; }
  .nav-item { padding: 8px 14px; font-size: 12px; }
  .nav-icon { font-size: 14px; }
}

@media (max-width: 1024px) and (min-width: 769px) {
  :root { --sidebar-w: 200px; }
  .content { padding: 20px; max-width: 100%; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .grid-2 { grid-template-columns: 1fr; }
  .data-table { font-size: 12px; }
  .toolbar { flex-wrap: wrap; }
}

img, iframe, video, embed, object {
  max-width: 100%;
  height: auto;
}
