:root {
  color-scheme: light;
  --bg: #f3f5f8;
  --panel: #ffffff;
  --ink: #17202a;
  --muted: #667085;
  --line: #d8dee8;
  --accent: #2563eb;
  --accent-strong: #1d4ed8;
  --nav: #111827;
  --nav-soft: #1f2937;
  --warn: #c2410c;
  --danger: #b42318;
  --ok: #027a48;
  --soft: #eff6ff;
  --shadow: 0 14px 28px rgba(20, 31, 45, 0.07);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  overflow-x: hidden;
}

.auth-screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: var(--bg);
}

.auth-ok .auth-screen {
  display: none;
}

.auth-box {
  width: min(430px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 22px;
}

.auth-box p,
.auth-muted {
  color: var(--muted);
}

.google-login {
  width: 100%;
  min-height: 46px;
  margin-top: 16px;
  border-color: #cfd8e6;
  background: #fff;
  font-weight: 900;
}

.auth-secondary-login {
  min-height: 38px;
  color: var(--muted);
  background: #f8fafc;
  font-size: 13px;
  font-weight: 700;
}

.auth-separator {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
  margin: 14px 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.auth-separator::before,
.auth-separator::after {
  content: "";
  height: 1px;
  background: var(--line);
}

.auth-tabs {
  display: flex;
  gap: 6px;
  margin: 16px 0 12px;
  padding: 4px;
  background: #eef2f6;
  border-radius: 8px;
}

.auth-tabs button {
  flex: 1;
  border-color: transparent;
  background: transparent;
}

.auth-tabs button.active {
  background: #fff;
  border-color: var(--line);
}

.auth-form {
  display: grid;
  gap: 10px;
}

.auth-form .code {
  text-align: center;
  font-size: 20px;
  letter-spacing: 3px;
}

.auth-error,
.auth-success {
  min-height: 18px;
  font-size: 13px;
  font-weight: 700;
}

.auth-error {
  color: var(--danger);
}

.auth-success {
  color: var(--ok);
}

button,
input,
select {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  border-radius: 8px;
  min-height: 38px;
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
}

button:hover {
  border-color: var(--accent);
}

input,
select {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 11px;
  background: #fff;
  min-width: 0;
}

.icon {
  width: 20px;
  height: 20px;
  border-radius: 6px;
  display: inline-grid;
  place-items: center;
  border: 1px solid currentColor;
  font-size: 10px;
  font-weight: 800;
  line-height: 1;
}

.app-shell {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  width: 100%;
  max-width: 100vw;
  height: 100dvh;
  overflow: hidden;
}

body:not(.auth-ok) .app-shell {
  visibility: hidden;
}

.sidebar {
  position: sticky;
  top: 0;
  align-self: start;
  background: var(--nav);
  color: #fff;
  padding: 22px 16px;
  border-right: 1px solid #0b1220;
  height: 100vh;
  overflow-y: auto;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 30px;
}

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: #ffffff;
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.18);
  overflow: hidden;
}

.brand-mark img {
  width: 100%;
  height: 100%;
  display: block;
}

.brand span,
.topbar p,
.section-head p {
  display: block;
  color: var(--muted);
  margin: 4px 0 0;
}

.sidebar .brand span {
  color: #b7c2cf;
}

.nav {
  display: grid;
  gap: 8px;
}

.admin-user-switcher {
  position: sticky;
  bottom: 0;
  display: grid;
  gap: 8px;
  margin-top: 14px;
  padding: 10px;
  border: 1px solid rgba(148, 163, 184, 0.32);
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.94);
  box-shadow: 0 -10px 24px rgba(0, 0, 0, 0.18);
}

.admin-user-switcher span,
.admin-user-switcher strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.admin-user-switcher span {
  color: #93a4b8;
  font-size: 10px;
  font-weight: 900;
  text-transform: uppercase;
}

.admin-user-switcher strong {
  color: #fff;
  font-size: 12px;
}

.admin-user-switcher select,
.admin-user-switcher button {
  width: 100%;
  min-height: 34px;
  font-size: 12px;
}

.admin-user-switcher button {
  border-color: rgba(148, 163, 184, 0.3);
  background: rgba(255, 255, 255, 0.06);
  color: #dbe4ee;
}

body:not([data-master-session="true"]) .admin-user-switcher {
  display: none;
}

.admin-user-switcher[hidden] {
  display: none;
}

.nav-item {
  width: 100%;
  justify-content: flex-start;
  background: transparent;
  color: #dbe4ee;
  border-color: transparent;
}

.nav-item.active {
  background: var(--nav-soft);
  border-color: #374151;
}

.nav-item strong {
  margin-left: auto;
  background: var(--danger);
  color: #fff;
  min-width: 22px;
  height: 22px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  font-size: 12px;
}

.agency-nav-agents {
  display: none;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid rgba(55, 65, 81, 0.72);
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
}

body[data-active-view="agency"] .agency-nav-agents {
  display: grid;
  gap: 7px;
}

.agency-nav-agent-block {
  display: grid;
  gap: 5px;
}

.agency-client-group {
  display: grid;
  gap: 5px;
  border: 1px solid rgba(55, 65, 81, 0.66);
  border-radius: 8px;
  padding: 6px;
  background: rgba(15, 23, 42, 0.38);
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
}

.agency-client-toggle {
  width: 100%;
  min-height: 32px;
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  padding: 5px 6px;
  border-radius: 7px;
  border-color: transparent;
  background: rgba(31, 41, 55, 0.72);
  color: #eef5ff;
  text-align: left;
}

.agency-client-toggle span {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  display: grid;
  place-items: center;
  background: #2563eb;
  font-size: 15px;
  font-weight: 900;
}

.agency-client-toggle strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
}

.agency-client-toggle small {
  min-width: 22px;
  height: 22px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: rgba(148, 163, 184, 0.2);
  color: #cbd5e1;
  font-size: 11px;
  font-weight: 900;
}

.agency-client-items {
  display: grid;
  gap: 5px;
}

.agency-client-group.collapsed .agency-client-items {
  display: none;
}

.agency-nav-agent,
.agency-nav-group {
  width: 100%;
  min-height: 58px;
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 9px;
  align-items: center;
  justify-content: stretch;
  padding: 8px;
  border-radius: 8px;
  border-color: transparent;
  background: transparent;
  color: #dbe4ee;
  text-align: left;
}

.agency-nav-agent:hover,
.agency-nav-group:hover,
.agency-nav-agent.active-agent,
.agency-nav-group.selected {
  background: var(--nav-soft);
  border-color: #374151;
  color: #fff;
}

.agency-nav-agent .module-mark,
.agency-nav-group .module-mark {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: #2563eb;
  color: #fff;
}

.unread-anchor {
  position: relative;
}

.agent-unread-badge {
  position: absolute;
  top: -7px;
  right: -7px;
  min-width: 17px;
  height: 17px;
  padding: 0 5px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #0b1220;
  border-radius: 999px;
  background: #e11d48;
  color: #fff;
  font-size: 10px;
  font-weight: 900;
  line-height: 1;
}

.agency-nav-agent .agency-agent-main,
.agency-nav-group .agency-agent-main {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.agency-nav-agent strong,
.agency-nav-agent small,
.agency-nav-group strong,
.agency-nav-group small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.agency-nav-agent strong,
.agency-nav-group strong {
  font-size: 13px;
  line-height: 1.2;
}

.agency-nav-agent small,
.agency-nav-group small {
  color: #b7c2cf;
  font-size: 11px;
  line-height: 1.2;
}

.agency-nav-status {
  display: none;
}

.chat-context {
  margin-top: -7px;
  color: #8493a8;
  font-size: 12px;
  line-height: 1.35;
}

.agency-nav-groups {
  margin: 0 0 2px 43px;
}

.agency-nav-groups button {
  min-height: 26px;
  padding: 4px 8px;
  font-size: 11px;
}

.agency-nav-empty {
  margin: 0;
  padding: 10px 8px;
  color: #b7c2cf;
  font-size: 12px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.agency-nav-section-title,
.sidebar-tasks-title {
  margin: 12px 2px 6px;
  color: #93a4b8;
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.sidebar-tasks {
  display: grid;
  gap: 6px;
  margin-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  padding-top: 6px;
}

.sidebar-task-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 28px;
  gap: 5px;
  align-items: stretch;
}

.sidebar-task-row > button:first-child {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 9px;
  align-items: center;
  min-width: 0;
  min-height: 58px;
  justify-content: flex-start;
  text-align: left;
  border-color: transparent;
  background: transparent;
  color: #dbe4ee;
  padding: 8px;
}

.sidebar-task-row.selected > button:first-child {
  border-color: #374151;
  background: var(--nav-soft);
  color: #fff;
}

.sidebar-task-row strong,
.sidebar-task-row small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-task-row strong {
  font-size: 12px;
}

.sidebar-task-row small {
  color: #b7c2cf;
  font-size: 10px;
}

.sidebar-task-close {
  min-height: 58px;
  padding: 0;
  border-color: rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.06);
  color: #cbd5e1;
  font-weight: 900;
}

.job-line {
  display: block;
  margin-top: 7px;
  color: rgba(255, 255, 255, 0.72);
  font-size: 11px;
  font-weight: 800;
}

body:not([data-master-session="true"]) .master-only {
  display: none;
}

body[data-role="client"] .master-only {
  display: none;
}

body[data-role="employee"] .employee-master-allowed {
  display: inline-flex;
}

body[data-role="employee"] #masterView > .section-head,
body[data-role="employee"] #contractForm,
body[data-role="employee"] #voucherForm {
  display: none;
}

main {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  height: 100dvh;
  padding: 22px 24px 28px;
  overflow: auto;
  overflow-x: hidden;
}

.topbar,
.section-head,
.panel-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.topbar {
  margin-bottom: 18px;
  min-height: 58px;
}

h1,
h2,
h3 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 26px;
}

h2 {
  font-size: 22px;
}

h3 {
  font-size: 16px;
}

.eyebrow {
  display: inline-block;
  margin-bottom: 5px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.status-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.status,
.pill {
  border-radius: 999px;
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.status.ok,
.pill.ok {
  background: #ecfdf3;
  color: var(--ok);
}

.status.muted,
.pill.muted {
  background: #eef2f6;
  color: #475467;
}

.pill.danger {
  background: #fef3f2;
  color: var(--danger);
}

.view {
  display: none;
}

.active-view {
  display: block;
  width: 100%;
  min-width: 0;
}

.hero-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 150px;
  margin-bottom: 16px;
  padding: 22px;
  border: 1px solid #cfd8e6;
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(37, 99, 235, 0.10), rgba(2, 122, 72, 0.08)),
    #fff;
  box-shadow: var(--shadow);
}

.hero-panel h2 {
  font-size: 30px;
}

.hero-panel p {
  max-width: 720px;
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

.hero-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.install-ready {
  border-color: var(--ok);
  color: var(--ok);
}

.install-guide {
  margin: -4px 0 18px;
  border: 1px solid #b9d9ff;
  border-radius: 8px;
  background: #eef6ff;
  padding: 12px 14px;
}

.install-guide p {
  margin: 5px 0 0;
  color: var(--muted);
  line-height: 1.4;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.kpi-card,
.mini-metrics article {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 14px;
  box-shadow: 0 8px 18px rgba(20, 31, 45, 0.05);
}

.kpi-card span,
.mini-metrics span {
  display: block;
  color: #64748b;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.kpi-card strong,
.mini-metrics strong {
  display: block;
  margin-top: 8px;
  font-size: 25px;
  line-height: 1.1;
}

.kpi-card p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.mini-metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(86px, 1fr));
  gap: 10px;
  min-width: 320px;
}

.inline-form {
  display: grid;
  grid-template-columns: minmax(120px, 160px) minmax(160px, 220px) auto;
  gap: 8px;
}

.task-create-form {
  grid-template-columns: minmax(190px, 1.25fr) minmax(160px, 1fr) minmax(150px, .85fr) auto;
  width: min(900px, 100%);
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.task-create-form input,
.task-create-form select {
  min-height: 40px;
}

.contract-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 8px;
  margin-bottom: 16px;
}

.contract-form button {
  min-width: 150px;
}

.compact-action,
.icon-action {
  min-height: 32px;
  padding: 6px 10px;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 800;
}

.operation-form {
  display: grid;
  margin-top: 8px;
}

.operation-form input {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  font: inherit;
}

.master-operations-panel .operation-form {
  max-width: 360px;
}

.form-status {
  align-self: center;
  color: #027a48;
  font-size: 13px;
  font-weight: 800;
}

.is-hidden {
  display: none !important;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(310px, 0.75fr);
  gap: 16px;
  margin-top: 18px;
}

.master-main-layout {
  grid-template-columns: minmax(0, 1fr);
  width: 100%;
}

.master-operations-panel {
  margin-top: 16px;
  padding: 12px 14px;
}

.agency-chat-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  justify-content: center;
  align-items: stretch;
  gap: 12px;
  height: clamp(560px, calc(100vh - 330px), 780px);
  min-height: 0;
  margin-top: 18px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 16px;
  width: 100%;
  min-width: 0;
}

.agent-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.agency-chat-panel,
.agency-tasks-panel {
  min-height: 0;
}

.agency-agent-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
  padding: 14px;
  background: var(--nav);
  border-color: #0b1220;
  color: #fff;
  box-shadow: 0 18px 34px rgba(9, 16, 29, 0.20);
}

.agency-agent-panel .panel-title h3 {
  color: #fff;
}

.agency-agent-panel .pill.ok {
  background: rgba(52, 211, 153, 0.14);
  color: #a7f3d0;
}

.agency-agent-panel .agent-grid {
  grid-template-columns: 1fr;
  grid-auto-rows: max-content;
  align-content: start;
  gap: 8px;
  overflow-y: auto;
  padding-right: 3px;
}

.agent-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  display: grid;
  gap: 12px;
  min-height: 192px;
  background: #fff;
}

.agent-card.active-agent {
  border-color: var(--accent);
  background: var(--soft);
}

.agent-card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.module-mark {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: #111827;
  color: #fff;
  font-size: 12px;
  font-weight: 900;
}

.agent-card.locked-agent {
  opacity: 0.74;
}

.agent-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.agent-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  align-items: center;
  margin-top: auto;
}

.task-list {
  display: grid;
  gap: 8px;
}

.task-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 38px;
  gap: 8px;
  align-items: stretch;
}

.task-card-main {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  min-height: 58px;
  justify-content: stretch;
  text-align: left;
  background: #fff;
}

.task-card.active-task .task-card-main {
  border-color: var(--accent);
  background: var(--soft);
}

.task-card-main strong,
.task-card-main small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.task-card-main small {
  color: var(--muted);
  font-size: 12px;
}

.task-close {
  min-height: 58px;
  padding: 0;
  border-color: #fda29b;
  background: #fef3f2;
  color: var(--danger);
  font-weight: 900;
}

.master-agent-card .agent-actions {
  gap: 0;
}

.master-agent-card .agent-actions button {
  min-height: 28px;
  padding: 5px 8px;
  font-size: 12px;
}

.agency-agent-card {
  min-height: 0;
  gap: 8px;
  padding: 10px;
  align-content: start;
  background: var(--nav-soft);
  border-color: #374151;
  color: #fff;
}

.agency-agent-card .agent-card-top {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) 38px;
  align-items: center;
}

.agency-agent-card .module-mark {
  width: 34px;
  height: 34px;
  background: #2563eb;
  border: 1px solid rgba(255, 255, 255, 0.22);
}

.agency-agent-main {
  min-width: 0;
}

.agency-agent-main h3 {
  margin: 0;
  font-size: 15px;
  line-height: 1.2;
  color: #fff;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.agency-agent-main p {
  margin-top: 3px;
  font-size: 12px;
  line-height: 1.25;
  color: #b7c2cf;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.agency-agent-card .pill {
  justify-self: start;
  font-size: 11px;
  padding: 4px 8px;
  background: rgba(255, 255, 255, 0.10);
  color: #dbe4ee;
}

.agents-ia-hidden-form {
  display: none;
}

.agents-ia-panel {
  min-height: 420px;
}

.agents-ia-summary {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px 14px;
  align-items: center;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.agents-ia-summary strong,
.agents-ia-summary span {
  min-width: 0;
}

.agents-ia-summary span {
  color: var(--muted);
  font-size: 13px;
}

.agents-ia-summary b {
  grid-row: span 2;
  font-size: 18px;
  color: var(--accent);
}

.agents-ia-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.agents-ia-card {
  display: grid;
  gap: 8px;
  min-height: 190px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.agents-ia-card p,
.agents-ia-card small {
  margin: 0;
  color: var(--muted);
  line-height: 1.35;
}

.agents-ia-card small {
  font-size: 12px;
}

.agents-ia-card b {
  margin-top: auto;
  font-size: 13px;
}

.icon-chat-button {
  width: 38px;
  height: 38px;
  min-height: 38px;
  padding: 0;
  display: inline-grid;
  place-items: center;
}

.group-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 2px;
}

.group-actions button {
  min-height: 30px;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 800;
  color: #dbe4ee;
  border-color: #374151;
  background: #111827;
}

.group-actions button.selected {
  border-color: var(--accent);
  color: #fff;
  background: #2563eb;
}

.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.primary:hover {
  background: var(--accent-strong);
}

.messages {
  height: 300px;
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 10px;
  padding: 12px 0;
}

.side-panel {
  align-self: start;
}

.agency-side-chat {
  position: static;
  top: auto;
}

.agency-side-chat .messages {
  height: 420px;
}

.agency-chat-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  margin-top: 0;
  position: static;
  padding: 14px;
  align-self: stretch;
}

.agency-chat-panel .messages {
  height: auto;
  min-height: 0;
  padding: 16px 6px 16px 0;
  align-content: end;
  background:
    linear-gradient(rgba(255, 255, 255, 0.88), rgba(255, 255, 255, 0.88)),
    radial-gradient(circle at top right, #dceafe, transparent 34%),
    #f8fafc;
  border: 1px solid #edf1f6;
  border-radius: 8px;
  padding-left: 14px;
  margin: 10px 0;
}

.agency-owned-panel {
  align-self: stretch;
  min-height: 0;
  overflow: auto;
  margin-top: 0;
  padding: 14px;
}

.owned-agent-list {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.owned-agent-item {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  gap: 9px;
  align-items: center;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.owned-agent-item .module-mark {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: #2563eb;
  color: #fff;
}

.owned-agent-item strong,
.owned-agent-item small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.owned-agent-item strong {
  font-size: 13px;
}

.owned-agent-item small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.agency-tasks-panel {
  align-self: stretch;
  overflow: hidden;
  margin-top: 0;
  padding: 14px;
}

.agency-tasks-panel .activity-list {
  max-height: calc(100% - 42px);
  overflow-y: auto;
  padding-right: 4px;
  gap: 8px;
}

.agency-tasks-panel .panel-title .pill {
  display: none;
}

.agency-tasks-panel .activity-item {
  padding: 9px;
}

.agency-tasks-panel .activity-item strong {
  font-size: 13px;
}

.agency-tasks-panel .activity-item p {
  font-size: 12px;
}

.workspace-chat {
  margin-top: 16px;
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

#clientView .workspace-chat {
  display: grid;
  grid-template-rows: auto minmax(260px, 1fr) auto;
  height: clamp(430px, calc(100dvh - 390px), 620px);
  min-height: 0;
}

#clientView .workspace-chat .messages {
  height: auto;
  min-height: 0;
}

.activity-list {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  overflow-x: auto;
  padding-bottom: 4px;
  scroll-snap-type: x proximity;
}

.activity-item {
  display: grid;
  grid-template-columns: 10px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.operation-chip {
  flex: 0 0 min(260px, 82vw);
  min-height: 58px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  scroll-snap-align: start;
}

.operation-chip strong,
.operation-chip span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.operation-chip strong {
  font-size: 13px;
}

.operation-chip span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.activity-item > span {
  width: 10px;
  height: 10px;
  margin-top: 5px;
  border-radius: 999px;
  background: var(--accent);
}

.activity-item strong {
  display: block;
  font-size: 14px;
}

.activity-item p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.messages:empty::before {
  content: "Todavia no hay mensajes.";
  color: var(--muted);
}

.msg {
  border-radius: 8px;
  padding: 10px 12px;
  max-width: 92%;
  line-height: 1.4;
  overflow-wrap: anywhere;
  white-space: normal;
}

.msg.user {
  justify-self: end;
  background: #e6f4f1;
}

.msg.agent,
.msg.system {
  justify-self: start;
  background: #f2f4f7;
}

.msg.work {
  padding: 5px 8px;
  font-size: 11px;
  line-height: 1.2;
  color: var(--muted);
  background: transparent;
  border: 1px dashed var(--line);
  opacity: 0.78;
}

.typing-text {
  vertical-align: middle;
}

.typing-dots {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin-left: 6px;
  vertical-align: middle;
}

.typing-dots span {
  width: 5px;
  height: 5px;
  border-radius: 999px;
  background: currentColor;
  opacity: 0.35;
  animation: typingPulse 1.15s infinite ease-in-out;
}

.typing-dots span:nth-child(2) {
  animation-delay: 0.16s;
}

.typing-dots span:nth-child(3) {
  animation-delay: 0.32s;
}

@keyframes typingPulse {
  0%,
  80%,
  100% {
    transform: translateY(0);
    opacity: 0.35;
  }
  40% {
    transform: translateY(-4px);
    opacity: 1;
  }
}

.chat-form {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) 44px;
  gap: 8px;
  align-items: center;
  min-width: 0;
}

.file-input {
  display: none;
}

.attach-button {
  white-space: nowrap;
  font-weight: 900;
  color: var(--accent-strong);
  background: var(--soft);
  border-color: #b8cdf8;
}

.attachment-status {
  grid-column: 1 / -1;
  min-height: 16px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.message-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 7px;
}

.message-attachments a,
.message-attachments span {
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 4px 7px;
  color: var(--accent-strong);
  background: #fff;
  font-size: 12px;
  font-weight: 800;
  text-decoration: none;
  overflow-wrap: anywhere;
}

.access-table {
  margin-top: 14px;
  overflow: auto;
}

.master-client-search {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 7px 10px;
  align-items: center;
  margin-bottom: 12px;
}

.master-client-search label {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.master-client-search input {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  font: inherit;
  font-size: 14px;
  background: #fff;
}

.master-client-search span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}

.master-client-list {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}

.client-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.client-filter button,
.client-detail-actions button {
  min-height: 34px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  border-radius: 8px;
  padding: 0 12px;
  font-size: 12px;
  font-weight: 900;
}

.client-filter button.selected {
  border-color: var(--accent);
  background: var(--soft);
  color: var(--accent);
}

.client-row {
  width: 100%;
  min-height: 58px;
  justify-content: space-between;
  text-align: left;
  background: #fff;
}

.client-row.selected {
  border-color: var(--accent);
  background: var(--soft);
}

.client-row span:first-child {
  display: grid;
  gap: 3px;
}

.client-row-state {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  white-space: nowrap;
}

.client-row small,
.client-detail-head p,
.promo-box p {
  color: var(--muted);
}

.master-client-detail {
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.client-detail-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 10px;
}

.client-detail-head h3 {
  margin-bottom: 5px;
}

.client-contact,
.client-note {
  margin: 3px 0;
  font-size: 14px;
  line-height: 1.3;
}

.client-compact-data {
  display: grid;
  gap: 3px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
}

.client-compact-data span {
  overflow-wrap: anywhere;
}

.client-compact-data strong {
  color: var(--text);
  font-size: 12px;
}

.client-detail-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  min-width: 170px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.client-detail-actions button {
  color: var(--text);
  width: 100%;
}

.client-detail-actions .danger-action {
  border-color: #fda29b;
  background: #fef3f2;
  color: var(--danger);
}

.client-detail-actions .danger-action:hover {
  border-color: var(--danger);
  background: #fee4e2;
}

.promo-box,
.permission-note {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  padding: 12px;
}

.client-timeline {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
  margin: 10px 0 12px;
}

.timeline-step {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-areas:
    "dot title"
    "dot meta";
  align-items: center;
  column-gap: 8px;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: #fff;
}

.timeline-step .status-dot {
  grid-area: dot;
}

.timeline-step strong {
  grid-area: title;
  font-size: 12px;
}

.timeline-step small {
  grid-area: meta;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.25;
}

.master-agent-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(118px, 1fr));
  gap: 7px;
  margin-top: 12px;
}

.master-agent-card {
  display: grid;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: #fff;
}

.master-agent-card.enabled {
  border-color: rgba(2, 122, 72, 0.35);
  background: #fbfffd;
}

.master-agent-card.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.10);
}

.master-agent-title {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 5px;
  align-items: center;
}

.master-agent-title strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
}

.status-dot {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  box-shadow: 0 0 0 3px rgba(148, 163, 184, 0.16);
}

.status-dot.active {
  background: #039855;
}

.status-dot.pending {
  background: #f79009;
}

.status-dot.inactive {
  background: #d92d20;
}

.status-word {
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0;
}

.status-word.active {
  color: #027a48;
}

.status-word.inactive {
  color: #b42318;
}

.master-agent-card p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.permission-note {
  margin-top: 12px;
  background: #fff;
}

.permission-note p {
  margin: 5px 0 0;
  color: var(--muted);
  line-height: 1.4;
}

.client-connections-panel {
  display: grid;
  gap: 10px;
  margin: 12px 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.connection-list {
  display: grid;
  gap: 7px;
}

.connection-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  min-height: 44px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.connection-item strong,
.connection-item small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.connection-item strong {
  font-size: 13px;
}

.connection-item small {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.3;
}

.connection-form {
  display: grid;
  grid-template-columns: minmax(130px, 0.8fr) minmax(170px, 1.1fr) auto auto;
  gap: 8px;
  align-items: end;
}

.connection-form label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
}

.connection-form select,
.connection-form input[type="text"] {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  background: #fff;
  color: var(--text);
  font: inherit;
  font-size: 13px;
}

.connection-form .notify-check {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font-size: 11px;
}

.connection-form .notify-check input {
  width: 14px;
  height: 14px;
  min-height: 0;
}

.connection-form button {
  min-height: 36px;
}

.compact-empty {
  padding: 10px;
}

.permission-switches {
  display: grid;
  grid-template-columns: 1fr;
  gap: 3px;
}

.permission-switches label {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 5px;
  min-height: 22px;
  padding: 0;
  border: 0;
  border-radius: 7px;
  background: transparent;
  font-size: 11px;
  font-weight: 700;
}

.permission-switches input {
  width: 14px;
  height: 14px;
  min-height: 0;
}

.permission-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0;
}

.master-chat-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.master-chat-form {
  margin-top: 10px;
}

.permission-summary span {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
  background: #fff;
  color: #475467;
  font-size: 12px;
  font-weight: 800;
}

.master-messages {
  height: 220px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #f8fafc;
}

.modal-open {
  overflow: hidden;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(15, 23, 42, 0.54);
}

.modal-backdrop[hidden] {
  display: none;
}

.connections-modal {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  width: min(620px, 100%);
  height: min(760px, calc(100dvh - 32px));
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 22px 70px rgba(15, 23, 42, 0.28);
}

.confirm-modal {
  display: grid;
  gap: 12px;
  width: min(390px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 18px;
  box-shadow: 0 22px 70px rgba(15, 23, 42, 0.28);
}

.confirm-modal p {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.confirm-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.confirm-actions button {
  min-height: 42px;
}

.connections-modal-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
  background: #f8fafc;
}

.connections-modal-head h3 {
  margin: 2px 0 0;
  font-size: 16px;
}

.connections-modal iframe {
  width: 100%;
  height: 100%;
  border: 0;
  background: #fff;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 860px;
}

@media (max-width: 1180px) and (min-width: 981px) {
  .app-shell {
    grid-template-columns: 232px minmax(0, 1fr);
  }

  .sidebar {
    padding: 18px 14px;
  }

  main {
    padding: 18px 16px 24px;
  }

  .hero-panel {
    padding: 18px;
  }

  .access-table,
  .master-client-detail,
  .client-connections-panel,
  .master-agent-grid,
  .workspace-chat {
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }

  .connection-form {
    grid-template-columns: minmax(150px, 1fr) minmax(190px, 1fr);
  }

  .connection-form .notify-check,
  .connection-form button,
  .connection-form .form-status {
    width: 100%;
  }

  .master-agent-grid {
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  }
}

@media (max-width: 1366px) and (min-width: 981px) {
  .app-shell {
    grid-template-columns: 250px minmax(0, 1fr);
  }

  main {
    padding: 22px 24px 28px;
  }

  .topbar,
  .section-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .hero-panel {
    align-items: flex-start;
    flex-direction: column;
    padding: 20px;
  }

  .mini-metrics {
    min-width: 0;
    width: 100%;
    grid-template-columns: repeat(auto-fit, minmax(86px, 1fr));
  }

  .access-table,
  .master-client-detail,
  .client-connections-panel,
  .master-agent-grid,
  .workspace-chat {
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }

  .connection-form {
    grid-template-columns: minmax(150px, 1fr) minmax(190px, 1fr);
  }

  .connection-form .notify-check,
  .connection-form button,
  .connection-form .form-status {
    width: 100%;
  }

  .master-agent-grid {
    grid-template-columns: repeat(auto-fill, minmax(112px, 1fr));
  }
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px 8px;
  text-align: left;
  vertical-align: middle;
  font-size: 14px;
}

th {
  color: #475467;
  font-size: 12px;
  text-transform: uppercase;
}

.check-cell {
  text-align: center;
}

.check-cell input {
  width: 18px;
  height: 18px;
  min-height: 0;
}

.check-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 3px 10px 3px 0;
  white-space: nowrap;
}

.check-label input {
  width: 16px;
  height: 16px;
  min-height: 0;
}

.empty-state {
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: #f8fafc;
  padding: 16px;
}

.empty-state p {
  margin: 6px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

.mirror-list,
.employee-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.mirror-item,
.employee-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.notification-unread {
  border-color: rgba(219, 63, 63, .38);
  background: rgba(255, 242, 242, .72);
}

.employee-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.employee-access-layout {
  display: grid;
  grid-template-columns: minmax(180px, 260px) minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.employee-access-layout.single {
  grid-template-columns: 1fr;
}

.employee-picker {
  display: grid;
  gap: 8px;
}

.employee-row {
  width: 100%;
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  text-align: left;
}

.employee-row.selected {
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .1);
}

.employee-row span:first-child {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.employee-row strong,
.employee-row small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.employee-row small {
  color: var(--muted);
}

.employee-permissions {
  display: grid;
  gap: 12px;
  min-width: 0;
}

.employee-agent-grid {
  margin-top: 0;
}

.employee-agent-card p {
  min-height: 38px;
}

.employee-client-grid {
  margin-top: 0;
}

.employee-client-card p {
  min-height: 20px;
}

.employee-client-card .master-agent-title {
  grid-template-columns: auto minmax(0, 1fr);
}

.employee-client-summary {
  display: grid;
  gap: 10px;
}

.employee-client-summary-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(180px, 0.65fr);
  gap: 12px;
  align-items: start;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fff;
}

.employee-client-summary-card.selected {
  border-color: var(--accent);
  background: var(--soft);
}

.employee-client-summary-card h3,
.employee-client-summary-card p {
  margin: 0;
}

.employee-client-summary-card p {
  color: var(--muted);
  overflow-wrap: anywhere;
}

.employee-subhead {
  margin-top: 4px;
}

.list-subtitle {
  margin-top: 8px;
}

.mirror-item p,
.employee-item p {
  color: var(--muted);
  margin: 4px 0 0;
  line-height: 1.4;
}

@media (max-width: 980px) {
  body {
    overflow: auto;
  }

  .app-shell {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 100dvh;
    overflow: visible;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 5;
    height: auto;
    min-height: 0;
    max-height: 42vh;
    padding: 12px;
  }

  .brand {
    margin-bottom: 12px;
  }

  .nav {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .admin-user-switcher {
    position: static;
    grid-template-columns: minmax(0, 1fr) minmax(180px, 260px) auto;
    align-items: center;
    margin-top: 10px;
  }

  .nav-item {
    justify-content: center;
  }

  .layout,
  .agency-chat-shell,
  .employee-access-layout,
  .connection-form,
  .inline-form,
  .contract-form,
  .employee-client-summary-card {
    grid-template-columns: 1fr;
  }

  .agency-chat-shell {
    height: auto;
    gap: 14px;
  }

  .agency-agent-panel .agent-grid {
    max-height: 320px;
  }

  .agency-chat-panel {
    min-height: 560px;
  }

  #clientView .workspace-chat {
    height: min(620px, calc(100dvh - 210px));
    min-height: 500px;
  }

  .agency-tasks-panel .activity-list {
    max-height: 280px;
  }

  .hero-panel {
    align-items: flex-start;
    flex-direction: column;
  }

  .kpi-grid,
  .mini-metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    min-width: 0;
    width: 100%;
  }

  .topbar,
  .section-head,
  .panel-title,
  .client-detail-head {
    align-items: flex-start;
    flex-direction: column;
  }

  main {
    height: auto;
    overflow: visible;
    padding: 16px;
  }

  .messages {
    height: 340px;
  }

  .agency-chat-panel .messages {
    height: auto;
  }

  .agency-agent-main p {
    white-space: normal;
  }

  .client-detail-actions {
    width: 100%;
  }
}

@media (max-width: 620px) {
  .nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .admin-user-switcher {
    grid-template-columns: 1fr;
  }

  .hero-panel h2 {
    font-size: 24px;
  }

  .kpi-grid,
  .mini-metrics {
    grid-template-columns: 1fr;
  }

  .agent-actions,
  .chat-form {
    grid-template-columns: 1fr;
  }

  .agency-chat-panel {
    min-height: 500px;
  }

  #clientView .workspace-chat {
    height: auto;
    min-height: 500px;
  }

  .agency-agent-card .agent-card-top {
    grid-template-columns: 34px minmax(0, 1fr);
  }

  .agency-agent-card .icon-chat-button {
    grid-column: 1 / -1;
    width: 100%;
  }

  .modal-backdrop {
    padding: 8px;
  }

  .connections-modal {
    height: calc(100dvh - 16px);
  }

  .master-client-search {
    grid-template-columns: 1fr;
  }

  .master-client-search span {
    text-align: left;
  }
}


/* ClawChat Copi Fase 1: modo movil/PC + latencia */
.copi-mode-toggle{display:flex;align-items:center;gap:6px;flex-wrap:wrap;margin-left:auto;background:#eff6ff;border:1px solid #bfdbfe;border-radius:999px;padding:5px 7px;color:#1e3a8a;font-size:12px;font-weight:800}
.copi-mode-toggle button{border:0;border-radius:999px;background:#dbeafe;color:#1e40af;padding:7px 10px;font-weight:850;cursor:pointer}
.copi-mode-toggle button.active{background:#2563eb;color:#fff;box-shadow:0 8px 20px rgba(37,99,235,.22)}
.latency-panel{font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;background:#ecfeff!important;color:#155e75!important;border-color:#a5f3fc!important;white-space:nowrap}
body.copi-mobile-mode .app-shell{grid-template-columns:1fr;min-height:100dvh}
body.copi-mobile-mode .sidebar{position:sticky;top:0;z-index:20;width:100%;height:auto;min-height:0;display:block;border-right:0;border-bottom:1px solid #dbeafe;padding:10px 12px;background:rgba(255,255,255,.96);backdrop-filter:blur(12px)}
body.copi-mobile-mode .sidebar .brand{margin-bottom:8px}
body.copi-mobile-mode .sidebar .nav{display:flex;overflow-x:auto;gap:8px;padding-bottom:4px}
body.copi-mobile-mode .sidebar .nav-item{white-space:nowrap;min-width:max-content;padding:9px 11px;border-radius:999px}
body.copi-mobile-mode .agency-nav-agents,body.copi-mobile-mode .sidebar-tasks,body.copi-mobile-mode .admin-user-switcher{display:none!important}
body.copi-mobile-mode main{padding:10px;min-width:0}
body.copi-mobile-mode .topbar{position:sticky;top:68px;z-index:15;display:block;padding:12px;border-radius:18px;margin-bottom:10px;background:rgba(255,255,255,.96);backdrop-filter:blur(12px)}
body.copi-mobile-mode .topbar h1{font-size:20px;margin:2px 0}
body.copi-mobile-mode .topbar p{font-size:13px;margin:0}
body.copi-mobile-mode .status-strip{margin-top:10px;gap:6px;overflow-x:auto;flex-wrap:nowrap}
body.copi-mobile-mode .hero-panel,body.copi-mobile-mode .client-workspace,body.copi-mobile-mode .agency-chat-shell,body.copi-mobile-mode .master-grid{grid-template-columns:1fr!important}
body.copi-mobile-mode .panel,body.copi-mobile-mode .hero-panel{border-radius:18px;padding:14px}
body.copi-mobile-mode .messages,body.copi-mobile-mode .agency-chat-panel .messages{max-height:calc(100dvh - 280px);min-height:300px}
body.copi-mobile-mode .chat-form{position:sticky;bottom:0;background:rgba(255,255,255,.96);padding-top:8px;border-top:1px solid #e2e8f0}
@media (min-width:981px){body.copi-pc-mode .app-shell{grid-template-columns:280px minmax(0,1fr)}}
@media (max-width:760px){body:not(.copi-pc-mode){ } .copi-mode-toggle{width:100%;justify-content:flex-start;margin-top:8px}}


/* === ClawChat Copi UI v1 · frontend polish 2026-09-17 === */
:root { --bg:#f6f8fb; --panel:#ffffff; --ink:#111827; --muted:#64748b; --line:#dbe3ef; --accent:#2563eb; --accent-strong:#1d4ed8; --accent-soft:#eff6ff; --nav:#f8fafc; --nav-soft:#eef2f7; --focus:#1d4ed8; --shadow:0 18px 50px rgba(15,23,42,.08); --radius-lg:22px; --radius-md:16px; --composer-h:72px; }
html { font-size:16px; }
body { background:radial-gradient(circle at top left,#eef6ff 0,#f7f9fc 38%,#f6f8fb 100%); color:var(--ink); }
button,input,select,textarea { font:inherit; }
button,input,select { border-radius:12px; }
button:focus-visible,input:focus-visible,select:focus-visible,a:focus-visible,[tabindex]:focus-visible { outline:3px solid rgba(37,99,235,.35); outline-offset:2px; box-shadow:0 0 0 1px var(--focus); }
button:hover { transform:translateY(-1px); box-shadow:0 8px 20px rgba(37,99,235,.10); }
button:disabled { opacity:.58; cursor:not-allowed; transform:none; box-shadow:none; }
.primary,button.primary,.chat-form button[type="submit"] { background:var(--accent); border-color:var(--accent); color:#fff; font-weight:800; }
.primary:hover,button.primary:hover,.chat-form button[type="submit"]:hover { background:var(--accent-strong); border-color:var(--accent-strong); }
.app-shell { grid-template-columns:280px minmax(0,1fr); background:transparent; }
.sidebar { background:rgba(248,250,252,.94); color:var(--ink); border-right:1px solid var(--line); padding:18px 14px; backdrop-filter:blur(18px); }
.brand { margin-bottom:18px; padding:10px; border-radius:18px; background:#fff; border:1px solid var(--line); box-shadow:0 10px 24px rgba(15,23,42,.05); }
.brand strong { letter-spacing:-.02em; }
.brand span { color:var(--muted); font-size:12px; }
.nav { display:grid; gap:8px; }
.nav-item { width:100%; justify-content:flex-start; min-height:44px; border:1px solid transparent; background:transparent; color:#334155; font-weight:750; }
.nav-item:hover { background:#fff; border-color:var(--line); }
.nav-item.active { color:var(--accent-strong); background:var(--accent-soft); border-color:#bfdbfe; box-shadow:inset 3px 0 0 var(--accent); }
.agency-nav-agents,.sidebar-tasks { margin-top:10px; display:grid; gap:6px; }
.agency-nav-agents:empty,.sidebar-tasks:empty { display:none; }
main { height:100dvh; overflow:auto; padding:22px; scroll-behavior:smooth; }
.topbar { position:sticky; top:0; z-index:8; margin:-22px -22px 18px; padding:18px 22px; background:rgba(246,248,251,.92); border-bottom:1px solid rgba(219,227,239,.85); backdrop-filter:blur(18px); }
.topbar h1 { margin:3px 0 4px; font-size:clamp(22px,3vw,34px); letter-spacing:-.04em; }
.topbar p { max-width:760px; line-height:1.45; }
.status-strip { gap:8px; flex-wrap:wrap; }
.status { min-height:30px; padding:6px 10px; border:1px solid var(--line); background:#fff; color:#475569; border-radius:999px; font-weight:800; font-size:12px; }
.status.ok { color:#166534; background:#f0fdf4; border-color:#bbf7d0; }
.status.error,.pill.error { color:#991b1b; background:#fef2f2; border-color:#fecaca; }
.status.sending,.pill.sending { color:#1d4ed8; background:#eff6ff; border-color:#bfdbfe; }
.hero-panel,.panel,.section-head,.install-guide { border:1px solid rgba(219,227,239,.95); border-radius:var(--radius-lg); box-shadow:var(--shadow); background:rgba(255,255,255,.96); }
.hero-panel { align-items:center; gap:18px; padding:22px; }
.hero-panel h2,.section-head h2,.panel-title h3 { letter-spacing:-.03em; }
.section-head { padding:18px; margin:18px 0; }
.inline-form { gap:10px; }
.inline-form input,.inline-form select { min-height:44px; }
.workspace-chat,.agency-chat-panel { min-height:min(760px,calc(100dvh - 190px)); display:flex; flex-direction:column; overflow:hidden; }
.panel-title { gap:12px; padding-bottom:12px; border-bottom:1px solid var(--line); }
.compact-title { padding-bottom:10px; margin-bottom:10px; }
.pill { border-radius:999px; padding:6px 10px; border:1px solid var(--line); background:#f8fafc; color:#475569; font-weight:800; font-size:12px; }
.messages { flex:1; min-height:320px; padding:18px; background:linear-gradient(180deg,#f8fbff 0%,#fff 100%); border-radius:18px; border:1px solid #edf2f7; overflow-y:auto; }
.messages:empty::before { content:"Sin mensajes todavia. Escribe abajo para empezar."; display:grid; place-items:center; min-height:180px; color:var(--muted); text-align:center; font-weight:700; }
.message,.chat-message { max-width:min(760px,86%); border-radius:18px; padding:12px 14px; margin:10px 0; line-height:1.5; box-shadow:0 8px 22px rgba(15,23,42,.06); }
.message.user,.chat-message.user,.message.me,.chat-message.me { margin-left:auto; background:var(--accent); color:#fff; border-bottom-right-radius:6px; }
.message.agent,.chat-message.agent,.message.assistant,.chat-message.assistant { background:#fff; border:1px solid var(--line); border-bottom-left-radius:6px; }
.message.error,.chat-message.error { background:#fef2f2; border:1px solid #fecaca; color:#991b1b; }
.message.sending,.chat-message.sending { opacity:.75; position:relative; }
.message.sending::after,.chat-message.sending::after { content:"Enviando..."; display:block; margin-top:6px; font-size:12px; font-weight:800; opacity:.78; }
.chat-form { position:sticky; bottom:0; z-index:5; display:grid; grid-template-columns:auto minmax(0,1fr) auto; align-items:center; gap:10px; padding:14px; margin-top:12px; border:1px solid var(--line); border-radius:20px; background:rgba(255,255,255,.96); box-shadow:0 -10px 28px rgba(15,23,42,.08); backdrop-filter:blur(16px); }
.chat-form .file-input,.file-input { position:absolute; inline-size:1px; block-size:1px; opacity:0; pointer-events:none; }
.chat-form input[type="text"],.chat-form input:not([type]),.chat-form #chatInput,.chat-form #agencyChatInput { min-height:48px; border-radius:999px; padding:0 16px; background:#f8fafc; }
.attach-button { min-width:44px; }
.attachment-status { grid-column:1 / -1; min-height:16px; color:var(--muted); font-size:12px; }
.agency-chat-shell { display:grid; grid-template-columns:minmax(210px,280px) minmax(0,1fr) minmax(220px,300px); gap:16px; align-items:stretch; }
.agency-conversations-panel,.agency-context-panel { min-height:420px; align-self:stretch; }
.conversation-summary,.conversation-help,.agency-context-panel p,.agency-context-panel li { color:var(--muted); line-height:1.5; }
.conversation-help { margin-top:14px; padding:12px; border-radius:14px; background:#f8fafc; border:1px solid var(--line); font-size:13px; }
.agency-context-panel ul { padding-left:18px; }
.copi-mode-toggle { border-radius:999px; background:#fff; }
body.copi-mobile-mode .app-shell { grid-template-columns:1fr; }
body.copi-mobile-mode .sidebar { position:sticky; top:0; z-index:12; height:auto; max-height:38dvh; overflow:auto; border-right:0; border-bottom:1px solid var(--line); padding:10px; }
body.copi-mobile-mode .brand { margin-bottom:8px; padding:8px; }
body.copi-mobile-mode .nav { display:flex; gap:8px; overflow-x:auto; padding-bottom:4px; scroll-snap-type:x proximity; }
body.copi-mobile-mode .nav-item { flex:0 0 auto; width:auto; min-height:40px; scroll-snap-align:start; border-color:var(--line); background:#fff; }
body.copi-mobile-mode .agency-nav-agents,body.copi-mobile-mode .sidebar-tasks { display:flex; flex:0 0 auto; overflow-x:auto; max-width:100%; }
body.copi-mobile-mode main { height:auto; min-height:100dvh; padding:12px; overflow:visible; }
body.copi-mobile-mode .topbar { margin:-12px -12px 12px; padding:12px; position:sticky; top:0; }
body.copi-mobile-mode .topbar h1 { font-size:22px; }
body.copi-mobile-mode .hero-panel,body.copi-mobile-mode .section-head { padding:14px; border-radius:18px; }
body.copi-mobile-mode .hero-actions,body.copi-mobile-mode .inline-form { display:grid; grid-template-columns:1fr; width:100%; }
body.copi-mobile-mode .agency-chat-shell { grid-template-columns:1fr; }
body.copi-mobile-mode .agency-conversations-panel,body.copi-mobile-mode .agency-context-panel { min-height:auto; }
body.copi-mobile-mode .messages { min-height:calc(100dvh - 330px); padding:12px; border-radius:16px; }
body.copi-mobile-mode .workspace-chat,body.copi-mobile-mode .agency-chat-panel { min-height:calc(100dvh - 170px); border-radius:18px; }
body.copi-mobile-mode .chat-form { grid-template-columns:auto minmax(0,1fr) 48px; border-radius:18px 18px 0 0; margin-left:-2px; margin-right:-2px; padding:10px; bottom:env(safe-area-inset-bottom,0); }
body.copi-mobile-mode .chat-form input { min-width:0; }
body.copi-mobile-mode .attach-button { padding:0 10px; font-size:0; }
body.copi-mobile-mode .attach-button .icon { font-size:10px; }
@media (max-width:1040px) { .agency-chat-shell { grid-template-columns:230px minmax(0,1fr); } .agency-context-panel { grid-column:1 / -1; min-height:auto; } }
@media (max-width:760px) { .app-shell { grid-template-columns:1fr; height:auto; min-height:100dvh; } .sidebar { height:auto; position:sticky; top:0; z-index:12; border-right:0; border-bottom:1px solid var(--line); } main { height:auto; min-height:100dvh; padding:12px; } .topbar { margin:-12px -12px 12px; padding:12px; } .agency-chat-shell { grid-template-columns:1fr; } .status-strip { width:100%; } #refreshBtn,#logoutBtn { flex:1; } }
@media (prefers-reduced-motion:reduce) { * { scroll-behavior:auto !important; transition:none !important; animation:none !important; } button:hover { transform:none; } }

/* Registro privado Telegram por cliente */
.telegram-registry-panel{margin-top:18px;min-height:420px}
.telegram-registry-toolbar{display:grid;grid-template-columns:auto minmax(240px,1fr) auto;gap:12px;align-items:center;margin-bottom:18px}
.telegram-registry-toolbar label{font-weight:850;color:#334155}
.telegram-registry-toolbar input{min-height:46px;padding:0 14px;border:1px solid var(--line);background:#f8fafc}
.telegram-client-registry{display:grid;grid-template-columns:repeat(auto-fit,minmax(min(100%,420px),1fr));gap:16px}
.telegram-client-card{border:1px solid var(--line);border-radius:18px;padding:16px;background:#fff;box-shadow:0 10px 28px rgba(15,23,42,.05);min-width:0}
.telegram-client-card>header{display:flex;justify-content:space-between;gap:12px;align-items:flex-start;padding-bottom:12px;border-bottom:1px solid var(--line)}
.telegram-client-card h3{margin:2px 0 0;font-size:20px}
.telegram-group-list{display:grid;gap:10px;padding-top:12px}
.telegram-group-row{display:grid;grid-template-columns:minmax(88px,auto) minmax(0,1fr) auto auto;gap:10px;align-items:center;padding:11px;border:1px solid #e8eef6;border-radius:14px;background:#f8fbff}
.telegram-agent-badge{font-size:11px;font-weight:900;letter-spacing:.04em;color:#1d4ed8;background:#dbeafe;border-radius:999px;padding:6px 9px;text-align:center}
.telegram-group-copy{display:grid;min-width:0;gap:3px}
.telegram-group-copy strong{overflow-wrap:anywhere}
.telegram-group-copy small{color:var(--muted);font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace}
.telegram-open-link{text-align:center;text-decoration:none;white-space:nowrap}
@media (max-width:760px){.telegram-registry-toolbar{grid-template-columns:1fr}.telegram-group-row{grid-template-columns:1fr auto}.telegram-group-copy{grid-column:1/-1;grid-row:2}.telegram-open-link{grid-column:1/-1}}
