* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #1a1a2e;
  color: #e0e0e0;
  min-height: 100vh;
}

header {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 12px 24px;
  background: #16213e;
  border-bottom: 1px solid #0f3460;
}

header h1 { font-size: 18px; color: #e94560; white-space: nowrap; }

nav { display: flex; gap: 4px; flex: 1; }

.tab {
  padding: 8px 16px;
  background: transparent;
  color: #a0a0a0;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}

.tab.active { background: #0f3460; color: #e0e0e0; }
.tab:hover { background: #0f3460; color: #e0e0e0; }

.header-actions { display: flex; gap: 8px; }

main { padding: 24px; max-width: 1400px; margin: 0 auto; }

.tab-content { display: none; }
.tab-content.active { display: block; }

.section-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

h2 { font-size: 16px; color: #a0a0a0; text-transform: uppercase; letter-spacing: 1px; }
h3 { font-size: 14px; margin-bottom: 8px; }
h4 { font-size: 12px; color: #a0a0a0; text-transform: uppercase; margin-bottom: 8px; }

.help-text { font-size: 12px; color: #666; margin-top: 8px; }

/* Hierarchical permission tree (Client Access modal). Used by
   renderPermissionTree(). The same look is mirrored in agency.css
   for the Client Admin's Sub-Admin form. */
.perm-group {
  border-top: 1px solid #1a1a3a;
  padding: 8px 0 4px;
  margin: 4px 0 0;
}
.perm-group:first-child { border-top: 0; padding-top: 0; }
.perm-group-title {
  font-weight: 700;
  color: #4fc3f7;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}
.perm-group-rows { display: flex; flex-direction: column; }
.perm-subgroup { padding-left: 14px; margin-top: 4px; }
.perm-subgroup-title {
  font-size: 11px;
  color: #9ed6ff;
  font-weight: 600;
  margin: 4px 0 2px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.perm-subgroup-rows { display: flex; flex-direction: column; padding-left: 8px; }
.grant-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  color: #e0e0e0;
  user-select: none;
}
.grant-row:hover { background: #0f1830; }
.grant-row input[type="checkbox"] {
  flex: 0 0 16px;
  width: 16px; height: 16px; margin: 0;
  accent-color: #4fc3f7;
  cursor: pointer;
}
.grant-row .label-text { flex: 1; line-height: 1.2; }

/* Buttons */
.btn {
  padding: 6px 14px;
  border: 1px solid #0f3460;
  border-radius: 4px;
  background: #16213e;
  color: #a0a0a0;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.btn:hover { background: #1a3a6e; color: #e0e0e0; }
.btn-primary { background: #e94560; color: white; border-color: #e94560; }
.btn-primary:hover { background: #d63851; }
.btn-danger { color: #f44336; border-color: #f44336; }
.btn-danger:hover { background: #f44336; color: white; }
.btn-sm { padding: 4px 10px; font-size: 11px; }

/* Tables */
table {
  width: 100%;
  border-collapse: collapse;
  background: #16213e;
  border-radius: 8px;
  overflow: hidden;
}

thead { background: #0f3460; }
th { padding: 10px 16px; text-align: left; font-size: 11px; text-transform: uppercase; color: #a0a0a0; }
td { padding: 10px 16px; font-size: 13px; border-bottom: 1px solid #0f3460; }
tr:last-child td { border-bottom: none; }

/* Modal */
.modal {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,0.7);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
}

.modal.hidden { display: none; }

.modal-content {
  background: #16213e;
  border: 1px solid #0f3460;
  border-radius: 8px;
  padding: 24px;
  min-width: 360px;
  max-width: 90vw;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-content.wide { min-width: 600px; }

.modal-content label {
  display: block;
  font-size: 12px;
  color: #a0a0a0;
  margin: 12px 0 4px;
}

.modal-content input, .modal-content select {
  width: 100%;
  padding: 8px 10px;
  background: #1a1a2e;
  color: #e0e0e0;
  border: 1px solid #0f3460;
  border-radius: 4px;
  font-size: 13px;
}

.modal-content input:focus, .modal-content select:focus {
  outline: none;
  border-color: #e94560;
}

.modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
  justify-content: flex-end;
}

/* Groups Grid */
.groups-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
}

.group-card {
  background: #16213e;
  border: 1px solid #0f3460;
  border-radius: 8px;
  padding: 16px;
}

.group-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.group-card-header h3 { margin: 0; font-size: 15px; }

.group-card-actions { display: flex; gap: 4px; }

.group-dispatchers {
  margin-bottom: 12px;
}

.group-dispatcher-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px;
  background: #1a1a2e;
  border-radius: 4px;
  margin-bottom: 4px;
  font-size: 12px;
}

.group-dispatcher-item .position {
  background: #0f3460;
  color: #4fc3f7;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 11px;
}

.group-rollover-info {
  font-size: 11px;
  color: #4fc3f7;
  margin-bottom: 8px;
  padding: 4px 8px;
  background: rgba(79, 195, 247, 0.1);
  border-radius: 4px;
}

.group-numbers { font-size: 12px; color: #a0a0a0; }

/* Rollover Editor */
.rollover-editor {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 12px;
}

.sortable-list {
  min-height: 100px;
  background: #1a1a2e;
  border: 2px dashed #0f3460;
  border-radius: 8px;
  padding: 8px;
}

.sortable-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: #16213e;
  border: 1px solid #0f3460;
  border-radius: 4px;
  margin-bottom: 4px;
  cursor: grab;
  font-size: 13px;
  user-select: none;
}

.sortable-item:active { cursor: grabbing; }
.sortable-item.dragging { opacity: 0.5; }

.sortable-item .drag-handle {
  color: #666;
  font-size: 14px;
}

.sortable-item .position-num {
  background: #0f3460;
  color: #4fc3f7;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 11px;
  flex-shrink: 0;
}

/* Phone Numbers Layout */
.numbers-layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 16px;
}

.numbers-panel {
  background: #16213e;
  border: 1px solid #0f3460;
  border-radius: 8px;
  padding: 16px;
}

.numbers-groups {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
  min-width: 0;
}

.numbers-layout > * { min-width: 0; }

.number-group-card {
  background: #16213e;
  border: 1px solid #0f3460;
  border-radius: 8px;
  padding: 16px;
}

.number-drop-zone {
  min-height: 60px;
  border: 2px dashed #0f3460;
  border-radius: 8px;
  padding: 8px;
  transition: border-color 0.2s, background 0.2s;
  box-sizing: border-box;
  min-width: 0;
  overflow: hidden;
}

.number-group-card { min-width: 0; overflow: hidden; }

.number-drop-zone.drag-over {
  border-color: #e94560;
  background: rgba(233, 69, 96, 0.1);
}

.number-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 10px;
  background: #1a1a2e;
  border: 1px solid #0f3460;
  border-radius: 4px;
  margin-bottom: 4px;
  cursor: grab;
  font-size: 12px;
  box-sizing: border-box;
  width: 100%;
  max-width: 100%;
  overflow: hidden;
}

.number-card:active { cursor: grabbing; }
.number-card.dragging { opacity: 0.5; }

.number-card .number-info {
  min-width: 0;
  overflow: hidden;
}
.number-card .number-name {
  font-weight: 600;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.number-card .number-phone { color: #a0a0a0; }
.number-card .number-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
}
.number-card .number-actions .btn {
  padding: 3px 7px;
  font-size: 10px;
  flex: 0 0 auto;
}

/* Quick Dial Editor */
.quickdial-list {
  min-height: 40px;
  margin-top: 12px;
}

.quickdial-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: #1a1a2e;
  border: 1px solid #0f3460;
  border-left: 4px solid #4fc3f7;
  border-radius: 4px;
  margin-bottom: 4px;
  cursor: grab;
  user-select: none;
}

.quickdial-item:active { cursor: grabbing; }
.quickdial-item.dragging { opacity: 0.5; }

.quickdial-item .position-num {
  background: #0f3460;
  color: #4fc3f7;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 11px;
  flex-shrink: 0;
}

.quickdial-item .drag-handle {
  color: #666;
  font-size: 14px;
}

.quickdial-item-info {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 12px;
}

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

.quickdial-item-number {
  font-size: 12px;
  color: #a0a0a0;
  font-family: monospace;
}

.quickdial-item-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn-qd {
  background: #4fc3f7 !important;
  color: #1a1a2e !important;
  border-color: #4fc3f7 !important;
  font-weight: 700 !important;
}

.btn-qd:hover {
  background: #81d4fa !important;
  color: #1a1a2e !important;
}

/* Setup */
.setup-status {
  background: #16213e;
  border: 1px solid #0f3460;
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
  font-size: 13px;
}

.setup-item {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.setup-check { color: #4caf50; }
.setup-x { color: #f44336; }

/* Toggle */
.toggle {
  display: inline-block;
  width: 36px;
  height: 20px;
  background: #333;
  border-radius: 10px;
  position: relative;
  cursor: pointer;
}

.toggle.on { background: #4caf50; }

.toggle::after {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  background: white;
  border-radius: 50%;
  top: 2px;
  left: 2px;
  transition: transform 0.2s;
}

.toggle.on::after { transform: translateX(16px); }

/* Retell AI Agents */
.retell-config-panel, .retell-agents-panel, .retell-calls-panel, .retell-log-panel {
  background: #16213e;
  border: 1px solid #0f3460;
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
}

.retell-config-row { margin-bottom: 12px; }
.retell-config-row label { display: block; font-size: 12px; color: #a0a0a0; margin-bottom: 4px; }

.input-group {
  display: flex;
  gap: 8px;
}

.input-group input {
  flex: 1;
  padding: 8px 10px;
  background: #1a1a2e;
  color: #e0e0e0;
  border: 1px solid #0f3460;
  border-radius: 4px;
  font-size: 13px;
}

.input-group input:focus { outline: none; border-color: #e94560; }

.retell-status { font-size: 13px; margin: 8px 0; padding: 8px; border-radius: 4px; }
.retell-status.ok { background: #0a3d0a; color: #4caf50; }
.retell-status.error { background: #3d0a0a; color: #f44336; }

.retell-agents-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.retell-agent-card {
  background: #1a1a2e;
  border: 1px solid #0f3460;
  border-left: 4px solid #7c4dff;
  border-radius: 4px;
  padding: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.retell-agent-card.disabled {
  opacity: 0.5;
  border-left-color: #666;
}

.retell-agent-name { font-weight: 600; font-size: 14px; }
.retell-agent-id { font-size: 11px; color: #666; font-family: monospace; }
.retell-agent-desc { font-size: 12px; color: #a0a0a0; margin-top: 4px; }

.retell-agent-actions { display: flex; align-items: center; gap: 8px; }

.remote-agents-list { max-height: 400px; overflow-y: auto; }

.remote-agent-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  background: #1a1a2e;
  border: 1px solid #0f3460;
  border-radius: 4px;
  margin-bottom: 6px;
}

.remote-agent-item.tracked { opacity: 0.6; }
.remote-agent-name { font-weight: 600; font-size: 13px; }
.remote-agent-id { font-size: 11px; color: #666; font-family: monospace; }

.badge { padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 600; }
.tracked-badge { background: #0f3460; color: #4fc3f7; }

.status-badge.retell-active { background: #1a0a3d; color: #7c4dff; }
.status-badge.transferred { background: #0a3d3d; color: #4fc3f7; }
.status-badge.completed { background: #0a3d0a; color: #4caf50; }

.positive { color: #4caf50; }
.negative { color: #f44336; }
