:root {
  --orange: #f08a24;
  --orange-soft: #fde3c8;
  --lime: #b4d335;
  --lime-dark: #7fa21f;
  --ink: #2b2b2f;
  --muted: #7d7a76;
  --bg: #e9e2da;
  --panel: #fffdfa;
  --line: #ece6de;
  --shadow: 0 10px 30px rgba(60, 40, 20, 0.14), 0 2px 6px rgba(60, 40, 20, 0.08);
  --radius: 16px;
  font-family: 'Segoe UI', system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); }
button, input, select { font: inherit; color: inherit; }

#scene { position: fixed; inset: 0; }
#scene canvas { display: block; touch-action: none; }
#labels { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }

#loading {
  position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg);
  font-size: 18px; color: var(--muted); z-index: 50; transition: opacity 0.6s;
}
body.ready #loading { opacity: 0; pointer-events: none; }

/* ------------------------------------------------ Etiquetas */
.tag {
  position: absolute; left: 0; top: 0; pointer-events: auto; cursor: pointer;
  transform-origin: 50% 100%;
  background: #fff; border-radius: 10px; padding: 5px 9px 6px;
  box-shadow: 0 4px 12px rgba(40, 30, 20, 0.18);
  min-width: 70px; max-width: 150px; text-align: center; white-space: nowrap;
  border: 1px solid rgba(0, 0, 0, 0.04);
  transition: box-shadow 0.2s;
}
.tag:hover { box-shadow: 0 6px 18px rgba(240, 138, 36, 0.4); }
.tag::after {
  content: ''; position: absolute; left: 50%; bottom: -5px; width: 10px; height: 10px;
  background: #fff; transform: translateX(-50%) rotate(45deg); border-radius: 2px;
}
.tag-name { font-weight: 800; font-size: 12.5px; letter-spacing: 0.02em; }
.tag-sub { font-size: 10.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; max-width: 132px; margin: 1px auto 0; }
.tag[data-state='free'] .tag-sub { color: #5b8a12; font-weight: 700; }
.tag-bar { height: 5px; background: #ececec; border-radius: 4px; margin-top: 4px; overflow: hidden; }
.tag-bar i { display: block; height: 100%; background: var(--orange); border-radius: 4px; transition: width 0.4s; }
.tag-ceo { background: var(--ink); color: #fff; border-color: var(--orange); }
.tag-ceo::after { background: var(--ink); }
.tag-ceo .tag-name { color: #fff; }

/* ------------------------------------------------ Barra superior */
.topbar {
  position: fixed; top: 12px; left: 12px; right: 12px; z-index: 10;
  display: flex; align-items: center; gap: 16px; padding: 8px 12px;
  background: rgba(255, 253, 250, 0.92); backdrop-filter: blur(8px);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand strong { display: block; font-size: 15px; letter-spacing: 0.04em; }
.brand span { font-size: 12px; color: var(--muted); }
.logo {
  width: 36px; height: 36px; border-radius: 10px; background: var(--orange); color: #fff;
  display: grid; place-items: center; font-weight: 800;
}
.stats { display: flex; gap: 8px; margin-left: auto; flex-wrap: wrap; }
.stat { font-size: 12.5px; padding: 5px 10px; border-radius: 999px; background: #f3efe9; color: var(--muted); }
.stat b { color: var(--ink); font-size: 14px; }
.stat.busy { background: var(--orange-soft); }
.stat.free { background: #eaf3d0; }
.actions { display: flex; gap: 8px; }

.btn {
  border: 0; cursor: pointer; padding: 8px 14px; border-radius: 10px; font-weight: 700; font-size: 13.5px;
  background: #f1ece5; transition: transform 0.1s, background 0.2s;
}
.btn:hover { background: #e9e2d8; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--orange); color: #fff; }
.btn.primary:hover { background: #e07a14; }
.btn.ghost { background: transparent; border: 1px solid var(--line); }
.btn.small { padding: 6px 10px; font-size: 12.5px; }
.btn.ok { background: #e4f1c4; color: #46660b; }
.btn.danger { background: #fbe1de; color: #b0392c; }

/* ------------------------------------------------ Salas */
.rooms-wrap { position: fixed; left: 12px; top: 80px; z-index: 9; display: flex; flex-direction: column; gap: 6px; max-height: calc(100% - 140px); }
.rooms-toggle { align-self: flex-start; border: 0; cursor: pointer; background: var(--ink); color: #fff; border-radius: 10px; padding: 6px 12px; font-weight: 700; font-size: 12.5px; }
.rooms {
  display: flex; flex-direction: column; gap: 3px; padding: 8px; overflow: auto;
  background: rgba(255, 253, 250, 0.92); backdrop-filter: blur(8px); border-radius: var(--radius); box-shadow: var(--shadow); width: 236px;
}
body.rooms-hidden .rooms { display: none; }
.room-btn {
  border: 0; background: transparent; text-align: left; cursor: pointer; padding: 6px 10px; border-radius: 8px; font-size: 12.8px;
}
.room-btn:hover { background: #f3eee7; }
.room-btn.active { background: var(--orange-soft); font-weight: 700; }
.room-btn.home { font-weight: 700; }

/* ------------------------------------------------ Zoom */
.zoom { position: fixed; right: 16px; bottom: 16px; z-index: 9; display: flex; flex-direction: column; gap: 6px; }
.zoom button {
  width: 40px; height: 40px; border-radius: 12px; border: 0; cursor: pointer; font-size: 20px; font-weight: 700;
  background: rgba(255, 253, 250, 0.95); box-shadow: var(--shadow);
}
.zoom button:hover { background: var(--orange-soft); }
.hint-bar {
  position: fixed; left: 50%; bottom: 12px; transform: translateX(-50%); margin: 0; z-index: 8;
  font-size: 12px; color: var(--muted); background: rgba(255, 253, 250, 0.8); padding: 5px 12px; border-radius: 999px;
}

/* ------------------------------------------------ Tablero */
.board {
  position: fixed; top: 80px; right: 12px; bottom: 12px; width: min(1000px, calc(100% - 270px)); z-index: 12;
  background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow);
  display: flex; flex-direction: column; padding: 14px 16px; gap: 10px;
  transform: translateX(calc(100% + 24px)); transition: transform 0.35s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.board.open { transform: none; }
.board-head { display: flex; align-items: flex-start; justify-content: space-between; }
.board-head h2 { margin: 0; font-size: 19px; }
.muted { color: var(--muted); font-size: 12.5px; margin: 2px 0 0; }
.board-tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.filter { padding: 7px 10px; border-radius: 10px; border: 1px solid var(--line); background: #fff; }
.switch { display: flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; }
.switch input { accent-color: var(--orange); width: 16px; height: 16px; }
.spacer { flex: 1; }
.columns { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; flex: 1; min-height: 0; }
.col { background: #f5f1eb; border-radius: 14px; display: flex; flex-direction: column; min-height: 0; border: 2px dashed transparent; }
.col.over { border-color: var(--orange); background: #fbefe2; }
.col header { display: flex; align-items: center; gap: 8px; padding: 10px 12px 6px; }
.col header h3 { margin: 0; font-size: 14px; text-transform: uppercase; letter-spacing: 0.05em; }
.col header .dot { width: 10px; height: 10px; border-radius: 50%; background: #bbb; }
.col-en_curso header .dot { background: var(--orange); }
.col-hecha header .dot { background: var(--lime-dark); }
.count { margin-left: auto; font-size: 12px; background: #fff; padding: 1px 8px; border-radius: 999px; color: var(--muted); }
.col-list { overflow: auto; padding: 4px 10px 12px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.empty { color: #b0aaa2; font-size: 13px; text-align: center; margin: 20px 0; }
.card {
  background: #fff; border-radius: 12px; padding: 10px; box-shadow: 0 2px 6px rgba(60, 40, 20, 0.08);
  cursor: grab; border-left: 4px solid transparent;
}
.col-en_curso .card { border-left-color: var(--orange); }
.col-hecha .card { border-left-color: var(--lime); opacity: 0.88; }
.card.dragging { opacity: 0.4; }
.card-top { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.chip {
  border: 0; cursor: pointer; font-size: 11px; font-weight: 800; letter-spacing: 0.03em; padding: 3px 8px; border-radius: 999px;
  background: color-mix(in srgb, var(--c) 22%, white); color: color-mix(in srgb, var(--c) 70%, black);
}
.date { font-size: 11px; color: #a39d95; }
.card-title { font-weight: 650; font-size: 13.5px; margin: 6px 0; line-height: 1.3; }
.progress { position: relative; height: 16px; background: #f0ece6; border-radius: 8px; overflow: hidden; }
.progress i { position: absolute; left: 0; top: 0; bottom: 0; background: linear-gradient(90deg, #f5a24f, var(--orange)); border-radius: 8px; transition: width 0.35s; }
.col-hecha .progress i { background: var(--lime); }
.progress span { position: relative; font-size: 10.5px; font-weight: 700; padding-left: 7px; line-height: 16px; }
.progress.big { height: 20px; }
.progress.big span { line-height: 20px; font-size: 12px; }
.card input[type='range'] { width: 100%; accent-color: var(--orange); margin: 6px 0 0; }
.card-actions { display: flex; gap: 4px; margin-top: 8px; align-items: center; }
.mini { border: 0; background: #f3eee7; border-radius: 7px; padding: 4px 8px; font-size: 12px; cursor: pointer; }
.mini:hover { background: #e9e1d6; }
.mini.ok { background: #e4f1c4; color: #46660b; font-weight: 700; }
.mini.danger:hover { background: #fbe1de; }
.icon-btn { border: 0; background: #f1ece5; width: 32px; height: 32px; border-radius: 10px; cursor: pointer; font-size: 15px; }
.icon-btn:hover { background: var(--orange-soft); }

/* ------------------------------------------------ Ficha del agente */
.agent-panel {
  position: fixed; top: 80px; left: 260px; width: 360px; max-height: calc(100% - 100px); overflow: auto; z-index: 13;
  background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px;
  transform: translateY(12px); opacity: 0; pointer-events: none; transition: all 0.25s;
}
.agent-panel.open { transform: none; opacity: 1; pointer-events: auto; }
.agent-panel .close { position: absolute; right: 12px; top: 12px; }
.ap-head { display: flex; gap: 12px; align-items: center; }
.ap-head h2 { margin: 0; font-size: 21px; letter-spacing: 0.04em; }
.role { margin: 2px 0 0; font-weight: 600; font-size: 13.5px; }
.avatar {
  width: 54px; height: 54px; border-radius: 16px; display: grid; place-items: center; font-weight: 800; font-size: 24px; color: #fff;
  background: var(--c); flex-shrink: 0;
}
.status { margin: 12px 0 4px; font-size: 13px; font-weight: 700; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.status .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--lime-dark); }
.status.busy .dot { background: var(--orange); }
.agent-panel h3 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 16px 0 6px; }
.functions { margin: 0; padding-left: 18px; font-size: 13.5px; line-height: 1.55; }
.current { background: #faf5ee; border-radius: 12px; padding: 10px; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.history { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.history li { display: grid; grid-template-columns: auto 1fr; gap: 2px 8px; padding: 8px; background: #f7f3ed; border-radius: 10px; font-size: 13px; }
.h-title { font-weight: 600; }
.h-meta { grid-column: 2; font-size: 11.5px; color: var(--muted); }
.badge { font-size: 10.5px; font-weight: 800; padding: 2px 7px; border-radius: 999px; align-self: start; white-space: nowrap; }
.b-pendiente { background: #ece8e2; color: #6a655f; }
.b-en_curso { background: var(--orange-soft); color: #a0520a; }
.b-hecha { background: #e4f1c4; color: #46660b; }

/* ------------------------------------------------ Diálogo */
#modal-root { position: fixed; inset: 0; z-index: 30; display: none; place-items: center; }
#modal-root.open { display: grid; }
.backdrop { position: absolute; inset: 0; background: rgba(40, 30, 20, 0.35); }
.dialog {
  position: relative; width: min(480px, calc(100% - 32px)); background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 20px; display: flex; flex-direction: column; gap: 12px;
}
.dialog h2 { margin: 0 0 4px; font-size: 19px; }
.dialog label { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; font-weight: 700; color: var(--muted); }
.dialog input[type='text'], .dialog select { padding: 9px 11px; border-radius: 10px; border: 1px solid #ddd5ca; background: #fff; font-weight: 500; color: var(--ink); }
.dialog input[type='text']:focus, .dialog select:focus { outline: 2px solid var(--orange); border-color: transparent; }
.dialog input[type='range'] { accent-color: var(--orange); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.hint { margin: 0; font-size: 12px; color: var(--muted); }
.dialog-actions { display: flex; gap: 8px; align-items: center; margin-top: 4px; }

#toast {
  position: fixed; left: 50%; bottom: 52px; transform: translate(-50%, 20px); opacity: 0; z-index: 40;
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 13.5px; font-weight: 600;
  transition: all 0.3s; pointer-events: none;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 900px) {
  .stats { display: none; }
  .rooms { width: 200px; }
  .board { width: calc(100% - 24px); }
  .agent-panel { left: 12px; width: calc(100% - 24px); }
  .hint-bar { display: none; }
}
