:root {
  --bg: #0b141d; --surface: #111b26; --surface-2: #16232f; --line: #1f3040;
  --ink: #e8eef5; --muted: #8fa3b8; --accent: #3a8bd0; --accent-2: #4a9be8;
  --ok: #3ecf8e; --warn: #f2b84b; --bad: #ef6b6b;
  color-scheme: dark;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
.muted { color: var(--muted); }
.small { font-size: 13px; }
[hidden] { display: none !important; }

.top { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.top .who { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; flex: 1; }
.top .who span { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

nav { display: flex; flex-wrap: wrap; gap: 4px; padding: 8px 12px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--bg); z-index: 2; }
nav a, nav summary { color: var(--muted); text-decoration: none; padding: 8px 12px; border-radius: 8px; white-space: nowrap; display: block; }
nav a:hover, nav summary:hover { color: var(--ink); }
nav a[aria-current="page"], .menu.active > summary { background: var(--surface-2); color: var(--ink); }
.menu { position: relative; }
.menu summary { cursor: pointer; list-style: none; user-select: none; }
.menu summary::-webkit-details-marker { display: none; }
.menu summary::after { content: "▾"; margin-left: 6px; font-size: 11px; }
.menu[open] summary::after { content: "▴"; }
.menu .items { position: absolute; top: calc(100% + 4px); left: 0; min-width: 190px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 4px; box-shadow: 0 10px 30px rgb(0 0 0 / .45); z-index: 4; }
/* En pantallas angostas el desplegable usa todo el ancho para no salirse. */
@media (max-width: 520px) {
  .menu { position: static; }
  .menu .items { left: 12px; right: 12px; top: 100%; }
}

main { max-width: 960px; margin: 0 auto; padding: 20px 16px 64px; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 24px 0 10px; }
.head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.head p { margin: 0; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; margin-bottom: 10px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.row > .grow { flex: 1; min-width: 180px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.tile b { display: block; font-size: 24px; line-height: 1.3; }

.badge { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); }
.badge.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 45%, transparent); }
.badge.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 45%, transparent); }
.badge.bad { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 45%, transparent); }

.alert { border-left: 3px solid var(--warn); background: var(--surface-2); padding: 10px 14px; border-radius: 8px; margin: 0 0 12px; }
.alert.bad { border-color: var(--bad); }

button, .button {
  font: inherit; cursor: pointer; border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface-2); color: var(--ink); padding: 8px 14px; text-decoration: none; display: inline-block;
}
button:hover, .button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: var(--accent-2); }
button.danger { color: var(--bad); }
button:disabled { opacity: .55; cursor: progress; }
:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; }

input, select, textarea {
  font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; width: 100%; min-width: 0;
}
input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); }
textarea { resize: vertical; min-height: 74px; }
#tenant { width: auto; max-width: 45vw; }
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
label.check { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.cols { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 12px; }

dialog { background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: 14px; width: min(560px, calc(100vw - 24px)); max-height: 90vh; padding: 20px; }
dialog::backdrop { background: rgb(0 0 0 / .65); }
dialog h2 { margin-top: 0; }
dialog .actions { justify-content: flex-end; margin-top: 16px; }
.error { color: var(--bad); margin: 8px 0 0; }

.pro-block { border-top: 1px solid var(--line); padding-top: 10px; margin-top: 6px; }
.day { display: grid; grid-template-columns: 130px 1fr 1fr; align-items: center; gap: 10px; margin-bottom: 8px; }
.day label { display: flex; gap: 8px; align-items: center; }

.event { display: grid; grid-template-columns: 92px 1fr; gap: 10px; }
.event time { font-variant-numeric: tabular-nums; color: var(--muted); }
.event.block { border-style: dashed; }

.chat { display: flex; flex-direction: column; gap: 6px; max-height: 55vh; overflow-y: auto; padding: 4px; }
.msg { max-width: 85%; padding: 8px 12px; border-radius: 12px; background: var(--surface-2); white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.agent { align-self: flex-end; background: color-mix(in srgb, var(--accent) 28%, var(--surface)); }
.msg time { display: block; font-size: 11px; color: var(--muted); }
button.card { width: 100%; text-align: left; }
.clip { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }

#toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--surface-2); border: 1px solid var(--accent); border-radius: 10px; padding: 10px 16px; opacity: 0; pointer-events: none; transition: opacity .2s; max-width: calc(100vw - 32px); z-index: 5; }
#toast.show { opacity: 1; }
#toast.bad { border-color: var(--bad); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
button.small, .button.small { padding: 5px 10px; font-size: 13px; }
.chart { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 6px; }
.chart .col { display: flex; flex-direction: column; align-items: center; gap: 4px; background: none; border: 0; padding: 4px 0; min-width: 0; }
.chart .col:hover { background: var(--surface-2); }
.chart .value { font-size: 12px; color: var(--ink); }
.chart .plot { height: 120px; width: 100%; display: flex; align-items: flex-end; justify-content: center; border-bottom: 1px solid var(--line); }
.chart .bar { width: min(24px, 80%); background: var(--accent); border-radius: 4px 4px 0 0; }
.chart .small { font-size: 11px; }
.rank { margin-bottom: 10px; }
.hbar { display: block; height: 6px; background: var(--accent); border-radius: 0 4px 4px 0; }
table { width: 100%; border-collapse: collapse; margin: 10px 0; font-size: 14px; }
th, td { text-align: left; vertical-align: top; padding: 6px 8px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 500; width: 45%; }
td { overflow-wrap: anywhere; }

@media (max-width: 520px) {
  .cols { grid-template-columns: minmax(0, 1fr); }
  .day { grid-template-columns: 1fr 1fr; }
  .day label { grid-column: 1 / -1; }
}
