:root {
  --navy-950: #091626;
  --navy-900: #10233e;
  --navy-800: #183452;
  --navy-700: #255070;
  --blue-600: #146b8c;
  --blue-100: #dceff4;
  --gold-500: #d8992f;
  --gold-100: #fff2d8;
  --ink: #172433;
  --muted: #667486;
  --line: #dce3e9;
  --surface: #ffffff;
  --canvas: #f3f6f8;
  --success: #167255;
  --danger: #b33b42;
  --warning: #906018;
  --shadow: 0 18px 50px rgba(16, 35, 62, 0.09);
  --radius: 16px;
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--canvas); }

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background: var(--canvas);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--blue-600); text-decoration: none; }
a:hover { color: var(--navy-900); }
button, input, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ============================================================
   ESTRUCTURA PRINCIPAL
   ============================================================ */

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 260px minmax(0, 1fr); }

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 28px 20px 20px;
  color: #fff;
  background: var(--navy-950);
  overflow-y: auto;
  z-index: 30;
}

.brand { display: flex; align-items: center; gap: 12px; color: #fff; padding: 0 8px; }
.brand:hover { color: #fff; }
.brand > span:last-child { display: flex; flex-direction: column; line-height: 1.05; }
.brand strong { font-size: 19px; letter-spacing: .02em; }
.brand small { margin-top: 4px; color: #a8c1d1; font-size: 11px; letter-spacing: .18em; text-transform: uppercase; }

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  color: var(--navy-950);
  background: var(--gold-500);
  font-size: 13px;
  font-weight: 900;
  letter-spacing: -.02em;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.2);
}

.brand-mark-large { width: 54px; height: 54px; border-radius: 15px; font-size: 16px; }
.main-nav { margin-top: 46px; display: grid; gap: 5px; }
.nav-label { margin: 18px 12px 7px; color: #738da2; font-size: 10px; font-weight: 800; letter-spacing: .16em; text-transform: uppercase; }
.main-nav a { padding: 11px 13px; border-radius: 10px; color: #b9cad7; font-weight: 650; transition: background .15s, color .15s; }
.main-nav a:hover { color: #fff; background: rgba(255,255,255,.06); }
.main-nav a[aria-current="page"] { color: #fff; background: var(--navy-800); box-shadow: inset 3px 0 0 var(--gold-500); }

.sidebar-footer { margin-top: auto; padding-top: 24px; border-top: 1px solid rgba(255,255,255,.1); }
.user-brief { display: flex; align-items: center; gap: 10px; margin: 0 6px 14px; }
.user-brief > span:last-child { display: grid; min-width: 0; }
.user-brief strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.user-brief small { color: #8ea7ba; font-size: 11px; }
.avatar { flex: 0 0 auto; width: 36px; height: 36px; display: grid; place-items: center; border-radius: 50%; color: #fff; background: var(--navy-700); font-weight: 800; }

.main-content { min-width: 0; padding: 42px clamp(24px, 4vw, 62px) 64px; }
.mobile-header { display: none; }
.surface { background: var(--surface); border: 1px solid rgba(20, 50, 76, .08); border-radius: var(--radius); box-shadow: var(--shadow); }

.page-heading { margin: 0 0 28px; }
.page-heading h1 { margin: 4px 0 7px; color: var(--navy-900); font-size: clamp(28px, 3vw, 40px); line-height: 1.12; letter-spacing: -.035em; }
.page-heading > p:last-child, .page-heading > div > p:last-child { max-width: 680px; margin: 0; color: var(--muted); }
.heading-actions { display: flex; align-items: end; justify-content: space-between; gap: 24px; }
.eyebrow { margin: 0; color: var(--gold-500); font-size: 11px; font-weight: 850; letter-spacing: .16em; text-transform: uppercase; }
.narrow-page { max-width: 720px; margin: 0 auto; }

/* ============================================================
   BOTONES Y FORMULARIOS
   ============================================================ */

.button { min-height: 40px; display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 9px 15px; border: 1px solid transparent; border-radius: 9px; cursor: pointer; font-weight: 750; line-height: 1.15; transition: transform .12s, box-shadow .12s, background .12s; }
.button:hover { transform: translateY(-1px); }
.button-primary { color: #fff; background: var(--navy-900); box-shadow: 0 8px 18px rgba(16,35,62,.16); }
.button-primary:hover { color: #fff; background: var(--navy-800); }
.button-secondary { color: var(--navy-900); background: #fff; border-color: var(--line); }
.button-secondary:hover { background: #f7fafb; }
.button-ghost { color: var(--muted); background: transparent; border-color: transparent; }
.sidebar .button-ghost { color: #b9cad7; border-color: rgba(255,255,255,.12); }
.button-danger { color: var(--danger); background: #fff5f5; border-color: #f1c8ca; }
.button-small { min-height: 34px; padding: 7px 10px; font-size: 12px; }
.button-large { min-height: 50px; }
.button-block { width: 100%; }
.button-row { display: flex; align-items: center; flex-wrap: wrap; gap: 9px; }

.form-card { padding: clamp(22px, 4vw, 36px); }
.field { margin-bottom: 20px; }
.field > label { display: block; margin: 0 0 7px; color: var(--navy-900); font-size: 13px; font-weight: 750; }
.field > small { display: block; margin-top: 6px; color: var(--muted); font-size: 12px; }
.form-control { width: 100%; min-height: 44px; padding: 10px 12px; color: var(--ink); background: #fff; border: 1px solid #cbd5de; border-radius: 9px; outline: none; transition: border .15s, box-shadow .15s; }
.form-control:focus { border-color: var(--blue-600); box-shadow: 0 0 0 3px rgba(20,107,140,.13); }
input[type="checkbox"].form-control { width: 18px; min-height: 18px; vertical-align: middle; }
.form-control-small { min-height: 34px; padding: 6px 8px; font-size: 12px; }
.field-error .form-control { border-color: var(--danger); }
.error-text { margin: 6px 0 0; color: var(--danger); font-size: 12px; }
.form-errors { margin: 0 0 18px; padding: 12px 14px; color: #8d252c; background: #fff0f0; border: 1px solid #f0c2c5; border-radius: 9px; }
.form-errors p, .form-errors ul { margin: 0; }
.form-actions { margin-top: 28px; display: flex; align-items: center; justify-content: flex-end; gap: 10px; }
.toolbar { padding: 18px; display: flex; gap: 12px; border-bottom: 1px solid var(--line); }
.toolbar-split { justify-content: space-between; }
.search-field { width: min(520px, 100%); display: flex; gap: 8px; }
.inline-form { display: flex; align-items: center; gap: 7px; }

/* ============================================================
   LOGIN
   ============================================================ */

.login-page { min-height: 100vh; display: grid; grid-template-columns: minmax(360px, .85fr) minmax(480px, 1.15fr); background: #fff; }
.login-panel { position: relative; min-height: 100vh; padding: clamp(36px, 6vw, 84px); display: flex; flex-direction: column; color: #fff; background: var(--navy-950); overflow: hidden; }
.login-panel::before { content: ""; position: absolute; width: 520px; height: 520px; right: -260px; top: -170px; border: 1px solid rgba(216,153,47,.26); border-radius: 50%; box-shadow: 0 0 0 80px rgba(255,255,255,.018), 0 0 0 160px rgba(255,255,255,.012); }
.login-panel::after { content: "@"; position: absolute; right: 7%; bottom: -17%; color: rgba(255,255,255,.025); font-family: Georgia, serif; font-size: 430px; font-weight: 800; line-height: 1; }
.login-brand { position: relative; z-index: 1; display: flex; align-items: center; gap: 13px; }
.login-brand > span:last-child { display: grid; line-height: 1; }
.login-brand strong { font-size: 22px; }
.login-brand small { margin-top: 5px; color: #a8c1d1; font-size: 11px; letter-spacing: .2em; text-transform: uppercase; }
.login-copy { position: relative; z-index: 1; margin: auto 0; max-width: 560px; }
.login-copy h1 { margin: 12px 0 22px; font-size: clamp(42px, 5vw, 70px); line-height: .98; letter-spacing: -.055em; }
.login-copy > p:last-child { max-width: 510px; color: #b9cad7; font-size: 17px; line-height: 1.7; }
.login-security { position: relative; z-index: 1; color: #8ea7ba; font-size: 12px; }
.login-security span { width: 22px; height: 22px; margin-right: 7px; display: inline-grid; place-items: center; color: var(--navy-950); background: var(--gold-500); border-radius: 50%; font-weight: 900; }
.login-form-wrap { display: grid; place-items: center; padding: 40px; background: linear-gradient(145deg, #fff 0%, #f4f7f9 100%); }
.login-card { width: min(440px, 100%); padding: 40px; background: #fff; border: 1px solid var(--line); border-radius: 20px; box-shadow: 0 30px 80px rgba(16,35,62,.12); }
.card-heading { margin-bottom: 28px; }
.card-heading h2 { margin: 5px 0 7px; color: var(--navy-900); font-size: 30px; letter-spacing: -.03em; }
.card-heading > p:last-child, .login-help { color: var(--muted); }
.login-help { margin: 20px 0 0; text-align: center; font-size: 12px; }

/* ============================================================
   MÉTRICAS, TABLAS Y ESTADOS
   ============================================================ */

.metric-grid { margin-bottom: 26px; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.metric-card { min-height: 152px; padding: 22px; display: flex; flex-direction: column; background: #fff; border: 1px solid rgba(20,50,76,.08); border-radius: 14px; box-shadow: var(--shadow); }
.metric-card > span { color: var(--muted); font-size: 12px; font-weight: 700; }
.metric-card > strong { margin: 10px 0 auto; color: var(--navy-900); font-size: 34px; line-height: 1; }
.metric-card > small { color: var(--muted); font-size: 11px; }
.metric-accent { color: #fff; background: var(--navy-900); }
.metric-accent > span, .metric-accent > small { color: #aec4d5; }
.metric-accent > strong { color: #fff; }
.status-word { font-size: 23px !important; }
.status-ok { color: var(--success) !important; }
.status-error { color: var(--danger) !important; }
.content-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.content-grid-wide { grid-template-columns: minmax(0, 1.25fr) minmax(320px, .75fr); }
.section-heading { min-height: 82px; padding: 19px 22px; display: flex; align-items: center; justify-content: space-between; gap: 20px; border-bottom: 1px solid var(--line); }
.section-heading h2 { margin: 2px 0 0; color: var(--navy-900); font-size: 19px; }
.section-heading > a { font-size: 12px; font-weight: 750; }
.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { padding: 12px 16px; color: #748191; background: #f8fafb; font-size: 10px; letter-spacing: .1em; text-align: left; text-transform: uppercase; white-space: nowrap; }
td { padding: 15px 16px; border-top: 1px solid #edf1f4; vertical-align: middle; }
td strong, td small { display: block; }
td small { margin-top: 3px; color: var(--muted); font-size: 11px; }
td code { color: var(--navy-800); font-family: "SFMono-Regular", Consolas, monospace; font-size: 12px; }
.table-actions { display: flex; align-items: center; justify-content: flex-end; gap: 5px; white-space: nowrap; }
.empty-cell { padding: 34px; color: var(--muted); text-align: center; }
.muted { color: var(--muted); }
.badge { display: inline-flex; align-items: center; padding: 4px 8px; border-radius: 999px; font-size: 10px; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; }
.badge-activo { color: #0d684d; background: #dcf5eb; }
.badge-inactivo { color: #75582a; background: #f7ebd5; }
.badge-error { color: #9b292f; background: #ffe1e3; }
.timeline { margin: 0; padding: 12px 20px 18px; list-style: none; }
.timeline li { position: relative; min-height: 52px; padding: 10px 0 10px 24px; border-left: 1px solid var(--line); }
.timeline-dot { position: absolute; left: -5px; top: 17px; width: 9px; height: 9px; background: var(--gold-500); border: 2px solid #fff; border-radius: 50%; box-shadow: 0 0 0 1px var(--gold-500); }
.timeline strong { color: var(--navy-900); font-size: 12px; }
.timeline p { margin: 2px 0 0; color: var(--muted); font-size: 11px; }

/* ============================================================
   NOTIFICACIONES Y CREDENCIALES
   ============================================================ */

.flash-stack { position: fixed; top: 18px; right: 24px; width: min(430px, calc(100vw - 36px)); display: grid; gap: 9px; z-index: 100; }
.flash { padding: 13px 14px; display: flex; align-items: center; justify-content: space-between; gap: 14px; color: var(--navy-900); background: #fff; border-left: 4px solid var(--blue-600); border-radius: 9px; box-shadow: 0 18px 45px rgba(16,35,62,.16); }
.flash-success { border-left-color: var(--success); }
.flash-error { border-left-color: var(--danger); }
.flash button { color: var(--muted); background: none; border: 0; cursor: pointer; font-size: 20px; }
.notice { margin-top: 18px; padding: 13px 15px; color: var(--navy-800); background: var(--blue-100); border-radius: 9px; font-size: 12px; }
.notice-warning { color: var(--warning); background: var(--gold-100); }
.credential-card { padding: 26px; }
.credential-row { display: grid; grid-template-columns: 145px minmax(0, 1fr) auto; align-items: center; gap: 14px; padding: 17px 0; border-bottom: 1px solid var(--line); }
.credential-row > span { color: var(--muted); font-size: 12px; font-weight: 700; }
.credential-row code { min-width: 0; overflow-wrap: anywhere; color: var(--navy-900); font-size: 14px; font-weight: 750; }
.copy-button { color: var(--blue-600); background: transparent; border: 0; cursor: pointer; font-size: 12px; font-weight: 800; }

/* ============================================================
   CORREO
   ============================================================ */

.mail-layout { display: grid; grid-template-columns: 245px minmax(0, 1fr); gap: 18px; align-items: start; }
.mail-nav { position: sticky; top: 28px; overflow: hidden; }
.mailbox-picker { padding: 18px; border-bottom: 1px solid var(--line); }
.mailbox-picker label { display: block; margin-bottom: 7px; color: var(--muted); font-size: 10px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }
.mail-nav nav { padding: 10px; display: grid; gap: 3px; }
.mail-nav nav a { padding: 10px 11px; display: flex; justify-content: space-between; color: var(--muted); border-radius: 8px; font-weight: 700; }
.mail-nav nav a:hover { color: var(--navy-900); background: #f4f7f9; }
.mail-nav nav a[aria-current="page"] { color: var(--navy-900); background: var(--gold-100); }
.mail-nav nav a strong { min-width: 23px; padding: 2px 6px; color: #fff; background: var(--navy-900); border-radius: 999px; font-size: 10px; text-align: center; }
.mailbox-note { margin: 10px; padding: 13px; background: #f5f8fa; border-radius: 10px; }
.mailbox-note strong { color: var(--navy-900); font-size: 12px; }
.mailbox-note p { margin: 4px 0 9px; color: var(--muted); font-size: 11px; }
.mailbox-note code { display: block; overflow-wrap: anywhere; color: var(--navy-800); font-size: 11px; }
.mailbox-note .copy-button { margin-top: 9px; padding: 0; }
.mail-main { min-height: 620px; overflow: hidden; }
.mail-heading { min-height: 105px; padding: 20px 24px; display: flex; align-items: end; justify-content: space-between; gap: 20px; border-bottom: 1px solid var(--line); }
.mail-heading h1 { margin: 2px 0; color: var(--navy-900); font-size: 25px; letter-spacing: -.03em; }
.mail-heading p:last-child { margin: 0; color: var(--muted); font-size: 11px; }
.mail-search { width: min(440px, 50%); display: flex; gap: 8px; }
.mail-search label { flex: 1; }
.message-row { border-bottom: 1px solid #edf1f4; transition: background .12s; }
.message-row:hover { background: #f8fafb; }
.message-link { min-height: 64px; padding: 13px 22px; display: grid; grid-template-columns: minmax(130px, .65fr) minmax(220px, 1.6fr) auto; align-items: center; gap: 18px; color: var(--ink); }
.message-sender, .message-subject { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.message-sender { color: var(--navy-800); font-weight: 650; }
.message-subject { color: #465464; }
.message-meta { color: #82909e; font-size: 11px; white-space: nowrap; }
.message-unread { background: #f2f8fa; box-shadow: inset 3px 0 0 var(--blue-600); }
.message-unread .message-sender, .message-unread .message-subject { color: var(--navy-900); font-weight: 800; }
.empty-list { padding: 90px 30px; color: var(--muted); text-align: center; }
.empty-list strong { display: block; color: var(--navy-900); font-size: 18px; }
.empty-list p { margin: 7px 0; }
.pagination { padding: 18px 22px; display: flex; align-items: center; justify-content: center; gap: 16px; }
.pagination span { color: var(--muted); font-size: 12px; }
.message-page { max-width: 1120px; margin: 0 auto; }
.message-toolbar { margin-bottom: 14px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.message-card { overflow: hidden; }
.message-card > header { padding: clamp(22px, 4vw, 38px); border-bottom: 1px solid var(--line); }
.message-card h1 { margin: 8px 0 24px; color: var(--navy-900); font-size: clamp(24px, 3vw, 35px); line-height: 1.18; letter-spacing: -.035em; }
.message-from { display: flex; align-items: center; gap: 11px; }
.message-from > div { min-width: 0; }
.message-from strong { color: var(--navy-900); }
.message-from p { margin: 1px 0 0; overflow-wrap: anywhere; color: var(--muted); font-size: 11px; }
.message-from time { margin-left: auto; color: var(--muted); font-size: 11px; white-space: nowrap; }
.message-body { padding: clamp(24px, 5vw, 54px); color: #263747; font-family: Georgia, "Times New Roman", serif; font-size: 16px; line-height: 1.8; overflow-wrap: anywhere; }
.safe-html img { display: none; }
.safe-html table { width: auto; max-width: 100%; }
.attachments { padding: 20px 30px 30px; border-top: 1px solid var(--line); }
.attachments h2 { margin: 0 0 13px; color: var(--navy-900); font-size: 15px; }
.attachment-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 10px; }
.attachment { padding: 13px; display: grid; color: var(--navy-900); background: #f7f9fa; border: 1px solid var(--line); border-radius: 9px; }
.attachment span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 750; }
.attachment small { color: var(--muted); }
.empty-state { max-width: 620px; margin: 8vh auto 0; padding: 54px; text-align: center; }
.empty-state h1 { margin: 7px 0; color: var(--navy-900); font-size: 29px; }
.empty-state p { margin: 0 auto 22px; color: var(--muted); }
.empty-icon { width: 70px; height: 70px; margin: 0 auto 20px; display: grid; place-items: center; color: var(--navy-900); background: var(--gold-100); border-radius: 22px; font-family: Georgia, serif; font-size: 35px; font-weight: 900; }

/* ============================================================
   RESPONSIVE
   ============================================================ */

@media (max-width: 1050px) {
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .content-grid-wide { grid-template-columns: 1fr; }
  .mail-layout { grid-template-columns: 210px minmax(0, 1fr); }
  .message-link { grid-template-columns: 130px minmax(190px, 1fr); }
  .message-meta { grid-column: 2; }
}

@media (max-width: 820px) {
  .app-shell { display: block; }
  .sidebar { position: fixed; left: 0; width: min(290px, 86vw); transform: translateX(-105%); transition: transform .2s; box-shadow: 20px 0 60px rgba(0,0,0,.2); }
  .sidebar.is-open { transform: translateX(0); }
  .main-content { padding: 24px 18px 44px; }
  .mobile-header { margin: -6px 0 25px; display: flex; align-items: center; gap: 13px; }
  .icon-button { padding: 8px 11px; color: var(--navy-900); background: #fff; border: 1px solid var(--line); border-radius: 8px; font-weight: 750; }
  .mobile-title { color: var(--navy-900); font-weight: 850; }
  .login-page { grid-template-columns: 1fr; }
  .login-panel { min-height: 320px; padding: 32px; }
  .login-copy { margin: 58px 0 30px; }
  .login-copy h1 { font-size: clamp(38px, 10vw, 58px); }
  .login-copy > p:last-child, .login-security { display: none; }
  .login-form-wrap { padding: 32px 18px 50px; }
  .login-card { margin-top: -62px; position: relative; z-index: 2; padding: 28px; }
  .mail-layout { grid-template-columns: 1fr; }
  .mail-nav { position: static; }
  .mail-nav nav { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .mail-nav nav a { justify-content: center; }
  .mail-nav nav a strong { display: none; }
  .mailbox-note { display: none; }
}

@media (max-width: 620px) {
  .heading-actions, .mail-heading, .message-toolbar { align-items: stretch; flex-direction: column; }
  .heading-actions .button-row, .heading-actions > .button { width: 100%; }
  .heading-actions .button { flex: 1; }
  .metric-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .metric-card { min-height: 130px; padding: 16px; }
  .metric-card > strong { font-size: 28px; }
  .toolbar, .toolbar-split, .search-field { width: 100%; align-items: stretch; flex-direction: column; }
  .mail-search { width: 100%; }
  .message-link { grid-template-columns: minmax(0, 1fr); gap: 3px; }
  .message-meta { grid-column: 1; }
  .message-from { align-items: flex-start; flex-wrap: wrap; }
  .message-from time { width: 100%; margin: 5px 0 0 47px; }
  .credential-row { grid-template-columns: 1fr auto; }
  .credential-row > span { grid-column: 1 / -1; }
  .table-actions { align-items: stretch; flex-direction: column; }
  .inline-form { min-width: 250px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}

