:root {
  --teal: #00a3a3;
  --teal-dark: #006f73;
  --cyan: #11bfc5;
  --orange: #f57412;
  --ink: #172128;
  --muted: #62717a;
  --line: #d7e2e5;
  --soft: #edf7f7;
  --mist: #f5f9f9;
  --danger: #b42318;
  --white: #ffffff;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body { margin: 0; color: var(--ink); background: #eef3f2; font-family: "Segoe UI", Arial, sans-serif; letter-spacing: 0; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

.auth-shell { --auth-accent: var(--teal); min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: clamp(24px, 5vw, 72px); background: #eef3f2; box-shadow: inset 0 5px 0 var(--auth-accent); }
.auth-panel { width: min(480px, 100%); min-width: 0; padding: clamp(26px, 4vw, 38px); background: var(--white); border: 1px solid #cfdbd8; border-radius: 8px; box-shadow: 0 24px 56px rgba(23, 33, 40, 0.12); }
.home-link { display: inline-flex; align-items: center; gap: 8px; margin-top: 20px; color: var(--teal-dark); font-size: 13px; font-weight: 750; text-decoration: none; }
.home-link::before { content: "\2190"; font-size: 18px; line-height: 1; }
.home-link:hover { color: var(--ink); }
.auth-brand { display: flex; align-items: center; gap: 13px; margin-bottom: 28px; }
.auth-brand-icon { flex: 0 0 auto; width: 54px; height: 54px; object-fit: cover; border: 1px solid #d8e2df; border-radius: 8px; }
.auth-brand-copy { display: grid; gap: 3px; min-width: 0; }
.auth-brand-copy strong { color: var(--ink); font-size: 20px; line-height: 1.1; }
.auth-brand-copy span { color: var(--teal-dark); font-size: 12px; font-weight: 700; line-height: 1.3; }
.auth-panel h1 { margin: 0 0 10px; font-size: 32px; line-height: 1.15; }
.auth-subtitle { margin: 0 0 28px; color: var(--muted); line-height: 1.55; }
.field { display: grid; gap: 7px; margin-bottom: 16px; }
.field label { color: #42525b; font-size: 13px; font-weight: 700; }
.field input, .field select, .field textarea { width: 100%; min-height: 46px; padding: 10px 12px; color: var(--ink); background: var(--white); border: 1px solid #bfcbd0; border-radius: 5px; outline: none; }
.field textarea { min-height: 92px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(0, 163, 163, 0.12); }
.primary, .secondary, .danger, .link-button { min-height: 42px; padding: 10px 16px; border-radius: 5px; font-weight: 750; }
.primary { color: var(--white); background: var(--teal-dark); border: 1px solid var(--teal-dark); }
.primary:hover { background: #00595b; }
.secondary { color: var(--ink); background: var(--white); border: 1px solid #aebdc3; }
.secondary:hover { border-color: var(--teal); }
.danger { color: var(--danger); background: var(--white); border: 1px solid #e3aaa4; }
.link-button { padding-inline: 0; color: var(--teal-dark); background: transparent; border: 0; }
.auth-actions { display: grid; gap: 12px; }
.auth-panel form { min-width: 0; width: 100%; }
.auth-panel form > .primary { width: 100%; min-height: 48px; }
.auth-panel form > .link-button { display: block; margin-top: 7px; }
.message { min-height: 22px; margin: 12px 0; color: var(--danger); font-size: 13px; }
.message.success { color: #087443; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 246px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 22px 16px; color: var(--ink); background: var(--white); border-top: 5px solid var(--teal); border-right: 1px solid var(--line); box-shadow: 8px 0 24px rgba(23, 33, 40, 0.04); }
.sidebar-brand { width: 188px; height: 46px; }
.sidebar-brand img { width: 100%; height: 100%; object-fit: contain; object-position: left center; }
.sidebar-brand img:last-child { display: none; }
.account { margin: 30px 0 22px; padding: 15px; background: var(--soft); border: 1px solid #d0e6e6; border-radius: 6px; }
.account strong, .account span { display: block; overflow: hidden; text-overflow: ellipsis; }
.account strong { font-size: 14px; }
.account span { margin-top: 5px; color: var(--teal-dark); font-size: 12px; font-weight: 700; }
.nav { display: grid; gap: 5px; }
.nav button { position: relative; width: 100%; min-height: 42px; padding: 10px 12px 10px 24px; color: #4c5d65; text-align: left; background: transparent; border: 0; border-radius: 5px; font-weight: 650; }
.nav button::before { content: ""; position: absolute; top: 50%; left: 10px; width: 6px; height: 6px; background: #bac8cc; border-radius: 50%; transform: translateY(-50%); }
.nav button:hover { color: var(--teal-dark); background: var(--mist); }
.nav button.active { color: var(--white); background: var(--teal-dark); }
.nav button.active::before { background: #8ee4e4; }
.sidebar-footer { position: absolute; right: 16px; bottom: 20px; left: 16px; }
.sidebar-footer button { width: 100%; color: #42525b; background: var(--white); border: 1px solid #b8c5ca; }
.workspace { min-width: 0; padding: 0 clamp(18px, 3vw, 42px) 42px; }
.topbar { min-height: 86px; display: flex; align-items: center; justify-content: space-between; gap: 18px; border-bottom: 1px solid var(--line); }
.topbar h1 { margin: 0; font-size: 25px; }
.toolbar { display: flex; align-items: center; gap: 10px; }
.content { padding-top: 26px; }
.metrics { display: grid; grid-template-columns: repeat(5, minmax(130px, 1fr)); gap: 12px; margin-bottom: 28px; }
.metric { min-width: 0; min-height: 106px; padding: 17px; background: var(--white); border: 1px solid var(--line); border-top: 4px solid var(--teal); border-radius: 6px; box-shadow: 0 8px 24px rgba(23, 33, 40, 0.04); }
.metric:nth-child(2n) { border-top-color: var(--cyan); }
.metric:nth-child(3n) { border-top-color: var(--orange); }
.metric span { display: block; color: var(--muted); font-size: 12px; font-weight: 650; }
.metric strong { display: block; margin-top: 10px; color: var(--ink); font-size: 28px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 12px; }
.section-head h2 { margin: 0; font-size: 19px; }
.table-wrap { overflow: auto; background: var(--white); border: 1px solid var(--line); border-radius: 6px; box-shadow: 0 12px 30px rgba(23, 33, 40, 0.04); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { min-width: 120px; padding: 12px; text-align: left; border-bottom: 1px solid #e2e9ec; vertical-align: middle; }
th { color: #42525b; background: var(--mist); font-size: 12px; white-space: nowrap; }
tbody tr:hover { background: #f7fbfb; }
.status { display: inline-block; padding: 4px 8px; color: #06633c; background: #e8f7ef; border-radius: 4px; font-size: 11px; font-weight: 700; }
.status.suspendido, .status.revocada { color: #8a4411; background: #fff1e5; }
.status.baja { color: #9b241a; background: #feecea; }
.empty { padding: 38px 18px; color: var(--muted); text-align: center; }

dialog { width: min(560px, calc(100vw - 32px)); padding: 0; border: 0; border-top: 4px solid var(--teal); border-radius: 7px; box-shadow: 0 22px 60px rgba(15, 28, 34, 0.25); }
dialog::backdrop { background: rgba(10, 23, 28, 0.55); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--line); }
.dialog-head h2 { margin: 0; font-size: 19px; }
.dialog-head button { width: 36px; height: 36px; padding: 0; color: var(--muted); background: transparent; border: 0; font-size: 24px; }
.dialog-body { max-height: 68vh; overflow: auto; padding: 20px 22px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 22px; background: var(--soft); border-top: 1px solid var(--line); }

body[data-portal-mode="control"] .sidebar { border-top-color: var(--orange); }
body[data-portal-mode="control"] .auth-shell { --auth-accent: var(--orange); }
body[data-portal-mode="control"] .nav button.active,
body[data-portal-mode="control"] .primary { background: var(--orange); border-color: var(--orange); }
body[data-portal-mode="control"] .primary:hover { background: #d85e08; }

@media (max-width: 980px) {
  .metrics { grid-template-columns: repeat(2, minmax(130px, 1fr)); }
  .app-shell { grid-template-columns: 205px minmax(0, 1fr); }
  .sidebar-brand { width: 170px; }
}

@media (max-width: 720px) {
  .auth-shell { padding: 20px; }
  .auth-panel { padding: 28px 24px; }
  .auth-brand { margin-bottom: 24px; }
  .auth-panel h1 { font-size: 28px; }
  .app-shell { display: block; }
  .sidebar { position: sticky; top: 0; z-index: 20; width: 100%; height: auto; display: grid; grid-template-columns: 44px minmax(0, 1fr) auto; grid-template-areas: "logo account logout" "nav nav nav"; align-items: center; gap: 9px 11px; padding: 8px 12px; border-top-width: 4px; border-right: 0; border-bottom: 1px solid var(--line); box-shadow: 0 5px 18px rgba(23, 33, 40, 0.1); }
  .sidebar-brand { grid-area: logo; width: 42px; height: 42px; }
  .sidebar-brand img:first-child { display: none; }
  .sidebar-brand img:last-child { display: block; border: 1px solid #dce6e8; border-radius: 5px; }
  .account { grid-area: account; min-width: 0; margin: 0; padding: 0; background: transparent; border: 0; }
  .account strong { font-size: 13px; white-space: nowrap; }
  .account span { margin-top: 2px; font-size: 10px; }
  .nav { grid-area: nav; display: flex; gap: 5px; overflow-x: auto; padding-top: 7px; border-top: 1px solid var(--line); scrollbar-width: none; }
  .nav::-webkit-scrollbar { display: none; }
  .nav button { flex: 0 0 auto; width: auto; min-height: 32px; padding: 6px 10px; text-align: center; white-space: nowrap; font-size: 12px; }
  .nav button::before { display: none; }
  .sidebar-footer { grid-area: logout; position: static; margin: 0; }
  .sidebar-footer button { width: auto; min-height: 34px; padding: 6px 9px; white-space: nowrap; font-size: 12px; }
  .workspace { padding: 0 12px 28px; }
  .topbar { min-height: 62px; gap: 10px; }
  .topbar h1 { max-width: 55%; font-size: 18px; line-height: 1.15; }
  .toolbar .secondary { min-height: 36px; padding: 7px 9px; font-size: 11px; }
  .content { padding-top: 15px; }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-bottom: 20px; }
  .metric { min-height: 78px; padding: 11px; border-top-width: 3px; }
  .metric strong { margin-top: 4px; font-size: 22px; }
  .section-head { margin-bottom: 9px; }
  .section-head h2 { font-size: 17px; }
}

@media (max-width: 390px) {
  .auth-shell { padding: 14px; }
  .auth-panel { padding: 24px 20px; }
  .auth-brand-icon { width: 48px; height: 48px; }
  .auth-brand-copy strong { font-size: 18px; }
  .auth-panel h1 { font-size: 26px; }
  .sidebar { grid-template-columns: 40px minmax(0, 1fr) auto; padding-inline: 9px; }
  .sidebar-brand { width: 38px; height: 38px; }
  .account strong { font-size: 12px; }
  .sidebar-footer button { padding-inline: 7px; font-size: 11px; }
  .topbar { align-items: flex-start; padding: 13px 0; }
  .topbar h1 { max-width: 50%; }
}
