/* === VARIABLES === */
:root {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface2: #f0f2f5;
  --text: #1a1a2e;
  --text2: #6c757d;
  --text-muted: #8f9bb3;
  --border: #dee2e6;
  --primary: #4a6cf7;
  --primary-hover: #3b5de7;
  --primary-light: rgba(74,108,247,0.08);
  --secondary: #6c757d;
  --secondary-hover: #5a6268;
  --success: #28a745;
  --warning: #ffc107;
  --danger: #dc3545;
  --info: #17a2b8;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 16px;
  --transition: 0.2s ease;
  --header-height: 60px;
}

/* === DARK THEME === */
body.dark {
  --bg: #0f0f1a;
  --surface: #1a1a2e;
  --surface2: #16213e;
  --text: #e8e8f0;
  --text2: #a0a0b8;
  --text-muted: #6b6b82;
  --border: #2a2a4a;
  --primary-light: rgba(74,108,247,0.12);
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.2);
  --shadow: 0 2px 8px rgba(0,0,0,0.3);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.4);
}

body.dark .theme-icon-light { display: none; }
body.dark .theme-icon-dark { display: inline; }
body:not(.dark) .theme-icon-light { display: inline; }
body:not(.dark) .theme-icon-dark { display: none; }

/* === RESET === */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  transition: background var(--transition), color var(--transition);
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* === HEADER === */
.header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-height);
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 0;
  z-index: 1000;
  gap: 8px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.header-title {
  font-size: 1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
}

/* Hamburger */
.hamburger {
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  border-radius: var(--radius-sm);
  transition: background var(--transition);
}
.hamburger:hover { background: var(--primary-light); }
.hamburger span {
  display: block;
  width: 20px;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
  transition: transform var(--transition), opacity var(--transition);
}
.hamburger.active span:nth-child(1) { transform: rotate(45deg) translate(4px, 4px); }
.hamburger.active span:nth-child(2) { opacity: 0; }
.hamburger.active span:nth-child(3) { transform: rotate(-45deg) translate(4px, -4px); }

/* Navigation */
.header-nav {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: 1;
  justify-content: flex-end;
}

.header-nav > a, .header-nav .dropbtn {
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.82rem;
  transition: background var(--transition), color var(--transition);
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
  border: none;
  background: none;
  font-family: inherit;
}

.header-nav > a:hover, .dropdown:hover .dropbtn {
  background: var(--primary-light);
  color: var(--primary);
  text-decoration: none;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.user-info {
  font-size: 0.78rem;
  color: var(--text2);
  display: none;
}

.header-actions {
  display: flex;
  gap: 4px;
  align-items: center;
}

/* Dropdown nav */
.dropdown { position: relative; display: inline-block; }
.dropdown .dropbtn { cursor: pointer; }
.dropdown-content {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  background: var(--surface);
  min-width: 200px;
  box-shadow: var(--shadow-lg);
  z-index: 1000;
  border-radius: 0 0 var(--radius) var(--radius);
  border: 1px solid var(--border);
  border-top: none;
  overflow: hidden;
}
.dropdown-content a {
  display: block;
  padding: 10px 16px;
  text-decoration: none;
  color: var(--text);
  font-size: 0.85rem;
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}
.dropdown-content a:last-child { border-bottom: none; }
.dropdown-content a:hover { background: var(--primary-light); color: var(--primary); text-decoration: none; }
.dropdown:hover .dropdown-content { display: block; }

/* Mobile overlay */
.nav-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 998;
}
.nav-overlay.active { display: block; }

/* Mobile nav drawer */
.mobile-nav {
  display: none;
  position: fixed;
  top: 0;
  left: -280px;
  width: 280px;
  height: 100vh;
  background: var(--surface);
  z-index: 999;
  overflow-y: auto;
  transition: left 0.3s ease;
  box-shadow: var(--shadow-lg);
  border-right: 1px solid var(--border);
}
.mobile-nav.open { left: 0; }
.mobile-nav-header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 700;
  font-size: 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.mobile-nav a {
  display: block;
  padding: 14px 20px;
  color: var(--text);
  text-decoration: none;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
  transition: background var(--transition);
}
.mobile-nav a:hover { background: var(--primary-light); color: var(--primary); text-decoration: none; }
.mobile-nav .nav-section {
  padding: 10px 20px 4px;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  font-weight: 600;
}

/* === CONTAINER === */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px;
}

.page-title {
  font-size: 1.35rem;
  margin-bottom: 16px;
  color: var(--text);
  font-weight: 700;
}

.page-header {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 16px;
}
.page-header > .flex-between, .page-header > div:last-child {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* === CARDS === */
.cards-grid, .dashboard-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition), box-shadow var(--transition);
}
.card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }

.card h3, .card .card-value {
  font-size: 1.6rem;
  font-weight: 700;
  margin-bottom: 2px;
  color: var(--primary);
  line-height: 1.2;
}

.card p, .card .card-title {
  font-size: 0.78rem;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.card-warning h3, .card-warning .card-value { color: #e67e22; }
.card-danger h3, .card-danger .card-value { color: var(--danger); }
.card-success h3, .card-success .card-value { color: var(--success); }
.card-info h3, .card-info .card-value { color: var(--info); }

/* === QUICK ACTIONS === */
.quick-actions {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

.quick-actions h3 {
  margin-bottom: 12px;
  font-size: 1rem;
  font-weight: 600;
}

.actions-grid {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* === BUTTONS === */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  cursor: pointer;
  text-decoration: none;
  transition: background var(--transition), opacity var(--transition), transform var(--transition);
  text-align: center;
  font-family: inherit;
  line-height: 1.4;
  font-weight: 500;
}
.btn:hover { text-decoration: none; opacity: 0.92; transform: translateY(-1px); }
.btn:active { transform: translateY(0); }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }

.btn-secondary { background: var(--secondary); color: #fff; }
.btn-secondary:hover { background: var(--secondary-hover); }

.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-warning { background: #e67e22; color: #fff; }
.btn-info { background: var(--info); color: #fff; }

.btn-sm { padding: 5px 12px; font-size: 0.8rem; }
.btn-lg { padding: 12px 24px; font-size: 1rem; }
.btn-block { width: 100%; justify-content: center; }

.btn-theme {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 0.95rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: background var(--transition), border-color var(--transition);
  line-height: 1;
}
.btn-theme:hover { background: var(--primary-light); border-color: var(--primary); }

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* === FORMS === */
.form-standard {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  max-width: 100%;
  box-shadow: var(--shadow-sm);
}

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

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

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  background: var(--surface);
  color: var(--text);
  transition: border-color var(--transition), box-shadow var(--transition);
  font-family: inherit;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.form-row {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.form-group-flex { flex: 1; }

.form-actions {
  margin-top: 16px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.input-select {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 0.85rem;
}

/* === SEARCH === */
.search-form {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.search-form input, .search-form select {
  flex: 1;
  min-width: 180px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  background: var(--surface);
  color: var(--text);
  transition: border-color var(--transition);
}
.search-form input:focus, .search-form select:focus {
  outline: none;
  border-color: var(--primary);
}

/* === TABLE === */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.table {
  width: 100%;
  border-collapse: collapse;
  min-width: 600px;
}

.table th, .table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
  vertical-align: middle;
}

.table th {
  background: var(--surface2);
  font-weight: 600;
  white-space: nowrap;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: var(--text2);
  position: sticky;
  top: 0;
  z-index: 1;
}

.table tbody tr:hover {
  background: var(--primary-light);
}

.table-sm td, .table-sm th { padding: 7px 10px; font-size: 0.8rem; }

/* Compact table for cards */
.table-compact { min-width: auto; }
.table-compact th, .table-compact td { padding: 6px 10px; font-size: 0.78rem; }

.text-center { text-align: center; }
.text-success { color: var(--success); font-weight: 600; }
.text-danger { color: var(--danger); font-weight: 600; }
.text-warning { color: #e67e22; font-weight: 600; }

.actions {
  white-space: nowrap;
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.row-warning { background: rgba(255,193,7,0.06); }
.row-active { background: var(--primary-light); }

/* === BADGES === */
.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.2px;
}

.badge-primary { background: var(--primary-light); color: var(--primary); }
.badge-secondary { background: rgba(108,117,125,0.12); color: var(--secondary); }
.badge-success { background: rgba(40,167,69,0.12); color: var(--success); }
.badge-warning { background: rgba(255,193,7,0.15); color: #b8860b; }
.badge-danger { background: rgba(220,53,69,0.12); color: var(--danger); }
.badge-info { background: rgba(23,162,184,0.12); color: var(--info); }

body.dark .badge-warning { color: #e6b800; }
body.dark .badge-secondary { color: #a0a0b8; }

/* === ALERTS === */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 14px;
  font-size: 0.88rem;
  line-height: 1.5;
  border: 1px solid transparent;
}

.alert-success {
  background: rgba(40,167,69,0.08);
  border-color: rgba(40,167,69,0.2);
  color: var(--success);
}

.alert-error {
  background: rgba(220,53,69,0.08);
  border-color: rgba(220,53,69,0.2);
  color: var(--danger);
}

.alert-warning {
  background: rgba(255,193,7,0.08);
  border-color: rgba(255,193,7,0.2);
  color: #b8860b;
}

body.dark .alert-warning { color: #e6b800; }

/* === LOGIN === */
.login-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: linear-gradient(135deg, #4a6cf7 0%, #6c63ff 50%, #3b5de7 100%);
}

.login-box {
  background: var(--surface);
  padding: 32px 28px;
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow-lg);
}

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

.login-logo h1 {
  font-size: 1.4rem;
  color: var(--primary);
  margin-bottom: 4px;
}

.login-subtitle {
  color: var(--text2);
  font-size: 0.9rem;
}

/* === RELATORIO === */
.relatorio-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  margin-bottom: 20px;
}

.relatorio-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 16px;
}

.relatorio-section h3 {
  margin-bottom: 10px;
  font-size: 0.95rem;
  font-weight: 600;
}

/* === FOOTER === */
.footer {
  text-align: center;
  padding: 16px;
  color: var(--text-muted);
  font-size: 0.8rem;
  margin-top: 20px;
  border-top: 1px solid var(--border);
}

/* === ETIQUETAS === */
.etiquetas-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  margin-top: 8px;
}

.card-etiqueta {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

.card-etiqueta h3 { font-size: 1.05rem; margin-bottom: 6px; }
.card-etiqueta p { font-size: 0.82rem; color: var(--text2); margin-bottom: 14px; }

.etiqueta-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.etiqueta-form select, .etiqueta-form input {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 0.88rem;
  width: 100%;
  font-family: inherit;
}
.etiqueta-form select:focus, .etiqueta-form input:focus {
  outline: none;
  border-color: var(--primary);
}

/* === ALUNO INFO BOX === */
.aluno-info-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}

.aluno-info-header {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.aluno-info-header h3 { font-size: 1.1rem; }

/* === BACKUP === */
.backup-create-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}

.backup-create-box h3 { margin-bottom: 10px; font-size: 1rem; }

.backup-form {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  flex-wrap: wrap;
}

.backup-form input {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  background: var(--surface);
  color: var(--text);
  flex: 1;
  min-width: 150px;
}
.backup-form input:focus { outline: none; border-color: var(--primary); }

.backup-info code {
  background: var(--primary-light);
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 0.82rem;
  color: var(--primary);
}

.card-restore { max-width: 100%; }

/* === EMPTY STATE === */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}
.empty-state .empty-icon { font-size: 3rem; margin-bottom: 12px; }
.empty-state p { font-size: 0.9rem; }

/* === UTILITY === */
.flex-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.text-muted { color: var(--text-muted); }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.gap-1 { gap: 8px; }
.gap-2 { gap: 16px; }

/* Hide on small screens */
@media (max-width: 479px) { .hide-xs { display: none !important; } }

/* === PRINT === */
@media print {
  body { background: #fff !important; }
  .header, .footer, .btn, .no-print, .hamburger, .mobile-nav, .nav-overlay { display: none !important; }
  .container { max-width: 100%; padding: 0; margin: 0; }
  .table-scroll { border: none; box-shadow: none; overflow-x: visible; }
  .table { min-width: auto; }
  .table th { background: #f0f0f0 !important; color: #000 !important; }
  .table td, .table th { border-color: #ccc !important; color: #000 !important; }
  .badge { border: 1px solid #999 !important; }
  .card, .relatorio-section, .form-standard { box-shadow: none; border: 1px solid #ddd; }
}

/* === TABLET (>=600px) === */
@media (min-width: 600px) {
  .header { padding: 0 20px; }
  .header-title { max-width: none; font-size: 1.05rem; }
  .user-info { display: inline; }
  .container { padding: 20px; }
  .form-row { flex-direction: row; gap: 16px; }
  .form-standard { padding: 24px; }
  .etiquetas-grid { grid-template-columns: repeat(2, 1fr); }
  .relatorio-grid { grid-template-columns: 1fr; }
  .page-title { font-size: 1.5rem; }
  .page-header { flex-direction: row; align-items: center; }
  .cards-grid, .dashboard-cards { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
}

/* === DESKTOP (>=900px) === */
@media (min-width: 900px) {
  .hamburger { display: none; }
  .header-nav { display: flex !important; }
  .mobile-nav { display: none !important; }
  .nav-overlay { display: none !important; }
  .header { padding: 0 24px; }
  .container { padding: 24px; }
  .form-standard { padding: 28px; max-width: 700px; }
  .etiquetas-grid { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
  .relatorio-grid { grid-template-columns: 1fr 1fr; }
  .cards-grid, .dashboard-cards { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 16px; }
  .card { padding: 20px; }
  .card h3, .card .card-value { font-size: 2rem; }
}

/* === WIDE (>=1200px) === */
@media (min-width: 1200px) {
  .container { padding: 32px; }
  .dashboard-cards { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
  .relatorio-grid { gap: 24px; }
}

/* === MOBILE ONLY (<900px) === */
@media (max-width: 899px) {
  .header-nav { display: none; }
  .header-nav.mobile-open { display: flex; flex-direction: column; position: absolute; top: var(--header-height); left: 0; right: 0; background: var(--surface); border-bottom: 1px solid var(--border); padding: 8px; box-shadow: var(--shadow-lg); z-index: 999; }
  .header-nav.mobile-open a, .header-nav.mobile-open .dropbtn { padding: 12px 16px; font-size: 0.9rem; width: 100%; text-align: left; }
  .header-nav.mobile-open .dropdown { width: 100%; }
  .header-nav.mobile-open .dropdown-content { position: static; box-shadow: none; border: none; border-radius: 0; display: none; }
  .header-nav.mobile-open .dropdown:hover .dropdown-content, .header-nav.mobile-open .dropdown.open .dropdown-content { display: block; }
  .table td, .table th { padding: 8px 10px; font-size: 0.8rem; }
  .login-box { padding: 24px 20px; }
  .actions { flex-direction: column; gap: 4px; }
  .actions .btn-sm { width: 100%; justify-content: center; }
}
