:root {
  --sys-white: #ffffff;
  --sys-blue: #0033a0;
  --sys-blue-dark: #003087;
  --sys-green: #00953b;
  --sys-bg-soft: #f5f7ff;
  --sys-border-soft: #e0e6f5;
  --sys-input-bg: #f8fafc;
  --radius-lg: 18px;
  --radius-xl: 26px;
  --shadow-soft: 0 10px 25px rgba(0, 0, 0, 0.06);
}

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

body {
  font-family: "Gotham", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--sys-bg-soft);
  color: #102048;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

h1, h2, h3, h4 {
  letter-spacing: 0.03em;
}

h1 {
  font-weight: 900;
  text-transform: uppercase;
  color: var(--sys-blue-dark);
}

h2 {
  font-weight: 500;
  color: var(--sys-blue);
}

h3 {
  font-weight: 500;
}

p, label, span, th, td {
  font-weight: 300;
}

a {
  text-decoration: none;
  color: inherit;
}

/* ───────────────── INPUTS Y CONTROLES (diseño coherente en toda la app) ───────────────── */
input[type="text"],
input[type="email"],
input[type="number"],
input[type="password"],
input[type="search"],
input[type="url"],
input[type="tel"],
input[type="date"],
input[type="datetime-local"],
select,
textarea {
  font-family: inherit;
  font-size: 14px;
  color: #374151;
  background: var(--sys-input-bg);
  border: 1px solid var(--sys-border-soft);
  border-radius: 10px;
  padding: 10px 12px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input[type="text"]:focus,
input[type="email"]:focus,
input[type="number"]:focus,
input[type="password"]:focus,
input[type="search"]:focus,
input[type="url"]:focus,
input[type="tel"]:focus,
input[type="date"]:focus,
input[type="datetime-local"]:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--sys-blue);
  box-shadow: 0 0 0 2px rgba(0, 51, 160, 0.12);
}

input::placeholder,
textarea::placeholder {
  color: #9ca3b8;
}

/* Select: misma estética que inputs (borde, radio, padding) + flecha coherente */
select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  cursor: pointer;
  min-height: 42px;
  background-color: var(--sys-input-bg);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23374151' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

select:hover {
  border-color: #c5cfe0;
}

select:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  background-color: #f5f7ff;
}

textarea {
  min-height: 80px;
  resize: vertical;
}

/* Checkbox y radio coherentes con la paleta */
input[type="checkbox"],
input[type="radio"] {
  accent-color: var(--sys-blue);
  cursor: pointer;
  width: 18px;
  height: 18px;
}

/* ───────────────── LAYOUT GENERAL ───────────────── */

.app-shell {
  display: grid;
  grid-template-rows: auto 1fr auto;
  grid-template-columns: 260px 1fr;
  grid-template-areas:
    "topbar topbar"
    "sidebar main"
    "footer footer";
  min-height: 100vh;
}

.topbar {
  grid-area: topbar;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px;
  background: linear-gradient(90deg, var(--sys-blue-dark), var(--sys-blue));
  color: var(--sys-white);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Botón hamburger - oculto en desktop */
.hamburger-btn {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 44px;
  height: 44px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.15);
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}

.hamburger-btn:hover {
  background: rgba(255, 255, 255, 0.25);
}

.hamburger-btn:focus {
  outline: 2px solid rgba(255, 255, 255, 0.5);
  outline-offset: 2px;
}

.hamburger-line {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--sys-white);
  border-radius: 1px;
  transition: transform 0.3s ease, opacity 0.3s ease;
}

body.mobile-menu-open .hamburger-btn .hamburger-line:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}

body.mobile-menu-open .hamburger-btn .hamburger-line:nth-child(2) {
  opacity: 0;
}

body.mobile-menu-open .hamburger-btn .hamburger-line:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

/* Overlay del menú móvil - oculto en desktop */
.mobile-menu-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 998;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s ease;
}

/* Salir en sidebar - oculto en desktop (se usa el del topbar) */
.sidebar-logout {
  display: none;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid rgba(0, 51, 160, 0.15);
}

.sidebar-item-logout {
  color: #c53030;
}

.sidebar-item-logout:hover {
  background: rgba(197, 48, 48, 0.08) !important;
}

.logo-pill {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255, 255, 255, 0.1);
  padding: 8px 16px;
  border-radius: 999px;
}

.logo-pill img {
  background: var(--sys-white);
  border-radius: 8px;
  padding: 6px;
}

.logo-text-main {
  font-weight: 900;
  letter-spacing: 0.15em;
}

.logo-text-sub {
  font-weight: 300;
  font-size: 11px;
  text-transform: uppercase;
  opacity: 0.85;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 14px;
}

.topbar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
}

.user-info {
  text-align: right;
}

.user-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--sys-green);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 500;
  font-size: 12px;
}

.sidebar {
  grid-area: sidebar;
  background: var(--sys-white);
  box-shadow: 4px 0 18px rgba(0, 0, 0, 0.04);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  overflow-y: auto;
}

.sidebar-title {
  font-size: 13px;
  text-transform: uppercase;
  color: #7c8ab4;
  font-weight: 500;
  letter-spacing: 0.14em;
  margin-bottom: 8px;
}

.sidebar-menu {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sidebar-item {
  padding: 9px 12px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.08s ease;
}

.sidebar-item span {
  display: flex;
  align-items: center;
  gap: 8px;
}

.sidebar-item.active {
  background: rgba(0, 51, 160, 0.09);
  color: var(--sys-blue);
  font-weight: 500;
}

.sidebar-item:hover {
  background: rgba(0, 51, 160, 0.04);
  transform: translateX(1px);
}

/* Ítems con submenú (cuando no está desplegado) misma estética que el resto */
.sidebar-item:has(.sidebar-arrow) {
  cursor: pointer;
}

.sidebar-arrow {
  font-size: 10px;
  opacity: 0.7;
  transition: transform 0.2s ease, opacity 0.2s ease;
  margin-left: 4px;
}

.sidebar-item:hover .sidebar-arrow {
  opacity: 1;
}

.sidebar-item.expanded .sidebar-arrow {
  transform: rotate(180deg);
  opacity: 1;
}

.sidebar-submenu {
  margin-left: 20px;
  margin-top: 4px;
  display: none;
  flex-direction: column;
  gap: 2px;
  padding-left: 8px;
  border-left: 2px solid rgba(0, 51, 160, 0.1);
}

.sidebar-item.expanded + .sidebar-submenu {
  display: flex;
}

.sidebar-submenu .sidebar-item {
  padding: 6px 12px;
  font-size: 12px;
  border-radius: 8px;
}

.sidebar-pill {
  margin-top: auto;
  background: linear-gradient(135deg, var(--sys-green), #29b95a);
  border-radius: var(--radius-xl);
  padding: 16px 16px 14px;
  color: var(--sys-white);
  box-shadow: var(--shadow-soft);
  font-size: 12px;
}

.sidebar-pill-title {
  font-weight: 500;
  margin-bottom: 6px;
}

.sidebar-pill button {
  margin-top: 10px;
  background: var(--sys-white);
  color: var(--sys-green);
  border-radius: 999px;
  border: none;
  padding: 5px 10px;
  font-size: 11px;
  cursor: pointer;
  font-weight: 500;
}

.main {
  grid-area: main;
  padding: 18px 24px 30px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  overflow-y: auto;
}

/* Centrar contenido y formularios en PC */
.main > .content-wrapper {
  max-width: 1200px;
  margin-left: auto;
  margin-right: auto;
  width: 100%;
  box-sizing: border-box;
  /* Evita que flex (align-items: center) use min-width: auto del contenido (p. ej. SVG) y rompa el ancho */
  align-self: stretch;
  min-width: 0;
}

.main > .sys-card,
.main > .sys-detail-card,
.main > .expense-card,
.main > .activity-card,
.main > .sys-list-card,
.main > .sys-revision-card,
.main > .expense-list-card {
  margin-left: auto;
  margin-right: auto;
  width: 100%;
  max-width: 1200px;
  box-sizing: border-box;
  align-self: stretch;
  min-width: 0;
}

/* Portal cliente: contenido y tarjetas */
.main > .page-content {
  width: 100%;
  max-width: 900px;
  margin-left: auto;
  margin-right: auto;
  box-sizing: border-box;
}

.portal-card {
  background: var(--sys-white);
  border-radius: 16px;
  padding: 24px;
  box-shadow: var(--shadow-soft);
}

.portal-card-title {
  font-size: 18px;
  font-weight: 600;
  text-transform: none;
  margin-bottom: 16px;
  color: var(--sys-blue-dark);
}

.portal-row {
  margin-bottom: 12px;
}

.portal-label {
  font-weight: 600;
  color: #6b7694;
  font-size: 12px;
  text-transform: uppercase;
}

.portal-link {
  color: var(--sys-blue);
  text-decoration: none;
  transition: opacity 0.15s ease;
}

.portal-link:hover {
  text-decoration: underline;
}

.footer {
  grid-area: footer;
  background: var(--sys-white);
  border-top: 1px solid var(--sys-border-soft);
  padding: 16px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: #6b7694;
}

.footer-nav {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
}

.footer-nav a {
  color: #6b7694;
  transition: color 0.15s ease;
}

.footer-nav a:hover {
  color: var(--sys-blue);
}

.footer-copyright {
  font-size: 11px;
  opacity: 0.7;
}

/* RESPONSIVE */

@media (max-width: 1024px) {
  .main {
    padding: 16px 20px 24px;
  }
  .app-shell {
    grid-template-columns: 72px 1fr;
  }

  .sidebar {
    padding-inline: 10px;
  }

  .sidebar-title {
    display: none;
  }

  .sidebar-item span span:last-child {
    display: none;
  }

  .sidebar-submenu {
    display: none;
  }

  .sidebar-pill {
    display: none;
  }
}

@media (max-width: 768px) {
  .main {
    padding: 12px 16px 20px;
  }

  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr auto;
    grid-template-areas:
      "topbar"
      "main"
      "footer";
  }

  /* Mostrar botón hamburger */
  .hamburger-btn {
    display: flex;
  }

  /* Ocultar Salir del topbar en móvil (está en el menú hamburger) */
  .topbar-right .topbar-logout {
    display: none !important;
  }

  /* Usuario visible en móvil: mostrar solo avatar para ahorrar espacio */
  .topbar-right .topbar-user .user-info {
    display: none;
  }

  .topbar-right .topbar-user {
    padding: 4px;
  }

  .topbar-right .topbar-user .user-avatar {
    width: 40px;
    height: 40px;
    font-size: 14px;
  }

  .topbar-right .topbar-user-link {
    -webkit-tap-highlight-color: transparent;
  }

  .topbar {
    padding: 12px 16px;
    flex-wrap: wrap;
    gap: 8px;
  }

  .topbar-right {
    flex-wrap: wrap;
  }

  .logo-pill {
    padding: 6px 12px;
  }

  .logo-text-sub {
    display: none;
  }

  /* Sidebar como menú deslizante (drawer) */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(300px, 85vw);
    max-width: 300px;
    z-index: 999;
    transform: translateX(-100%);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    overflow-y: auto;
    grid-area: unset;
    padding: 20px 16px;
    box-shadow: none;
  }

  body.mobile-menu-open .sidebar {
    transform: translateX(0);
    box-shadow: 8px 0 24px rgba(0, 0, 0, 0.15);
  }

  body.mobile-menu-open {
    overflow: hidden;
  }

  /* Mostrar overlay cuando menú abierto */
  .mobile-menu-overlay {
    display: block;
    pointer-events: none;
  }

  body.mobile-menu-open .mobile-menu-overlay {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
  }

  /* Sidebar en móvil: columna vertical con submenús expandibles */
  .sidebar-menu {
    flex-direction: column;
  }

  .sidebar-item span span:last-child {
    display: inline;
  }

  .sidebar-title {
    display: block;
  }

  .sidebar-submenu {
    display: none;
  }

  .sidebar-item.expanded + .sidebar-submenu {
    display: flex;
  }

  /* Mostrar Salir en sidebar móvil */
  .sidebar-logout {
    display: block !important;
  }

  .sidebar-pill {
    display: none;
  }

  .footer {
    flex-direction: column;
    gap: 12px;
    text-align: center;
  }
}
