:root {
  --ink: #13233c;
  --muted: #64748b;
  --line: #dce5f1;
  --surface: #ffffff;
  --canvas: #f4f7fb;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --cyan: #0891b2;
  --success: #16a34a;
  --danger: #dc2626;
  --shadow: 0 18px 55px rgba(33, 62, 104, .10);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--canvas);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background:
    radial-gradient(circle at 8% -10%, rgba(37, 99, 235, .11), transparent 32rem),
    radial-gradient(circle at 94% 8%, rgba(6, 182, 212, .09), transparent 28rem),
    var(--canvas);
}

button, input, select { font: inherit; }
button { cursor: pointer; }

.app-header {
  min-height: 106px;
  padding: 22px clamp(20px, 4vw, 64px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  background: rgba(255, 255, 255, .86);
  border-bottom: 1px solid rgba(201, 214, 232, .85);
  backdrop-filter: blur(16px);
}

.brand { display: flex; align-items: center; gap: 15px; }
.brand img { filter: drop-shadow(0 7px 14px rgba(37, 99, 235, .16)); }
.eyebrow, .section-kicker {
  margin: 0 0 4px;
  color: var(--primary);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .14em;
  text-transform: uppercase;
}
.brand h1 { margin: 0; font-size: clamp(21px, 2vw, 28px); letter-spacing: -.04em; }
.brand h1 span { color: var(--primary); font-weight: 600; }

.connection-chip {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: #fff;
  font-size: 13px;
  font-weight: 700;
}
.connection-dot { width: 9px; height: 9px; border-radius: 50%; background: #94a3b8; box-shadow: 0 0 0 4px #e2e8f0; }
.connection-chip[data-state="online"] { color: #166534; border-color: #bbf7d0; background: #f0fdf4; }
.connection-chip[data-state="online"] .connection-dot { background: var(--success); box-shadow: 0 0 0 4px #dcfce7; }
.connection-chip[data-state="offline"] { color: #991b1b; border-color: #fecaca; background: #fff7f7; }
.connection-chip[data-state="offline"] .connection-dot { background: var(--danger); box-shadow: 0 0 0 4px #fee2e2; }

.workspace { width: min(1540px, calc(100% - 40px)); margin: 30px auto 50px; }
.control-panel, .result-panel {
  background: rgba(255, 255, 255, .95);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}
.company-panel {
  margin-top: 20px;
  padding: clamp(20px, 3vw, 34px);
  background: rgba(255, 255, 255, .96);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}
.control-panel { padding: clamp(20px, 3vw, 34px); }
.section-heading, .panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.section-heading { margin-bottom: 22px; }
.section-heading h2, .panel-heading h2 { margin: 0; font-size: 20px; letter-spacing: -.025em; }
.section-note { margin: 0; color: var(--muted); font-size: 13px; }

.connection-form {
  display: grid;
  grid-template-columns: minmax(180px, .8fr) minmax(230px, 1fr) auto;
  gap: 12px;
  padding: 14px;
  margin-bottom: 22px;
  border-radius: 13px;
  background: #f7f9fc;
  border: 1px solid #e7edf5;
}
label > span, .batch-control { color: var(--muted); font-size: 11px; font-weight: 800; letter-spacing: .045em; text-transform: uppercase; }
label > span { display: block; margin: 0 0 6px 2px; }
input, select {
  width: 100%;
  min-height: 40px;
  padding: 8px 11px;
  color: var(--ink);
  background: #fff;
  border: 1px solid #cbd7e6;
  border-radius: 9px;
  outline: none;
  transition: border-color .16s, box-shadow .16s;
}
input:focus, select:focus { border-color: #60a5fa; box-shadow: 0 0 0 3px rgba(59, 130, 246, .13); }

.button {
  min-height: 40px;
  padding: 9px 14px;
  border: 0;
  border-radius: 9px;
  color: #fff;
  background: var(--primary);
  font-weight: 750;
  font-size: 13px;
  transition: transform .12s, background .16s, opacity .16s;
}
.button:hover { background: var(--primary-dark); transform: translateY(-1px); }
.button:active { transform: translateY(0); }
.button:disabled { opacity: .55; cursor: wait; transform: none; }
.button-secondary { align-self: end; color: var(--primary); background: #eaf1ff; border: 1px solid #c7d8ff; }
.button-secondary:hover { color: #fff; background: var(--primary); }
.button-ghost { min-height: 34px; padding: 7px 11px; color: var(--muted); background: #f1f5f9; }
.button-ghost:hover { color: var(--ink); background: #e2e8f0; }
.button-danger { color: #b91c1c; background: #fee2e2; }
.button-danger:hover { color: #fff; background: #b91c1c; }

.operation-groups { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.operation-group { padding: 18px; border: 1px solid #e1e8f2; border-radius: 14px; background: #fbfcfe; }
.group-title { display: flex; align-items: center; gap: 12px; padding: 1px 2px 14px; }
.group-title h3 { margin: 0 0 2px; font-size: 16px; }
.group-title p { margin: 0; color: var(--muted); font-size: 12px; }
.group-icon { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 11px; color: #fff; background: linear-gradient(135deg, #2563eb, #60a5fa); font-weight: 900; }
.group-icon.client { background: linear-gradient(135deg, #0891b2, #22d3ee); }

.operation-form {
  display: grid;
  grid-template-columns: minmax(170px, 1fr) minmax(110px, 160px) auto;
  align-items: center;
  gap: 9px;
  min-height: 64px;
  padding: 11px 0;
  border-top: 1px solid #e8edf4;
}
.operation-form.wide { grid-template-columns: minmax(150px, 1fr) 72px 76px minmax(120px, 1fr) auto; }
.operation-copy strong, .operation-copy small { display: block; }
.operation-copy strong { font-size: 13px; }
.operation-copy small { margin-top: 3px; color: var(--muted); font-size: 11px; }
.operation-form input { min-width: 0; }

.results-grid { display: grid; grid-template-columns: minmax(0, .85fr) minmax(0, 1.15fr); gap: 20px; margin-top: 20px; }
.result-panel { min-height: 560px; overflow: hidden; }
.panel-heading { height: 78px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.json-panel { background: #12213a; border-color: #263a58; }
.json-panel .panel-heading { border-color: #293c58; }
.json-panel .panel-heading h2 { color: #f8fafc; }
.json-panel .section-kicker { color: #67e8f9; }
.json-panel .button-ghost { color: #cbd5e1; background: #263853; }
#json-output {
  height: 482px;
  margin: 0;
  padding: 22px;
  overflow: auto;
  color: #c9e5ff;
  background: linear-gradient(145deg, #12213a, #0b172a);
  font: 13px/1.62 "Cascadia Code", Consolas, monospace;
  white-space: pre-wrap;
  word-break: break-word;
}

.batch-control { display: flex; align-items: center; gap: 9px; white-space: nowrap; }
.batch-control select { width: 70px; min-height: 34px; padding: 5px 8px; font-size: 12px; }
.table-meta { height: 38px; padding: 0 18px; display: flex; align-items: center; justify-content: space-between; gap: 14px; color: var(--muted); background: #f8fafc; border-bottom: 1px solid var(--line); font-size: 11px; font-weight: 700; }
.table-scroll { height: 444px; overflow: auto; outline: none; }
table { width: 100%; min-width: 600px; border-collapse: separate; border-spacing: 0; font-size: 12px; }
th {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 12px 14px;
  color: #44546b;
  background: #f1f5f9;
  border-bottom: 1px solid #d7e0ec;
  text-align: left;
  font-size: 10px;
  letter-spacing: .045em;
  text-transform: uppercase;
}
td { max-width: 340px; padding: 11px 14px; border-bottom: 1px solid #edf1f6; color: #30415b; vertical-align: top; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
tbody tr:nth-child(even) td { background: #fbfcfe; }
tbody tr:hover td { background: #eff6ff; }
.empty-state { height: 300px; color: var(--muted); text-align: center; vertical-align: middle; white-space: normal; }

.company-heading { margin-bottom: 18px; }
.company-heading .button-secondary { align-self: center; }
.company-search {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto auto auto;
  align-items: end;
  gap: 10px;
  padding: 14px;
  border: 1px solid #e2e8f0;
  border-radius: 13px;
  background: #f8fafc;
}
.company-search input, .company-form input:not([type="number"]):not([name="EMAIL"]):not(#company-api-key) { text-transform: uppercase; }
.company-form input[name="EMAIL"] { text-transform: lowercase; }
.company-search > .button { width: 120px; min-height: 40px; }
.inactive-filter {
  min-height: 40px;
  padding: 0 11px;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid #cbd7e6;
  border-radius: 9px;
  background: #fff;
}
.inactive-filter input { width: 17px; min-height: 17px; margin: 0; }
.inactive-filter span { margin: 0; white-space: nowrap; }
.company-list-meta {
  min-height: 48px;
  padding: 7px 4px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 15px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}
.company-pagination { display: flex; align-items: center; gap: 9px; }
.company-table-scroll {
  min-height: 270px;
  max-height: 460px;
  overflow: auto;
  border: 1px solid #d7e0ec;
  border-radius: 12px;
  outline: none;
}
.company-table { min-width: 1050px; }
.company-table .empty-state { height: 230px; }
.company-table tbody tr { cursor: default; }
.company-table tbody tr.selected td { background: #dbeafe; }
.company-table td.api-key-cell { min-width: 190px; font-family: "Cascadia Code", Consolas, monospace; }
.company-table td.actions-cell { min-width: 260px; overflow: visible; }
.actions-column { min-width: 260px; }
.table-actions { display: flex; align-items: center; gap: 6px; }
.icon-button {
  min-width: 34px;
  min-height: 34px;
  padding: 6px 9px;
  border: 1px solid #cbd7e6;
  border-radius: 8px;
  color: #334155;
  background: #fff;
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
}
.icon-button:hover { color: var(--primary); border-color: #93b4ff; background: #eff6ff; }
.icon-button.danger:hover { color: #fff; border-color: #b91c1c; background: #b91c1c; }
.icon-button:disabled { cursor: not-allowed; opacity: .45; }
.page-button { min-width: 36px; font-size: 18px; }
.company-detail-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-top: 24px;
  padding: 20px 22px;
  border: 1px solid #dce5f1;
  border-bottom: 0;
  border-radius: 14px 14px 0 0;
  background: linear-gradient(120deg, #f8fafc, #eef5ff);
}
.company-detail-toolbar h3 { margin: 0; font-size: 18px; }
.company-form {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 15px;
  padding: 22px;
  border: 1px solid #dce5f1;
  border-radius: 0 0 14px 14px;
  background: #fff;
}
.company-form .field-wide { grid-column: span 2; }
.company-form .field-api-key { grid-column: 1 / -1; }
.api-key-form-control { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
.api-key-form-control input { font-family: "Cascadia Code", Consolas, monospace; }
.api-key-form-control .icon-button { min-width: 42px; min-height: 40px; }
.company-form input[readonly], .company-form select:disabled {
  color: #475569;
  background: #f1f5f9;
  border-color: #e2e8f0;
  cursor: default;
  opacity: 1;
}
.company-form-actions {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding-top: 7px;
  border-top: 1px solid #eef2f7;
}
.company-form[data-mode="view"] .company-form-actions { display: none; }

.confirmation-dialog {
  width: min(480px, calc(100% - 32px));
  padding: 0;
  color: var(--ink);
  border: 1px solid #cbd7e6;
  border-radius: 16px;
  box-shadow: 0 24px 80px rgba(15, 23, 42, .28);
}
.confirmation-dialog::backdrop { background: rgba(15, 23, 42, .48); backdrop-filter: blur(2px); }
.confirmation-dialog form { padding: 24px; }
.confirmation-dialog h2 { margin: 0; font-size: 20px; }
.confirmation-dialog p:not(.section-kicker) { margin: 12px 0 22px; color: var(--muted); line-height: 1.55; }
.confirmation-actions { display: flex; justify-content: flex-end; gap: 10px; }

.action-tooltip {
  position: fixed;
  z-index: 20;
  max-width: 230px;
  padding: 7px 10px;
  color: #fff;
  background: #172a47;
  border-radius: 7px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, .24);
  opacity: 0;
  transform: translate(-50%, calc(-100% - 4px));
  pointer-events: none;
  transition: opacity .08s, transform .08s;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}
.action-tooltip.visible { opacity: 1; transform: translate(-50%, calc(-100% - 8px)); }

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  max-width: min(420px, calc(100vw - 48px));
  padding: 12px 16px;
  color: #fff;
  background: #172a47;
  border-radius: 11px;
  box-shadow: 0 16px 40px rgba(15, 32, 58, .24);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity .18s, transform .18s;
  font-size: 13px;
}
.toast.visible { opacity: 1; transform: translateY(0); }
.toast.error { background: #991b1b; }

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: min(440px, 100%);
  padding: clamp(28px, 6vw, 44px);
  background: rgba(255, 255, 255, .96);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: 0 24px 70px rgba(33, 62, 104, .16);
}
.login-brand { margin-bottom: 22px; }
.login-copy { margin: 0 0 24px; color: var(--muted); line-height: 1.55; }
.login-form { display: grid; gap: 16px; }
.login-form .button { margin-top: 4px; }
.form-message { min-height: 20px; margin: 14px 0 0; color: #b91c1c; font-size: 13px; }

.admin-user { display: flex; align-items: center; gap: 16px; }
.admin-user div { display: grid; justify-items: end; }
.admin-user strong { font-size: 14px; }
.admin-user small { margin-top: 2px; color: var(--muted); }
.admin-workspace { max-width: 1540px; }
.admin-tabs {
  display: flex;
  gap: 8px;
  padding: 7px;
  margin-bottom: 18px;
  background: rgba(255, 255, 255, .88);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
}
.admin-tab {
  min-height: 42px;
  padding: 8px 22px;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 9px;
  font-weight: 750;
}
.admin-tab:hover { color: var(--ink); background: #f1f5f9; }
.admin-tab.active { color: #fff; background: var(--primary); }
.admin-section {
  display: none;
  padding: clamp(20px, 3vw, 34px);
  background: rgba(255, 255, 255, .96);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}
.admin-section.active { display: block; }
.filters-grid {
  display: grid;
  grid-template-columns: minmax(190px, .75fr) minmax(250px, 1.25fr) auto auto;
  align-items: end;
  gap: 12px;
  padding: 14px;
  margin-bottom: 18px;
  background: #f7f9fc;
  border: 1px solid #e7edf5;
  border-radius: 13px;
}
.filters-grid.compact { grid-template-columns: minmax(220px, 420px) auto auto; }
.inactive-filter {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  white-space: nowrap;
}
.inactive-filter input { width: 17px; min-height: 17px; margin: 0; }
.inactive-filter span { margin: 0; }
.user-form .create-password { grid-column: span 2; }
.agent-table-scroll { margin-top: 18px; }
.status-chip {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 9px;
  border-radius: 999px;
  color: #166534;
  background: #dcfce7;
  font-size: 11px;
  font-weight: 800;
}
.status-chip.offline, .status-chip.inactive { color: #991b1b; background: #fee2e2; }
.empty-row td { padding: 34px 12px; color: var(--muted); text-align: center; }

@media (max-width: 1100px) {
  .operation-groups, .results-grid { grid-template-columns: 1fr; }
  .operation-form.wide { grid-template-columns: minmax(150px, 1fr) 72px 76px minmax(150px, 1fr) auto; }
  .company-form { grid-template-columns: repeat(2, minmax(150px, 1fr)); }
  .filters-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 720px) {
  .app-header { align-items: flex-start; flex-direction: column; }
  .workspace { width: min(100% - 24px, 1540px); margin-top: 16px; }
  .connection-form { grid-template-columns: 1fr; }
  .button-secondary { width: 100%; }
  .operation-form, .operation-form.wide { grid-template-columns: 1fr 1fr; padding: 14px 0; }
  .operation-copy { grid-column: 1 / -1; }
  .operation-form.wide input[name="busca"] { grid-column: 1 / -1; }
  .operation-form .button { grid-column: 2; }
  .operation-form.wide .button { grid-column: 2; }
  .section-heading, .panel-heading { align-items: flex-start; }
  .section-note { display: none; }
  .company-search { grid-template-columns: 1fr 1fr; }
  .company-search label { grid-column: 1 / -1; }
  .company-form { grid-template-columns: 1fr; }
  .company-form .field-wide { grid-column: auto; }
  .company-detail-toolbar { align-items: flex-start; flex-direction: column; }
  .company-detail-toolbar .button { width: 100%; }
  .admin-user { width: 100%; justify-content: space-between; }
  .admin-user div { justify-items: start; }
  .admin-tabs { overflow-x: auto; }
  .admin-tab { flex: 1 0 auto; }
  .filters-grid, .filters-grid.compact { grid-template-columns: 1fr; }
  .filters-grid .button { width: 100%; }
  .user-form .create-password { grid-column: auto; }
}
