:root {
  --azul: #1f3864;
  --azul-claro: #2f5496;
  --gris: #6b7280;
  --gris-claro: #f3f4f6;
  --borde: #e5e7eb;
  --texto: #1f2937;
  --critico: #b91c1c;
  --alta: #b45309;
  --ok: #15803d;
  --radio: 10px;
  --sombra: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--texto);
  background: var(--gris-claro);
  font-size: 15px;
}
h1, h2, h3 { color: var(--azul); margin: 0 0 .6rem; }
.muted { color: var(--gris); font-size: .9rem; }
.error { color: var(--critico); font-size: .9rem; }
button {
  cursor: pointer; border: none; border-radius: 8px;
  background: var(--azul); color: #fff; padding: .55rem .9rem; font-size: .95rem;
}
button:hover { background: var(--azul-claro); }
button.ghost { background: #fff; color: var(--azul); border: 1px solid var(--borde); }
button.ghost:hover { background: var(--gris-claro); }
input, select, textarea {
  font: inherit; padding: .55rem .7rem; border: 1px solid var(--borde);
  border-radius: 8px; background: #fff; color: var(--texto); width: 100%;
}
textarea { resize: vertical; }
select { width: auto; }

/* LOGIN */
.login { display: grid; place-items: center; height: 100vh; padding: 1rem; }
.login-card {
  background: #fff; padding: 2rem; border-radius: var(--radio);
  box-shadow: var(--sombra); width: 100%; max-width: 340px; text-align: center;
}
.login-card h1 { font-size: 2rem; margin-bottom: 0; }
.login-card form { display: grid; gap: .8rem; margin-top: 1.2rem; }

/* APP LAYOUT */
.app { display: flex; flex-direction: column; height: 100vh; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--azul); color: #fff; padding: .6rem 1rem;
}
.brand { font-weight: 700; font-size: 1.2rem; }
.topbar-right { display: flex; align-items: center; gap: .8rem; }
.ctx { font-size: .85rem; display: flex; align-items: center; gap: .4rem; }
.topbar select { padding: .3rem .5rem; }
.topbar button.ghost { color: #fff; border-color: rgba(255,255,255,.4); background: transparent; }

.tabs { display: flex; gap: .2rem; background: #fff; border-bottom: 1px solid var(--borde); overflow-x: auto; }
.tab { background: transparent; color: var(--gris); border-radius: 0; padding: .8rem 1rem; white-space: nowrap; }
.tab:hover { background: var(--gris-claro); }
.tab.active { color: var(--azul); border-bottom: 3px solid var(--azul); font-weight: 600; }

.content { flex: 1; overflow-y: auto; padding: 1rem; max-width: 1000px; width: 100%; margin: 0 auto; }
.tabpane { display: none; }
.tabpane.active { display: block; }

.row-between { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.filters { display: flex; gap: .5rem; align-items: center; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 1.2rem; }
.col { min-width: 0; }
.form-grid { display: grid; gap: .6rem; margin: .6rem 0; }
.inline { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin: .4rem 0; }
.panel { background: #fff; border: 1px solid var(--borde); border-radius: var(--radio); padding: .6rem .9rem; margin-bottom: .8rem; }
.panel summary { cursor: pointer; font-weight: 600; color: var(--azul); }

/* CHAT */
#tab-chat.active { display: flex; flex-direction: column; height: 100%; }
.chat-log { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: .6rem; padding-bottom: .5rem; }
.msg { max-width: 80%; padding: .6rem .85rem; border-radius: 14px; white-space: pre-wrap; line-height: 1.4; box-shadow: var(--sombra); }
.msg.user { align-self: flex-end; background: var(--azul); color: #fff; border-bottom-right-radius: 4px; }
.msg.carla { align-self: flex-start; background: #fff; border-bottom-left-radius: 4px; }
.typing { color: var(--gris); font-size: .85rem; font-style: italic; padding: .2rem .5rem; }
.grabando { color: var(--critico); font-size: .85rem; font-weight: 600; padding: .2rem .5rem; animation: pulso 1s infinite; }
@keyframes pulso { 50% { opacity: .4; } }
.mic { background: #fff; color: var(--azul); border: 1px solid var(--borde); font-size: 1.2rem; padding: .4rem .7rem; touch-action: none; user-select: none; }
.mic:hover { background: var(--gris-claro); }
.mic.rec { background: var(--critico); color: #fff; border-color: var(--critico); transform: scale(1.08); }
.chat-input { display: flex; gap: .5rem; padding-top: .5rem; border-top: 1px solid var(--borde); }
.chat-input textarea { flex: 1; max-height: 140px; }

/* LISTAS / TABLAS */
.lista { display: grid; gap: .5rem; margin-top: .6rem; }
.item { background: #fff; border: 1px solid var(--borde); border-radius: var(--radio); padding: .7rem .9rem; display: flex; justify-content: space-between; align-items: center; gap: .6rem; }
.item .titulo { font-weight: 600; }
.item .sub { color: var(--gris); font-size: .85rem; }
.badge { font-size: .72rem; padding: .15rem .5rem; border-radius: 999px; background: var(--gris-claro); color: var(--gris); }
.badge.critica { background: #fee2e2; color: var(--critico); }
.badge.alta { background: #fef3c7; color: var(--alta); }
.tabla-wrap { overflow-x: auto; margin-top: .8rem; }
table { border-collapse: collapse; width: 100%; background: #fff; border-radius: var(--radio); overflow: hidden; }
th, td { text-align: left; padding: .5rem .7rem; border-bottom: 1px solid var(--borde); font-size: .9rem; }
th { background: var(--azul); color: #fff; }

/* NOTIFICACIONES */
.notif-container { position: fixed; top: 1rem; right: 1rem; display: grid; gap: .5rem; z-index: 1000; max-width: 340px; }
.notif { background: #fff; border-left: 4px solid var(--azul); border-radius: 8px; box-shadow: 0 4px 12px rgba(0,0,0,.15); padding: .7rem .9rem; animation: slidein .2s ease; }
.notif.critica { border-left-color: var(--critico); }
.notif .n-titulo { font-weight: 600; }
.notif .n-cuerpo { font-size: .88rem; color: var(--gris); white-space: pre-wrap; }
.notif .n-acciones { margin-top: .4rem; display: flex; gap: .4rem; }
.notif button { padding: .3rem .6rem; font-size: .8rem; }
@keyframes slidein { from { transform: translateX(20px); opacity: 0; } to { transform: none; opacity: 1; } }

@media (max-width: 720px) {
  .cols { grid-template-columns: 1fr; }
  .content { padding: .7rem; }
  .msg { max-width: 90%; }
  .notif-container { left: .5rem; right: .5rem; max-width: none; }
}
