@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
  --primary: #2563eb;
  --primary-dark: #1e40af;
  --bg-body: #f3f4f6;
  --bg-card: #ffffff;
  --text-main: #1f2937;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --sidebar-width: 260px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Inter', sans-serif;
  background-color: var(--bg-body);
  color: var(--text-main);
  -webkit-font-smoothing: antialiased;
}

/* --- UTILITIES --- */
.btn {
  padding: 0.75rem 1.25rem; border-radius: 0.5rem; font-weight: 500; border: none; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
  font-size: 0.95rem; transition: all 0.2s; white-space: nowrap;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { background: #ef4444; color: white; }
.btn-ghost { background: white; color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover { background: #f9fafb; }
.btn-icon { padding: 0.5rem; border-radius: 0.375rem; display: flex; align-items: center; justify-content: center; cursor: pointer; border: none; }

.form-input {
  width: 100%; padding: 0.8rem; border-radius: 0.5rem;
  border: 1px solid var(--border); font-size: 1rem;
}
.form-input:focus { outline: 2px solid var(--primary); border-color: transparent; }
.form-input.error { border-color: #ef4444; background-color: #fef2f2; }

.badge { padding: 0.3rem 0.6rem; border-radius: 99px; font-size: 0.75rem; font-weight: 600; }
.badge-blue { background: #dbeafe; color: #1e40af; }
.badge-green { background: #dcfce7; color: #166534; }
.badge-gray { background: #f3f4f6; color: #374151; }
.badge-yellow { background: #fef9c3; color: #854d0e; }

/* --- LAYOUT --- */
.login-container {
  display: flex; min-height: 100vh; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%); padding: 1rem;
}
.login-card {
  background: white; padding: 2rem; border-radius: 1rem; width: 100%; max-width: 400px; text-align: center;
}
.error-banner {
  background: #fef2f2; border: 1px solid #fee2e2; color: #991b1b;
  padding: 0.75rem; border-radius: 0.5rem; margin-bottom: 1rem; text-align: left; display: flex; align-items: center; gap: 0.5rem;
}

.dashboard-layout { display: flex; min-height: 100vh; position: relative; }

/* Sidebar */
.sidebar {
  width: var(--sidebar-width); background: #111827; color: white;
  display: flex; flex-direction: column; padding: 1.5rem;
  position: fixed; top: 0; bottom: 0; left: 0; z-index: 50;
  transition: transform 0.3s ease;
}
.sidebar.open { transform: translateX(0); }
.sidebar-logo { font-size: 1.4rem; font-weight: 700; margin-bottom: 2rem; display: flex; align-items: center; gap: 0.8rem; color: #60a5fa; }
.menu-item {
  display: flex; align-items: center; gap: 0.8rem; padding: 0.8rem 1rem;
  color: #d1d5db; background: rgba(255,255,255,0.05); border: none; border-radius: 0.5rem;
  font-size: 1rem; cursor: pointer; width: 100%; text-align: left; margin-bottom: 0.5rem;
}
.menu-item:hover { background: rgba(255,255,255,0.1); }
.menu-item.active { background: var(--primary); color: white; }

/* Content */
.main-content {
  margin-left: var(--sidebar-width); flex: 1; padding: 2rem;
  width: calc(100% - var(--sidebar-width));
}

/* Header */
.header-bar { display: flex; align-items: center; gap: 1rem; margin-bottom: 1.5rem; }
.header-title { margin: 0; font-size: 1.8rem; font-weight: 700; color: #111; }
.mobile-menu-btn { 
  display: none; background: white; border: 1px solid var(--border); 
  width: 44px; height: 44px; border-radius: 8px; 
  align-items: center; justify-content: center;
  color: #1f2937; cursor: pointer; padding: 0;
}

/* Stats */
.stats-grid { 
  display: grid; 
  grid-template-columns: repeat(3, 1fr); 
  gap: 1.5rem; margin-bottom: 2rem; 
}
.stat-card { background: white; padding: 1.5rem; border-radius: 0.8rem; border: 1px solid var(--border); box-shadow: 0 2px 4px rgba(0,0,0,0.05); display: flex; align-items: center; gap: 1rem; }
.stat-icon { width: 48px; height: 48px; border-radius: 10px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.stat-icon.blue { background: #eff6ff; color: var(--primary); }
.stat-icon.green { background: #dcfce7; color: #166534; }
.stat-info h3 { margin: 0 0 0.2rem 0; font-size: 0.9rem; color: var(--text-muted); font-weight: 500; }
.stat-info p { margin: 0; font-size: 1.5rem; font-weight: 700; color: var(--text-main); }

/* Action Bar */
.action-bar {
  display: flex; flex-wrap: wrap; gap: 1rem; align-items: center; justify-content: space-between;
  background: white; padding: 1rem; border-radius: 0.8rem; border: 1px solid var(--border); margin-bottom: 1.5rem;
}
.search-wrapper { flex: 1; min-width: 250px; position: relative; }
.search-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: #9ca3af; }
.form-input-search { padding-left: 2.5rem; }

/* Table */
.table-container { background: white; border-radius: 0.8rem; border: 1px solid var(--border); overflow: hidden; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; padding: 1rem; background: #f8fafc; font-size: 0.75rem; text-transform: uppercase; color: var(--text-muted); font-weight: 600; }
td { padding: 1rem; border-bottom: 1px solid var(--border); font-size: 0.95rem; }
.user-cell { display: flex; flex-direction: column; gap: 2px; }
.user-name { font-weight: 600; color: var(--text-main); }
tr.selected td { background-color: #eff6ff; }

/* Expanded Rows */
tr.expanded-row td { background: #f8fafc; padding: 0.5rem 1rem 1rem 1rem; }
.minors-list { padding-top: 0.5rem; }
.minor-card-display {
    background: white; border: 1px solid var(--border);
    padding: 0.8rem; margin-bottom: 0.5rem; border-radius: 0.5rem;
    display: flex; justify-content: space-between; align-items: center;
}

/* Modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 100; display: flex; align-items: center; justify-content: center; padding: 1rem; backdrop-filter: blur(2px); }
.modal { background: white; width: 100%; max-width: 600px; padding: 1.5rem; border-radius: 1rem; max-height: 90vh; overflow-y: auto; display: flex; flex-direction: column; }
.modal-content { flex: 1; overflow-y: auto; padding-right: 5px; }

/* Mobile */
@media (max-width: 1024px) {
  .sidebar { transform: translateX(-100%); box-shadow: 5px 0 15px rgba(0,0,0,0.2); }
  .sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.6); z-index: 40; }
  .sidebar-overlay.open { display: block; }

  .main-content { margin-left: 0; width: 100%; padding: 1rem; padding-top: 5rem; }
  
  .header-bar {
    position: fixed; top: 0; left: 0; right: 0; height: 4rem;
    background: white; border-bottom: 1px solid var(--border);
    padding: 0 1rem; margin: 0; z-index: 30;
    display: flex; align-items: center; gap: 1rem;
  }
  .mobile-menu-btn { display: flex !important; }
  .header-title { font-size: 1.2rem; }

  .stats-grid { grid-template-columns: 1fr; gap: 1rem; }

  .action-bar { flex-direction: column; align-items: stretch; gap: 0.8rem; padding: 1rem; }
  
  /* Mobile Table Card View */
  .table-container { background: transparent; border: none; }
  thead { display: none; }
  table, tbody, tr, td { display: block; width: 100%; }
  
  tr {
    background: white; margin-bottom: 1rem;
    border: 1px solid var(--border); border-radius: 0.8rem;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    position: relative; padding-top: 3.5rem;
  }

  td { display: flex; justify-content: space-between; align-items: center; padding: 0.8rem 1rem; text-align: right; border-bottom: 1px solid #f1f5f9; }
  /* Custom positioning for mobile cards - replicating your CSS logic */
  td:nth-child(1) { position: absolute; top: 0.8rem; left: 0.5rem; border: none; padding: 0; width: auto; } /* Expand btn */
  td:nth-child(2) { position: absolute; top: 0.8rem; left: 2.5rem; border: none; padding: 0; width: auto; } /* Checkbox */
  td:nth-child(3) { /* Nominativo */
    position: absolute; top: 0; left: 4.5rem; right: 0;
    height: 3.5rem; display: flex; align-items: center;
    border-bottom: 1px solid #f3f4f6; padding: 0 1rem 0 0; font-size: 1rem;
    justify-content: flex-start;
  }
  
  td:before { content: attr(data-label); font-weight: 600; color: #6b7280; font-size: 0.75rem; text-transform: uppercase; text-align: left; width: 40%; }
  /* Hide label for absolute positioned elements */
  td:nth-child(1):before, td:nth-child(2):before, td:nth-child(3):before { content: none; }

  td:last-child { background: #f9fafb; border-bottom: none; border-radius: 0 0 0.8rem 0.8rem; justify-content: center; gap: 1rem; padding: 1rem; }
  td:last-child:before { content: none; }

  tr.expanded-row { margin-top: -1rem; padding-top: 0; }
  tr.expanded-row td { display: block; text-align: left; background: #f8fafc; padding: 1rem; position: static; height: auto; }
  
  .modal { padding: 1rem; height: 100vh; max-height: 100vh; border-radius: 0; width: 100vw; max-width: none; }
}