:root {
  --em-red: #c9151e;
  --em-red-dark: #991b1b;
  --em-red-soft: #fff1f2;
  --em-navy: #101827;
  --em-navy-2: #172033;
  --em-text: #172033;
  --em-muted: #64748b;
  --em-line: #e5e7eb;
  --em-bg: #f4f6f9;
  --em-card: #fff;
  --em-green: #15803d;
  --em-amber: #b45309;
  --em-blue: #1d4ed8;
  --em-shadow: 0 18px 44px rgba(15, 23, 42, .08);
}

* { box-sizing: border-box; }
html { font-size: 16px; }
body { margin: 0; font-family: "Poppins", system-ui, -apple-system, Segoe UI, sans-serif; color: var(--em-text); background: var(--em-bg); }
button, input, select, textarea { font: inherit; }
a { color: inherit; text-decoration: none; }
img { max-width: 100%; }

.em-admin-body { min-height: 100vh; }
.em-shell { min-height: 100vh; display: grid; grid-template-columns: 282px minmax(0, 1fr); }
.em-sidebar { position: sticky; top: 0; height: 100vh; overflow-y: auto; padding: 1.35rem 1.05rem; color: #e5e7eb; background: linear-gradient(180deg, #111827 0%, #0b1220 100%); box-shadow: 12px 0 32px rgba(15,23,42,.12); z-index: 40; }
.em-brand { display: flex; align-items: center; gap: .75rem; padding: .2rem .25rem 1.1rem; border-bottom: 1px solid rgba(255,255,255,.09); }
.em-brand img { width: 64px; height: 64px; object-fit: contain; filter: drop-shadow(0 8px 18px rgba(0,0,0,.22)); }
.em-brand strong, .em-brand span { display: block; }
.em-brand strong { color: #fff; font-size: 1.05rem; }
.em-brand span { color: #aeb8c7; font-size: .76rem; }
.em-user-pill { margin: 1rem 0; display: flex; gap: .65rem; align-items: center; padding: .7rem; border: 1px solid rgba(255,255,255,.09); border-radius: 16px; background: rgba(255,255,255,.05); }
.em-user-pill > span { width: 38px; height: 38px; flex: 0 0 38px; display: grid; place-items: center; border-radius: 12px; color: #fff; background: linear-gradient(135deg, #ef4444, #991b1b); font-weight: 800; }
.em-user-pill strong, .em-user-pill small { display: block; }
.em-user-pill strong { color: #fff; font-size: .78rem; line-height: 1.25; }
.em-user-pill small { color: #9ca3af; font-size: .7rem; margin-top: .15rem; }
.em-nav { display: grid; gap: .3rem; }
.em-nav a { display: flex; align-items: center; gap: .75rem; min-height: 44px; padding: .65rem .75rem; color: #bac3d1; border-radius: 13px; font-size: .86rem; font-weight: 600; transition: .18s ease; }
.em-nav a:hover { color: #fff; background: rgba(255,255,255,.07); transform: translateX(2px); }
.em-nav a.active { color: #fff; background: linear-gradient(135deg, #d91e28, #a7131b); box-shadow: 0 10px 24px rgba(185,28,28,.26); }
.em-nav-icon { width: 23px; height: 23px; display: grid; place-items: center; font-size: 1.12rem; font-weight: 700; }
.em-sidebar-footer { margin-top: 1.2rem; padding: 1rem .75rem .25rem; border-top: 1px solid rgba(255,255,255,.08); color: #8f9aac; font-size: .7rem; line-height: 1.55; text-align: center; }
.em-workspace { min-width: 0; }
.em-topbar { min-height: 108px; display: flex; align-items: center; gap: 1rem; padding: 1.15rem 2rem; background: rgba(255,255,255,.96); border-bottom: 1px solid var(--em-line); position: sticky; top: 0; z-index: 30; backdrop-filter: blur(12px); }
.em-topbar > div { flex: 1; }
.em-topbar h1 { margin: .06rem 0 0; font-size: clamp(1.35rem, 2.4vw, 2rem); line-height: 1.15; }
.em-eyebrow { margin: 0; color: var(--em-red); font-size: .71rem; text-transform: uppercase; letter-spacing: .12em; font-weight: 800; }
.em-subtitle { margin: .3rem 0 0; color: var(--em-muted); font-size: .86rem; }
.em-menu-button { display: none; width: 44px; height: 44px; border: 1px solid var(--em-line); border-radius: 12px; background: #fff; cursor: pointer; }
.em-main { padding: 1.65rem 2rem 2.5rem; max-width: 1640px; width: 100%; margin: 0 auto; }

.em-btn { border: 1px solid transparent; border-radius: 12px; min-height: 42px; padding: .65rem 1rem; display: inline-flex; justify-content: center; align-items: center; gap: .45rem; font-weight: 700; font-size: .83rem; cursor: pointer; transition: .18s ease; }
.em-btn:hover { transform: translateY(-1px); }
.em-btn-primary { color: #fff; background: linear-gradient(135deg, #d51c26, #a91018); box-shadow: 0 9px 22px rgba(185,28,28,.2); }
.em-btn-outline { color: #334155; background: #fff; border-color: #d8dee8; }
.em-btn-soft { color: var(--em-red-dark); background: var(--em-red-soft); border-color: #fecdd3; }
.em-btn-danger { color: #fff; background: #991b1b; }
.em-btn-sm { min-height: 34px; padding: .45rem .7rem; border-radius: 9px; font-size: .76rem; }
.em-actions { display: flex; flex-wrap: wrap; gap: .55rem; align-items: center; }

.em-alert { margin-bottom: 1rem; padding: .85rem 1rem; border-radius: 13px; border: 1px solid; font-size: .86rem; font-weight: 600; }
.em-alert-success { color: #166534; background: #f0fdf4; border-color: #bbf7d0; }
.em-alert-error { color: #991b1b; background: #fff1f2; border-color: #fecdd3; }
.em-alert-warning { color: #92400e; background: #fffbeb; border-color: #fde68a; }

.em-card { background: var(--em-card); border: 1px solid rgba(15,23,42,.07); border-radius: 21px; box-shadow: var(--em-shadow); }
.em-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; padding: 1.15rem 1.25rem; border-bottom: 1px solid var(--em-line); }
.em-card-head h2, .em-card-head h3 { margin: 0; font-size: 1rem; }
.em-card-head p { margin: .28rem 0 0; color: var(--em-muted); font-size: .78rem; }
.em-card-body { padding: 1.25rem; }
.em-section-space { margin-top: 1.15rem; }
.em-grid { display: grid; gap: 1rem; }
.em-grid-2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.em-grid-3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.em-grid-4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
.em-grid-5 { grid-template-columns: repeat(5, minmax(0,1fr)); }

.em-kpi { position: relative; padding: 1.1rem 1.15rem; min-height: 132px; overflow: hidden; }
.em-kpi::after { content: ""; position: absolute; width: 92px; height: 92px; right: -30px; bottom: -38px; border-radius: 50%; background: var(--kpi-color, #dc2626); opacity: .09; }
.em-kpi-top { display: flex; justify-content: space-between; align-items: center; }
.em-kpi-label { color: var(--em-muted); font-size: .76rem; font-weight: 600; }
.em-kpi-icon { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 11px; color: var(--kpi-color, var(--em-red)); background: color-mix(in srgb, var(--kpi-color, var(--em-red)) 12%, white); font-weight: 800; }
.em-kpi strong { display: block; margin-top: .6rem; font-size: 2rem; line-height: 1; }
.em-kpi small { display: block; color: var(--em-muted); margin-top: .45rem; font-size: .69rem; }

.em-table-wrap { overflow-x: auto; }
.em-table { width: 100%; border-collapse: collapse; font-size: .79rem; }
.em-table th { padding: .75rem .7rem; color: #475569; background: #f8fafc; text-align: left; font-size: .69rem; letter-spacing: .04em; text-transform: uppercase; border-bottom: 1px solid var(--em-line); white-space: nowrap; }
.em-table td { padding: .78rem .7rem; border-bottom: 1px solid #edf0f4; vertical-align: middle; }
.em-table tr:last-child td { border-bottom: 0; }
.em-table tbody tr:hover { background: #fbfcfd; }
.em-table .em-number { font-weight: 800; color: #111827; }
.em-table .em-muted-cell { color: var(--em-muted); font-size: .72rem; }

.em-status { display: inline-flex; align-items: center; min-height: 28px; padding: .3rem .62rem; border-radius: 999px; font-weight: 700; font-size: .68rem; white-space: nowrap; }
.em-status-borrador { color: #475569; background: #f1f5f9; }
.em-status-pendiente { color: #92400e; background: #fef3c7; }
.em-status-observado { color: #9a3412; background: #ffedd5; }
.em-status-aprobado { color: #166534; background: #dcfce7; }
.em-status-anulado { color: #991b1b; background: #fee2e2; }

.em-filter-bar { display: grid; grid-template-columns: repeat(5, minmax(0,1fr)) auto; gap: .75rem; align-items: end; }
.em-field { display: grid; gap: .35rem; }
.em-field > span, .em-field > label, .em-label { color: #334155; font-size: .72rem; font-weight: 700; }
.em-input, .em-select, .em-textarea { width: 100%; border: 1px solid #d9dee7; border-radius: 12px; background: #fff; color: #172033; outline: none; transition: .18s ease; }
.em-input, .em-select { min-height: 44px; padding: .62rem .72rem; }
.em-textarea { min-height: 118px; padding: .75rem; resize: vertical; line-height: 1.55; }
.em-input:focus, .em-select:focus, .em-textarea:focus { border-color: #e05259; box-shadow: 0 0 0 3px rgba(220,38,38,.1); }
.em-input[readonly] { background: #f8fafc; color: #64748b; }
.em-form-grid { display: grid; grid-template-columns: repeat(12, minmax(0,1fr)); gap: .85rem; }
.em-col-12 { grid-column: span 12; }
.em-col-8 { grid-column: span 8; }
.em-col-6 { grid-column: span 6; }
.em-col-4 { grid-column: span 4; }
.em-col-3 { grid-column: span 3; }
.em-col-2 { grid-column: span 2; }
.em-required::after { content: " *"; color: var(--em-red); }
.em-help { margin: .25rem 0 0; color: var(--em-muted); font-size: .69rem; }

.em-stepper { display: flex; overflow-x: auto; gap: .4rem; padding: .4rem; margin-bottom: 1rem; border-radius: 16px; background: #e9edf3; }
.em-step-button { flex: 1 0 auto; min-width: 122px; border: 0; border-radius: 12px; padding: .75rem .85rem; background: transparent; color: #64748b; font-size: .73rem; font-weight: 700; cursor: pointer; }
.em-step-button.active { color: #fff; background: linear-gradient(135deg, #cf1822, #a81118); box-shadow: 0 8px 18px rgba(185,28,28,.2); }
.em-form-step { display: none; }
.em-form-step.active { display: block; animation: emFade .2s ease; }
@keyframes emFade { from { opacity: .3; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.em-step-actions { display: flex; justify-content: space-between; flex-wrap: wrap; gap: .65rem; padding-top: 1rem; margin-top: 1rem; border-top: 1px solid var(--em-line); }

.em-choice-grid { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: .65rem; }
.em-choice-card { display: block; position: relative; }
.em-choice-card > input { position: absolute; opacity: 0; pointer-events: none; }
.em-choice-content { min-height: 100%; display: grid; gap: .55rem; padding: .75rem; border: 1px solid #dce1e9; border-radius: 14px; background: #fff; cursor: pointer; transition: .16s ease; }
.em-choice-content strong { font-size: .77rem; line-height: 1.35; }
.em-choice-content small { color: var(--em-muted); font-size: .67rem; }
.em-choice-card > input:checked + .em-choice-content { border-color: var(--em-red); background: var(--em-red-soft); box-shadow: 0 0 0 2px rgba(220,38,38,.08); }
.em-choice-extra { display: grid; grid-template-columns: 1fr 1fr; gap: .4rem; }
.em-choice-extra .em-select { min-height: 36px; padding: .4rem .5rem; font-size: .68rem; }

.em-repeat-list { display: grid; gap: .65rem; }
.em-repeat-row { display: grid; grid-template-columns: 1.5fr 1fr .75fr .7fr auto; gap: .55rem; align-items: end; padding: .7rem; border: 1px solid var(--em-line); border-radius: 14px; background: #fbfcfd; }
.em-repeat-row.em-affected-row { grid-template-columns: 1.25fr .75fr .5fr .6fr 1fr 1fr auto; }
.em-repeat-row.em-support-row { grid-template-columns: 1fr 1fr 1fr auto; }
.em-remove-row { width: 40px; height: 40px; border: 0; border-radius: 10px; color: #991b1b; background: #fee2e2; cursor: pointer; }

.em-bar-list { display: grid; gap: .78rem; }
.em-bar-label { display: flex; justify-content: space-between; gap: 1rem; margin-bottom: .28rem; font-size: .74rem; }
.em-bar-label span { color: #475569; }
.em-bar-label strong { color: #111827; }
.em-bar-track { height: 9px; border-radius: 999px; background: #edf1f5; overflow: hidden; }
.em-bar-fill { height: 100%; border-radius: inherit; background: linear-gradient(90deg, #e12a33, #a50f18); }
.em-month-chart { height: 235px; display: grid; grid-template-columns: repeat(12, minmax(24px,1fr)); align-items: end; gap: .45rem; padding-top: .5rem; }
.em-month-column { height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: .35rem; }
.em-month-column strong { font-size: .66rem; }
.em-month-bar { width: min(30px, 85%); min-height: 3px; border-radius: 8px 8px 3px 3px; background: linear-gradient(180deg, #ef4444, #a30d16); box-shadow: 0 7px 15px rgba(185,28,28,.18); }
.em-month-column span { color: var(--em-muted); font-size: .61rem; }

.em-detail-grid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: .75rem; }
.em-detail-item { padding: .75rem; border: 1px solid var(--em-line); border-radius: 13px; background: #fbfcfd; }
.em-detail-item span { display: block; color: var(--em-muted); font-size: .66rem; text-transform: uppercase; letter-spacing: .04em; font-weight: 700; }
.em-detail-item strong { display: block; margin-top: .25rem; font-size: .79rem; overflow-wrap: anywhere; }
.em-prose { line-height: 1.7; color: #334155; font-size: .85rem; white-space: pre-line; }
.em-photo-grid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: .75rem; }
.em-photo { overflow: hidden; border-radius: 15px; border: 1px solid var(--em-line); background: #fff; }
.em-photo img { display: block; width: 100%; height: 220px; object-fit: cover; }
.em-photo p { margin: 0; padding: .65rem .75rem; color: var(--em-muted); font-size: .7rem; }
.em-role-lock { min-height: 42px; display: flex; align-items: center; padding: .55rem .75rem; border: 1px solid #fecaca; border-radius: 11px; color: #991b1b; background: #fff5f5; font-size: .72rem; font-weight: 800; }

.em-empty { min-height: 220px; display: grid; place-items: center; align-content: center; gap: .4rem; padding: 2rem; text-align: center; color: var(--em-muted); }
.em-empty > span { width: 52px; height: 52px; display: grid; place-items: center; border-radius: 16px; background: #f1f5f9; font-size: 1.5rem; }
.em-empty h3 { margin: .25rem 0 0; color: #334155; font-size: 1rem; }
.em-empty p { margin: 0; font-size: .76rem; }

.em-login-page { min-height: 100vh; display: grid; grid-template-columns: 1.05fr .95fr; background: #fff; }
.em-login-brand { min-height: 100vh; padding: 3rem; display: flex; flex-direction: column; justify-content: space-between; color: #fff; background: radial-gradient(circle at 20% 15%, rgba(239,68,68,.22), transparent 34%), linear-gradient(145deg, #172033, #090f1b); }
.em-login-brand img { width: 132px; height: 132px; object-fit: contain; }
.em-login-brand h1 { max-width: 680px; margin: 1rem 0 .6rem; font-size: clamp(2rem, 4.6vw, 4.4rem); line-height: 1.03; }
.em-login-brand p { max-width: 540px; color: #bdc6d4; font-size: 1rem; line-height: 1.65; }
.em-login-brand small { color: #8b97a9; }
.em-login-panel { display: grid; place-items: center; padding: 2rem; background: #f7f8fa; }
.em-login-card { width: min(450px, 100%); padding: 2rem; }
.em-login-card .em-mobile-logo { display: none; width: 90px; margin: 0 auto 1rem; }
.em-login-card h2 { margin: 0; font-size: 1.65rem; }
.em-login-card > p { margin: .45rem 0 1.3rem; color: var(--em-muted); font-size: .82rem; }
.em-login-card form { display: grid; gap: .85rem; }
.em-login-card .em-btn { width: 100%; margin-top: .25rem; }

.em-install-page { min-height: 100vh; padding: 2rem; background: linear-gradient(145deg, #111827, #1e293b); }
.em-install-wrap { width: min(1000px, 100%); margin: 0 auto; }
.em-install-head { color: #fff; text-align: center; margin-bottom: 1.2rem; }
.em-install-head img { width: 100px; }
.em-install-head h1 { margin: .65rem 0 .25rem; }
.em-install-head p { margin: 0; color: #cbd5e1; }
.em-install-card { padding: 1.3rem; }

.em-sidebar-backdrop { display: none; }
.em-search-highlight { color: var(--em-red-dark); font-weight: 800; }
.em-checkbox-line { display: flex; align-items: center; gap: .45rem; min-height: 42px; }
.em-checkbox-line input { width: 18px; height: 18px; accent-color: var(--em-red); }
.em-note { padding: .75rem; border-left: 4px solid var(--em-red); border-radius: 8px; background: #fff5f5; color: #7f1d1d; font-size: .75rem; line-height: 1.55; }
.em-pager { display: flex; justify-content: flex-end; gap: .4rem; padding: 1rem 0 0; }
.em-pager a { min-width: 38px; height: 38px; display: grid; place-items: center; border: 1px solid var(--em-line); border-radius: 10px; background: #fff; font-size: .75rem; font-weight: 700; }
.em-pager a.active { color: #fff; background: var(--em-red); border-color: var(--em-red); }

@media (max-width: 1180px) {
  .em-grid-5, .em-grid-4 { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .em-filter-bar { grid-template-columns: repeat(3, minmax(0,1fr)); }
  .em-choice-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .em-detail-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .em-photo-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
}

@media (max-width: 900px) {
  .em-shell { grid-template-columns: 1fr; }
  .em-sidebar { position: fixed; left: 0; top: 0; width: 282px; transform: translateX(-104%); transition: transform .2s ease; }
  body.em-menu-open .em-sidebar { transform: none; }
  .em-sidebar-backdrop { position: fixed; inset: 0; background: rgba(15,23,42,.55); z-index: 35; }
  body.em-menu-open .em-sidebar-backdrop { display: block; }
  .em-menu-button { display: grid; place-items: center; flex: 0 0 auto; }
  .em-main { padding: 1.2rem; }
  .em-topbar { padding: 1rem 1.2rem; }
  .em-top-action { display: none; }
  .em-grid-3 { grid-template-columns: 1fr; }
  .em-repeat-row, .em-repeat-row.em-affected-row, .em-repeat-row.em-support-row { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .em-remove-row { align-self: end; }
}

@media (max-width: 680px) {
  .em-topbar { min-height: 86px; }
  .em-eyebrow { display: none; }
  .em-grid-2, .em-grid-4, .em-grid-5, .em-filter-bar, .em-choice-grid, .em-detail-grid, .em-photo-grid { grid-template-columns: 1fr; }
  .em-form-grid { grid-template-columns: 1fr; }
  [class*="em-col-"] { grid-column: auto; }
  .em-repeat-row, .em-repeat-row.em-affected-row, .em-repeat-row.em-support-row { grid-template-columns: 1fr; }
  .em-month-chart { gap: .2rem; }
  .em-month-column span { writing-mode: vertical-rl; transform: rotate(180deg); height: 36px; }
  .em-login-page { grid-template-columns: 1fr; }
  .em-login-brand { display: none; }
  .em-login-card .em-mobile-logo { display: block; }
  .em-login-panel { min-height: 100vh; padding: 1rem; }
  .em-login-card { padding: 1.25rem; }
  .em-install-page { padding: 1rem; }
}

@media print {
  .em-sidebar, .em-topbar, .em-actions, .em-btn, .em-sidebar-backdrop { display: none !important; }
  .em-shell { display: block; }
  .em-main { padding: 0; }
  .em-card { box-shadow: none; border-color: #bbb; break-inside: avoid; }
}
