/* ──────────────────────────────────────────────────────────────────────────
   Business IT Design System · Portal de Comunicaciones
   Tokens y estados globales (mismo sistema que BitTravel y business-it-analytics:
   Montserrat, verde #A3C243, gris #606161, radios 8/12/16, sombras suaves).
   Los componentes de app.jsx usan estilos en línea para el layout; aquí viven
   las variables, la tipografía base y los estados hover/focus que el inline no cubre.
   ────────────────────────────────────────────────────────────────────────── */
:root {
  --font-family-base: 'Montserrat', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;

  --color-brand-green: #A3C243;
  --color-brand-gray:  #606161;

  --background:     #F4F4F2;
  --foreground:     #606161;
  --text-strong:    #1F1F1F;
  --card:           #FFFFFF;
  --primary:        #A3C243;
  --primary-hover:  #8FAD38;
  --primary-active: #7A962F;
  --primary-strong: #5E7A1F;
  --primary-tint:   #F4F8E6;
  --primary-tint-2: #E9F1CF;
  --primary-border: #D6E3A6;
  --secondary:      #606161;
  --muted:          #F5F5F5;
  --muted-2:        #FAFAFA;
  --muted-foreground: #8B8B8C;
  --border:         #E5E5E5;
  --input:          #D9D9D9;
  --ring:           #A3C243;
  --destructive:    #DC2626;
  --warning:        #F59E0B;
  --info:           #3B82F6;

  --radius-sm: 4px; --radius-md: 8px; --radius-lg: 12px; --radius-xl: 16px; --radius-full: 9999px;

  --shadow-sm: 0 1px 2px 0 rgba(96, 97, 97, 0.06);
  --shadow-md: 0 4px 6px -1px rgba(96, 97, 97, 0.10), 0 2px 4px -1px rgba(96, 97, 97, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(96, 97, 97, 0.10), 0 4px 6px -2px rgba(96, 97, 97, 0.05);
  --shadow-xl: 0 20px 25px -5px rgba(96, 97, 97, 0.12), 0 10px 10px -5px rgba(96, 97, 97, 0.04);
  --shadow-primary: 0 6px 16px rgba(163, 194, 67, 0.32);

  --transition-fast: 150ms ease-in-out;
  --transition-base: 200ms ease-in-out;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-family-base);
  color: var(--foreground);
  background:
    radial-gradient(900px 540px at 8% -6%, rgba(163, 194, 67, 0.14), transparent 55%),
    radial-gradient(700px 420px at 100% 0%, rgba(96, 97, 97, 0.06), transparent 60%),
    linear-gradient(160deg, #FBFBF9 0%, var(--background) 45%, #EFEFEC 100%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font-family: inherit; }
button { font-weight: 600; }
h1, h2, h3, h4 { color: var(--text-strong); letter-spacing: -0.01em; }
a { color: var(--primary-strong); }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes progress { from { width: 0%; } to { width: 100%; } }
@keyframes fade-up { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ── App bar ─────────────────────────────────────────────────────────── */
.app-bar {
  position: sticky; top: 0; z-index: 100;
  height: 60px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 0 24px;
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(14px) saturate(140%);
  -webkit-backdrop-filter: blur(14px) saturate(140%);
  border-bottom: 1px solid var(--border);
}
.app-bar::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 3px;
  background: linear-gradient(90deg, var(--primary), var(--primary-active));
  opacity: 0.9;
}
.app-bar-brand { display: flex; align-items: center; gap: 14px; min-width: 0; }
.app-bar-brand img { height: 32px; width: auto; display: block; }
.app-bar-divider { width: 1px; height: 26px; background: var(--border); }
.app-bar-title { font-size: 14px; font-weight: 700; color: var(--text-strong); white-space: nowrap; }
.app-bar-sub { font-size: 11px; font-weight: 500; color: var(--muted-foreground); white-space: nowrap; }

#user-menu-wrap { position: relative; flex-shrink: 0; }
#user-bar {
  display: none; align-items: center; gap: 10px; cursor: pointer;
  padding: 4px 8px 4px 4px; border-radius: var(--radius-full); background: none;
  border: 1px solid transparent; transition: background var(--transition-fast), border-color var(--transition-fast);
}
#user-bar:hover, #user-bar[aria-expanded="true"] { background: var(--muted); border-color: var(--border); }
.user-caret { color: var(--muted-foreground); transition: transform var(--transition-fast); }
#user-bar[aria-expanded="true"] .user-caret { transform: rotate(180deg); }
#user-menu {
  position: absolute; right: 0; top: calc(100% + 8px); min-width: 248px; z-index: 120;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl); padding: 6px; animation: fade-up 160ms ease-out both;
}
#user-menu[hidden] { display: none; }
.user-menu-head { padding: 8px 12px 10px; border-bottom: 1px solid var(--border); margin-bottom: 6px; }
.user-menu-name { font-size: 13px; font-weight: 700; color: var(--text-strong); }
.user-menu-email { font-size: 11.5px; color: var(--muted-foreground); word-break: break-all; }
.user-menu-item {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  padding: 10px 12px; border-radius: var(--radius-md); border: none; background: none; cursor: pointer;
  font-size: 13.5px; font-weight: 600; color: var(--text-strong); text-decoration: none;
}
.user-menu-item svg { color: var(--muted-foreground); flex-shrink: 0; }
.user-menu-item:hover { background: var(--primary-tint); color: var(--primary-strong); }
.user-menu-item:hover svg { color: var(--primary-strong); }
.user-menu-item.danger:hover { background: #FEF2F2; color: var(--destructive); }
.user-menu-item.danger:hover svg { color: var(--destructive); }
.user-menu-item[hidden] { display: none; }
.user-menu-sep { height: 1px; background: var(--border); margin: 6px 4px; }
#user-avatar {
  width: 34px; height: 34px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; color: #1A2400;
  background: linear-gradient(135deg, #C3D97A, var(--primary));
  box-shadow: inset 0 0 0 2px rgba(255,255,255,0.7);
}
.user-bar-text { line-height: 1.2; text-align: left; }
#user-name { font-size: 12.5px; font-weight: 600; color: var(--text-strong); line-height: 1.2; }
#user-email { font-size: 10.5px; color: var(--muted-foreground); line-height: 1.2; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 50%; border: none; background: none; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; color: var(--muted-foreground);
  transition: background var(--transition-fast), color var(--transition-fast);
}
.icon-btn:hover { background: var(--muted); color: var(--destructive); }

/* ── Página / superficie principal ───────────────────────────────────── */
.page { padding: 28px 16px 56px; display: flex; justify-content: center; }
#root {
  display: none;   /* msal-init.js lo muestra (display: block) tras el login */
  width: 100%; max-width: 780px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  padding: 8px;
  animation: fade-up 240ms ease-out both;
  transition: max-width var(--transition-base);
}

/* ── Login ────────────────────────────────────────────────────────────── */
#login-overlay {
  display: none; position: fixed; inset: 0; z-index: 9999;
  align-items: center; justify-content: center; padding: 16px;
  background:
    radial-gradient(900px 540px at 8% -6%, rgba(163, 194, 67, 0.18), transparent 55%),
    linear-gradient(160deg, #FBFBF9 0%, var(--background) 45%, #EFEFEC 100%);
}
.login-card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl); padding: 44px 40px 36px; max-width: 420px; width: 100%; text-align: center;
  position: relative; overflow: hidden; animation: fade-up 300ms ease-out both;
}
.login-card::before { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 4px;
  background: linear-gradient(90deg, var(--primary), var(--primary-active)); }
.login-card img { height: 40px; width: auto; margin-bottom: 26px; }
.login-card h2 { font-size: 20px; font-weight: 700; margin: 0 0 8px; }
.login-card p { font-size: 14px; color: var(--foreground); margin: 0 0 28px; line-height: 1.6; }
.login-card .fine { font-size: 11px; color: var(--muted-foreground); margin: 18px 0 0; }
.btn-ms {
  display: inline-flex; align-items: center; justify-content: center; gap: 12px; width: 100%;
  height: 48px; padding: 0 24px; font-size: 15px; font-weight: 600; color: #FFFFFF;
  background: linear-gradient(135deg, var(--primary), var(--primary-active));
  border: none; border-radius: var(--radius-lg); cursor: pointer; box-shadow: var(--shadow-primary);
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}
.btn-ms:hover { transform: translateY(-1px); box-shadow: 0 10px 22px rgba(163, 194, 67, 0.42); }

/* ── Estados globales de controles (lo que el estilo inline no puede) ── */
input:not([type="checkbox"]):not([type="radio"]), textarea, select {
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast), background var(--transition-fast);
}
input:not([type="checkbox"]):not([type="radio"]):hover, textarea:hover, select:hover { border-color: #BDBDBD !important; }
input:not([type="checkbox"]):not([type="radio"]):focus, textarea:focus, select:focus {
  outline: none; border-color: var(--primary) !important; background: #FFFFFF !important;
  box-shadow: 0 0 0 3px rgba(163, 194, 67, 0.22);
}
input::placeholder, textarea::placeholder { color: #A8A8A9; }
input[type="checkbox"] { accent-color: var(--primary); }
select { appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23606161' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='m6 9 6 6 6-6'/></svg>");
  background-repeat: no-repeat; background-position: right 10px center; padding-right: 34px !important; }
button { transition: background var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast),
  box-shadow var(--transition-fast), transform var(--transition-fast), opacity var(--transition-fast); }
button:not(:disabled):active { transform: translateY(0) scale(0.99); }
:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
button:focus:not(:focus-visible) { outline: none; }

/* Botones nombrados desde app.jsx (className). Los colores base viajan en el inline style. */
.btn-primary:not(:disabled):hover { transform: translateY(-1px); box-shadow: 0 10px 22px rgba(163, 194, 67, 0.42) !important; filter: saturate(1.05); }
.btn-secondary:not(:disabled):hover { background: #EDEDED !important; border-color: #D4D4D4 !important; }
.btn-tonal:not(:disabled):hover { background: var(--primary-tint-2) !important; border-color: #C3D97A !important; }
.btn-ghost:not(:disabled):hover { background: var(--muted) !important; }
.btn-link:not(:disabled):hover { color: var(--text-strong) !important; }
.choice-card:not(:disabled):hover { border-color: #C3D97A !important; box-shadow: var(--shadow-md); }
.choice-card[data-active="true"] { box-shadow: 0 0 0 3px rgba(163, 194, 67, 0.18); }
.image-card:not(:disabled):hover { box-shadow: var(--shadow-lg); transform: translateY(-2px); }
.area-item:hover { background: var(--primary-tint) !important; }
.tab-btn:not([aria-selected="true"]):hover { background: var(--muted) !important; }
.table-row:hover td { background: var(--primary-tint) !important; }
.cal-ev:hover { filter: brightness(0.96); }
details > summary { list-style: none; }
details > summary::-webkit-details-marker { display: none; }
details > summary::before { content: "▸"; display: inline-block; margin-right: 6px; transition: transform var(--transition-fast); }
details[open] > summary::before { transform: rotate(90deg); }

@media (max-width: 640px) {
  .app-bar { padding: 0 12px; height: 56px; }
  .app-bar-brand img { height: 26px; }
  .app-bar-title { font-size: 13px; white-space: normal; line-height: 1.2; }
  .app-bar-sub, #user-name, #user-email, .user-caret { display: none; }
  #user-bar { padding: 2px; }
  .page { padding: 14px 10px 40px; }
  #root { border-radius: var(--radius-lg); padding: 4px; }
  .choice-row { flex-wrap: wrap; }
  .choice-row > button { flex: 1 1 100% !important; }
}
.btn-ms:disabled { opacity: 0.6; cursor: wait; transform: none; }
