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

:root {
  --sidebar-w: 230px;
  --sidebar-bg: #0f172a;
  --sidebar-hover: #1e293b;
  --topbar-h: 60px;
  --primary: #0d9488;
  --primary-dark: #0f766e;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,.1), 0 4px 6px -2px rgba(0,0,0,.05);
}

body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; font-size: 14px; color: var(--text); background: var(--bg); }

#app { display: flex; min-height: 100vh; }

/* ── SIDEBAR ── */
#sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 18px 16px;
  border-bottom: 1px solid #1e293b;
}

.sidebar-logo {
  width: 100%;
  max-width: 190px;
  height: auto;
  background: #fff;
  border-radius: 10px;
  padding: 10px 12px;
}

.brand-icon {
  width: 38px; height: 38px;
  background: var(--primary);
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; color: #fff; font-size: 14px;
  flex-shrink: 0;
}

.brand-name { color: #fff; font-weight: 700; font-size: 17px; display: block; line-height: 1; }
.brand-sub { color: #64748b; font-size: 11px; display: block; margin-top: 3px; }

.sidebar-nav { padding: 12px 8px; flex: 1; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  color: #94a3b8;
  cursor: pointer;
  margin-bottom: 2px;
  transition: all .15s;
  font-size: 13.5px;
  font-weight: 500;
  text-decoration: none;
}

.nav-item svg { width: 18px; height: 18px; fill: currentColor; flex-shrink: 0; }
.nav-item:hover { background: var(--sidebar-hover); color: #e2e8f0; }
.nav-item.active { background: var(--primary); color: #fff; }

/* ── MAIN ── */
#main { margin-left: var(--sidebar-w); flex: 1; display: flex; flex-direction: column; }

#topbar {
  height: var(--topbar-h);
  background: var(--card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky; top: 0; z-index: 50;
  box-shadow: var(--shadow);
}

#page-title { font-size: 18px; font-weight: 600; color: var(--text); }
#topbar-actions { display: flex; gap: 8px; align-items: center; }
#content { padding: 24px; flex: 1; }

/* ── CARDS ── */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--border); }
.card-header { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.card-title { font-weight: 600; font-size: 15px; }
.card-body { padding: 20px; }

/* ── DASHBOARD STATS ── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card { background: var(--card); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); border: 1px solid var(--border); display: flex; align-items: center; gap: 16px; }
.stat-icon { width: 48px; height: 48px; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 22px; flex-shrink: 0; }
.stat-icon.teal { background: #f0fdfa; }
.stat-icon.blue { background: #eff6ff; }
.stat-icon.green { background: #f0fdf4; }
.stat-icon.yellow { background: #fffbeb; }
.stat-icon.purple { background: #faf5ff; }
.stat-value { font-size: 24px; font-weight: 700; line-height: 1; }
.stat-label { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* Variante grande (dashboard): tarjetas más amplias y ordenadas */
.stats-grid-lg { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 20px; }
.stats-grid-lg .stat-card { padding: 28px 26px; gap: 20px; }
.stats-grid-lg .stat-icon { width: 60px; height: 60px; border-radius: 15px; font-size: 28px; }
.stats-grid-lg .stat-value { font-size: 32px; }
.stats-grid-lg .stat-label { font-size: 13px; margin-top: 6px; }

/* ── TABLES ── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead { background: #f8fafc; }
th { padding: 10px 16px; text-align: left; font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 12px 16px; border-bottom: 1px solid var(--border); color: var(--text); }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #f8fafc; }

/* ── BUTTONS ── */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px; border-radius: 8px; border: none; font-size: 13px; font-weight: 500; cursor: pointer; transition: all .15s; text-decoration: none; white-space: nowrap; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #16a34a; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-ghost { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--bg); color: var(--text); }
.btn-sm { padding: 5px 10px; font-size: 12px; }

/* ── BADGES ── */
.badge { display: inline-flex; align-items: center; padding: 3px 8px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.badge-green { background: #dcfce7; color: #166534; }
.badge-red { background: #fee2e2; color: #991b1b; }
.badge-blue { background: #dbeafe; color: #1e40af; }
.badge-teal { background: #ccfbf1; color: #115e59; }
.badge-yellow { background: #fef9c3; color: #854d0e; }
.badge-gray { background: #f1f5f9; color: #475569; }
.badge-purple { background: #ede9fe; color: #5b21b6; }

/* ── FORMS ── */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid.cols-3 { grid-template-columns: 1fr 1fr 1fr; }
.form-full { grid-column: 1 / -1; }
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group label { font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
.form-group input, .form-group select, .form-group textarea {
  padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px;
  color: var(--text); background: #fff; transition: border-color .15s; outline: none; font-family: inherit;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(13,148,136,.12); }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); }
.field-hint { color: var(--text-muted); font-size: 12px; margin-top: 4px; }
.field-error { color: #991b1b; font-size: 12px; margin-top: 4px; }
input.input-invalid { border-color: #dc2626 !important; box-shadow: 0 0 0 3px rgba(239,68,68,.12) !important; }

/* ── MODAL ── */
#modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: flex; align-items: center; justify-content: center; z-index: 1000; padding: 16px; }
#modal-overlay.hidden { display: none; }
#modal { background: var(--card); border-radius: var(--radius); width: 100%; max-width: 620px; max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow-lg); }
#modal-header { display: flex; align-items: center; justify-content: space-between; padding: 20px 24px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--card); }
#modal-title { font-size: 16px; font-weight: 600; }
#modal-close { background: none; border: none; font-size: 18px; cursor: pointer; color: var(--text-muted); line-height: 1; width: 28px; height: 28px; display: flex; align-items: center; justify-content: center; border-radius: 4px; }
#modal-close:hover { background: var(--bg); }
#modal-body { padding: 24px; }

/* ── TOASTS ── */
#toasts { position: fixed; bottom: 24px; right: 24px; display: flex; flex-direction: column; gap: 8px; z-index: 2000; }
.toast { padding: 12px 16px; border-radius: 8px; color: #fff; font-size: 13px; font-weight: 500; box-shadow: var(--shadow-lg); animation: slideIn .2s ease; max-width: 320px; }
.toast-success { background: #16a34a; }
.toast-error { background: #dc2626; }
.toast-info { background: var(--primary); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ── EMPTY / LOADING ── */
.empty-state { text-align: center; padding: 48px 24px; color: var(--text-muted); }
.empty-state p { font-size: 14px; }
.loading { display: flex; align-items: center; justify-content: center; padding: 48px; }
.spinner { width: 32px; height: 32px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.hidden { display: none !important; }
.actions-cell { display: flex; gap: 6px; flex-wrap: wrap; }
.muted { color: var(--text-muted); }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar .form-group { gap: 0; }
.toolbar select { padding: 7px 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px; background: #fff; }

/* ── LOGIN ── */
.login-wrap { min-height: 100vh; background: linear-gradient(135deg, #0f172a 0%, #134e4a 100%); display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card { background: var(--card); border-radius: 16px; padding: 40px; width: 100%; max-width: 400px; box-shadow: var(--shadow-lg); }
.login-brand { display: flex; align-items: center; justify-content: center; margin-bottom: 28px; }
.login-logo { width: 100%; max-width: 260px; height: auto; }
.login-title { font-size: 16px; font-weight: 600; color: var(--text-muted); margin-bottom: 22px; text-align: center; }
.login-error { background: #fee2e2; color: #991b1b; border-radius: 8px; padding: 10px 14px; font-size: 13px; margin-top: 12px; }
.login-card .form-group { margin-bottom: 14px; }
