:root {
  --bg: #f0f2f5;
  --bg-card: #ffffff;
  --bg-soft: #e8f0fe;
  --sidebar-bg: #ffffff;
  --border: #dadce0;
  --text: #202124;
  --muted: #5f6368;
  --accent: #1a73e8;
  --accent-hover: #1557b0;
  --accent-2: #00897b;
  --accent-soft: #e8f0fe;
  --danger: #c5221f;
  --danger-soft: #fce8e6;
  --ok: #137333;
  --ok-soft: #e6f4ea;
  --warn: #b06000;
  --warn-soft: #fef7e0;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(60, 64, 67, 0.12);
  --shadow-sm: 0 1px 2px rgba(60, 64, 67, 0.08);
  --font: "Plus Jakarta Sans", "Nunito", system-ui, sans-serif;
  --sidebar-width: 360px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  line-height: 1.55;
}

a {
  color: var(--accent-2);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* ——— App shell (WhatsApp / Gmail izquierda) ——— */
.app-body {
  overflow: hidden;
  height: 100%;
}

.app-shell {
  display: flex;
  flex-direction: row;
  height: 100vh;
  max-width: 100%;
}

.app-sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.app-sidebar__head {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.app-sidebar__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1rem;
  color: var(--text);
}

.app-sidebar__brand:hover {
  color: var(--accent);
  text-decoration: none;
}

.app-sidebar__brand-icon {
  font-size: 1.2rem;
}

.app-sidebar__brand-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-sidebar__compose {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 12px 16px;
  padding: 12px;
  border-radius: 24px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  color: var(--text);
  font-weight: 600;
  font-size: 0.92rem;
}

.app-sidebar__compose:hover {
  background: var(--bg-soft);
  text-decoration: none;
  box-shadow: var(--shadow);
}

.app-sidebar__search {
  padding: 0 12px 8px;
}

.app-sidebar__search input {
  border-radius: 24px;
  background: var(--bg);
  border: none;
  padding: 10px 16px;
  font-size: 0.9rem;
}

.app-chat-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0;
}

.app-chat-list__label {
  padding: 10px 16px 4px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--muted);
  letter-spacing: 0.05em;
}

.app-chat-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  color: var(--text);
  border-left: 3px solid transparent;
}

.app-chat-item:hover {
  background: #f1f3f4;
  text-decoration: none;
}

.app-chat-item.is-active {
  background: var(--accent-soft);
  border-left-color: var(--accent);
}

.app-chat-item--muted {
  opacity: 0.75;
}

.app-chat-item__avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 1.1rem;
  flex-shrink: 0;
}

.app-chat-item__body {
  flex: 1;
  min-width: 0;
}

.app-chat-item__top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.app-chat-item__name {
  font-size: 0.95rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-chat-item__badge {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 2px 8px;
  border-radius: 999px;
  flex-shrink: 0;
}

.app-chat-item__preview {
  display: block;
  font-size: 0.82rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-top: 2px;
}

.app-sidebar__portales {
  padding: 10px 12px;
  border-top: 1px solid var(--border);
}

.app-sidebar__portales-title {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 8px;
  text-transform: uppercase;
}

.app-sidebar__portales-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.app-sidebar__portal-btn {
  display: block;
  padding: 2px;
  border-radius: 10px;
}

.app-sidebar__portal-btn:hover {
  background: var(--bg);
}

.app-sidebar__foot {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.app-main {
  flex: 1;
  min-width: 0;
  height: 100vh;
  overflow-y: auto;
  background: var(--bg);
}

.app-main-inner {
  padding: 20px 28px 40px;
  max-width: 920px;
}

.app-main-head {
  margin-bottom: 20px;
}

.app-page-title {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
}

.app-page-sub {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.app-section {
  margin-bottom: 24px;
}

.app-section__title {
  margin: 0 0 12px;
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.app-back-link {
  display: inline-block;
  margin-bottom: 8px;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--accent);
}

.app-back-link:hover {
  text-decoration: underline;
}

.app-main-head--actions {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  flex-wrap: wrap;
}

.btn-lg {
  padding: 14px 22px;
  font-size: 1rem;
  white-space: nowrap;
}

.app-section__toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.app-search-inline {
  max-width: 280px;
  padding: 10px 14px;
  border-radius: 24px;
  border: 1px solid var(--border);
  font-size: 0.9rem;
}

.app-scroll-panel {
  max-height: min(52vh, 520px);
  overflow-y: auto;
  padding-right: 4px;
}

.app-scroll-panel::-webkit-scrollbar {
  width: 8px;
}

.app-scroll-panel::-webkit-scrollbar-thumb {
  background: #c1c7cd;
  border-radius: 8px;
}

.app-modal {
  border: none;
  padding: 0;
  max-width: 96vw;
  width: 560px;
  background: transparent;
}

.app-modal::backdrop {
  background: rgba(32, 33, 36, 0.55);
}

.app-modal__box {
  background: var(--bg-card);
  border-radius: 16px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.2);
  overflow: hidden;
}

.app-modal__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.app-modal__title {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
}

.app-modal__close {
  border: none;
  background: transparent;
  font-size: 1.25rem;
  cursor: pointer;
  color: var(--muted);
  padding: 8px;
  border-radius: 50%;
}

.app-modal__close:hover {
  background: var(--border);
}

.app-modal__tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
}

.app-modal__tab {
  flex: 1;
  padding: 12px;
  border: none;
  background: transparent;
  font-family: inherit;
  font-weight: 600;
  font-size: 0.88rem;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 3px solid transparent;
}

.app-modal__tab.is-active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  background: var(--accent-soft);
}

.app-modal__panel {
  display: none;
  padding: 20px;
}

.app-modal__panel.is-active {
  display: block;
}

.app-section--add {
  background: linear-gradient(135deg, #e8f5e9 0%, #e3f2fd 100%);
  border: 2px solid #81c784;
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-top: 8px;
}

.app-section__title--add {
  color: #1b5e20;
  font-size: 0.95rem;
  text-transform: none;
  letter-spacing: 0;
}

.card--add {
  border-color: #a5d6a7;
  box-shadow: none;
}

.app-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  text-align: center;
  padding: 40px 20px;
}

.app-empty__illus {
  font-size: 4rem;
  margin-bottom: 16px;
  opacity: 0.85;
}

.app-empty__title {
  margin: 0 0 8px;
  font-size: 1.75rem;
  font-weight: 400;
  color: var(--muted);
}

.app-empty__text {
  max-width: 420px;
  color: var(--muted);
  margin: 0 0 24px;
  line-height: 1.6;
}

.btn-block {
  width: 100%;
}

.btn-sm {
  padding: 8px 12px;
  font-size: 0.85rem;
}

/* ——— Institution logos ——— */
.inst-logo {
  border-radius: 12px;
  overflow: hidden;
  flex-shrink: 0;
  background: var(--inst-bg, var(--bg-soft));
  box-shadow: var(--shadow-sm);
  position: relative;
}

.inst-logo img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.inst-logo__fallback {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 0.75rem;
  color: var(--inst-color, var(--accent));
  background: var(--inst-bg, var(--accent-soft));
}

/* ——— Legacy / público / auth ——— */
.wrap {
  max-width: 1100px;
  margin: 0 auto;
  padding: 28px 20px 64px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 0 8px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 700;
}

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: linear-gradient(135deg, #1a73e8, #00897b);
  box-shadow: var(--shadow-sm);
}

.brand small {
  display: block;
  font-weight: 500;
  color: var(--muted);
  font-size: 0.78rem;
}

.nav-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.hero {
  padding: 20px 0 8px;
}

.hero h1 {
  font-size: clamp(1.6rem, 3vw, 2.2rem);
  margin: 0 0 10px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.grid {
  display: grid;
  gap: 16px;
}

@media (min-width: 860px) {
  .grid-2 {
    grid-template-columns: 1fr 1fr;
  }
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 20px;
}

.card h2,
.card h3 {
  margin: 0 0 12px;
}

.card-soft {
  background: var(--bg);
  border: 1px dashed var(--border);
  box-shadow: none;
}

.muted {
  color: var(--muted);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 12px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.92rem;
  font-family: inherit;
  transition: transform 0.1s, box-shadow 0.15s;
}

.btn:hover {
  box-shadow: var(--shadow-sm);
}

.btn-primary {
  border-color: transparent;
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-hover);
  color: #fff;
  text-decoration: none;
}

.btn-danger {
  border-color: transparent;
  background: var(--danger-soft);
  color: var(--danger);
}

.btn-ghost {
  background: transparent;
}

.btn-sm {
  padding: 8px 12px;
  font-size: 0.85rem;
}

.field {
  display: grid;
  gap: 6px;
  margin-bottom: 14px;
}

label {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text);
}

input,
select,
textarea {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.table {
  width: 100%;
  border-collapse: collapse;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: #fff;
}

.table th,
.table td {
  padding: 14px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}

.table th {
  background: var(--bg);
  color: var(--muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.table tr:last-child td {
  border-bottom: none;
}

.pill {
  display: inline-flex;
  align-items: center;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  background: var(--bg);
  color: var(--muted);
}

.pill.ok {
  background: var(--ok-soft);
  color: var(--ok);
}

.pill.warn {
  background: var(--warn-soft);
  color: var(--warn);
}

.pill.bad {
  background: var(--danger-soft);
  color: var(--danger);
}

.logo-tile {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 0.8rem;
  background: var(--inst-bg, var(--accent-soft));
  color: var(--inst-color, var(--accent));
}

.row {
  display: flex;
  gap: 12px;
  align-items: center;
}

.row-between {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  flex-wrap: wrap;
}

.flash {
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 16px;
  font-weight: 500;
}

.flash.error {
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid #fecaca;
}

.flash.ok {
  background: var(--ok-soft);
  color: var(--ok);
  border: 1px solid #bbf7d0;
}

.mono {
  font-family: ui-monospace, monospace;
  font-size: 0.9rem;
}

.qr {
  max-width: 260px;
  width: 100%;
  border-radius: 12px;
  border: 1px solid var(--border);
}

.footer-note {
  margin-top: 28px;
  color: var(--muted);
  font-size: 0.85rem;
}

/* ——— Client cards (panel) ——— */
.client-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}

/* ——— Credential cards ——— */
.cred-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.cred-card {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
  padding: 16px 18px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.cred-card__info {
  flex: 1;
  min-width: 180px;
}

.cred-card__info strong {
  display: block;
  font-size: 1rem;
}

.cred-card__user {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.9rem;
}

.cred-card__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.cred-card__secret {
  width: 100%;
  margin-top: 4px;
  padding: 10px 12px;
  background: var(--ok-soft);
  border-radius: 10px;
  color: var(--ok);
  font-weight: 600;
}

.details-block {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  margin-bottom: 16px;
  overflow: hidden;
}

.details-block summary {
  padding: 14px 18px;
  cursor: pointer;
  font-weight: 700;
  list-style: none;
}

.details-block summary::-webkit-details-marker {
  display: none;
}

.details-block__body {
  padding: 0 18px 18px;
  border-top: 1px solid var(--border);
}

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
}

.empty-state__icon {
  font-size: 2.5rem;
  margin-bottom: 12px;
}

@media (max-width: 900px) {
  .app-shell {
    flex-direction: column;
  }

  .app-sidebar {
    width: 100%;
    height: auto;
    max-height: 45vh;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .app-main {
    height: auto;
    min-height: 55vh;
  }

  .app-main-inner {
    padding: 16px;
  }
}
