/* ===========================================================================
   Agent Builder — modern dark UI
   =========================================================================== */
:root {
  --bg: #0e1117;
  --bg-2: #151b24;
  --panel: #1a212c;
  --panel-2: #20293566;
  --border: #2a3340;
  --border-2: #364152;
  --text: #e6edf3;
  --muted: #8b97a7;
  --primary: #6366f1;
  --primary-2: #818cf8;
  --primary-ghost: #6366f126;
  --success: #22c55e;
  --danger: #ef4444;
  --warn: #f59e0b;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 10px 30px -10px rgba(0, 0, 0, .55);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(1200px 600px at 80% -10%, #1b2740 0%, var(--bg) 55%) fixed;
  color: var(--text);
  font-family: "Inter", system-ui, -apple-system, sans-serif;
  font-size: 14px;
}
code, .webhook-url, .tool-name, .tool-url { font-family: "JetBrains Mono", monospace; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 18px; margin: 0; }
h3 { font-size: 15px; margin: 0; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
a { color: var(--primary-2); }

/* --- Buttons --------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  padding: 9px 15px; font-size: 13.5px; font-weight: 600; cursor: pointer;
  transition: .15s ease; font-family: inherit; white-space: nowrap;
}
.btn-sm { padding: 7px 12px; font-size: 12.5px; }
.btn-xs { padding: 4px 9px; font-size: 11.5px; border-radius: 7px; }
.btn-block { width: 100%; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-2); }
.btn-secondary { background: var(--panel); color: var(--text); border-color: var(--border-2); }
.btn-secondary:hover { border-color: var(--primary); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover { background: #ffffff0d; color: var(--text); }
.btn-danger { background: var(--danger) !important; color: #fff !important; }
.btn-danger-text { color: #f87171; }
.btn-danger-text:hover { background: #ef444418; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* --- Login ----------------------------------------------------------------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card {
  width: 360px; background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 30px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 12px;
}
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.login-brand h1 { font-size: 19px; }
.login-brand p { color: var(--muted); font-size: 12.5px; }
.logo-dot {
  width: 34px; height: 34px; border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), #a855f7);
  box-shadow: 0 0 18px #6366f180; flex: none;
}
.login-card .field-label { margin-top: 6px; }
.login-card .btn { margin-top: 10px; }

/* --- Layout ---------------------------------------------------------------- */
.layout { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; }
.sidebar {
  background: #0c1016; border-right: 1px solid var(--border);
  padding: 18px 14px; display: flex; flex-direction: column; gap: 6px; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.side-brand { display: flex; align-items: center; gap: 10px; font-weight: 700; padding: 6px 8px 16px; }
.side-brand .logo-dot { width: 26px; height: 26px; border-radius: 8px; }
.side-section { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); padding: 14px 10px 6px; }
.side-tenants { display: flex; flex-direction: column; gap: 3px; }
.nav-item {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  width: 100%; text-align: left; background: transparent; border: none; color: var(--text);
  padding: 9px 11px; border-radius: 9px; cursor: pointer; font-size: 13.5px; font-family: inherit;
}
.nav-item:hover { background: #ffffff0a; }
.nav-item.active { background: var(--primary-ghost); color: var(--primary-2); font-weight: 600; }
.nav-sub { font-size: 11px; color: var(--muted); }

.main-col { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 26px; border-bottom: 1px solid var(--border); background: #0e131bcc; backdrop-filter: blur(8px); position: sticky; top: 0; z-index: 5;
}
.crumbs { font-weight: 600; }
.top-right { display: flex; align-items: center; gap: 12px; }
.user-chip { font-size: 12.5px; color: var(--muted); background: var(--panel); border: 1px solid var(--border); padding: 5px 11px; border-radius: 20px; }
.content { padding: 26px; max-width: 1180px; width: 100%; }

/* --- Page head ------------------------------------------------------------- */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 22px; gap: 16px; }
.page-head p { margin-top: 5px; }

/* --- Cards ----------------------------------------------------------------- */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 16px; }
.card {
  background: linear-gradient(180deg, var(--panel), #161d27);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 18px;
  display: flex; flex-direction: column; gap: 13px; transition: .15s;
}
.card:hover { border-color: var(--border-2); transform: translateY(-1px); }
.card-top { display: flex; align-items: center; gap: 12px; }
.avatar {
  width: 40px; height: 40px; border-radius: 11px; flex: none; display: grid; place-items: center;
  font-weight: 700; background: linear-gradient(135deg, #6366f1, #a855f7); color: #fff;
}
.avatar.agent { background: linear-gradient(135deg, #0ea5e9, #6366f1); font-size: 18px; }
.card-title-wrap { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 0; }
.card-title-wrap h3 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { font-size: 11px; color: var(--muted); }
.card-desc { color: var(--muted); font-size: 12.5px; line-height: 1.45; }
.status-dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.status-dot.on { background: var(--success); box-shadow: 0 0 8px var(--success); }
.status-dot.off { background: #475569; }

.kv { display: flex; flex-wrap: wrap; gap: 7px; }
.pill { font-size: 11.5px; padding: 4px 10px; border-radius: 20px; border: 1px solid var(--border-2); }
.pill.ok { color: #86efac; border-color: #22c55e44; background: #22c55e14; }
.pill.off { color: #fca5a5; border-color: #ef444433; background: #ef444410; }
.pill.neutral { color: var(--muted); background: #ffffff08; }

.webhook-row { display: flex; align-items: center; gap: 8px; background: #0c1016; border: 1px solid var(--border); border-radius: 9px; padding: 8px 10px; }
.webhook-label { font-size: 11px; color: var(--muted); flex: none; }
.webhook-url { font-size: 11.5px; color: var(--primary-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.card-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 2px; }

/* --- Empty state ----------------------------------------------------------- */
.empty { text-align: center; padding: 50px 20px; color: var(--muted); border: 1px dashed var(--border-2); border-radius: var(--radius); grid-column: 1 / -1; }
.empty-icon { font-size: 34px; opacity: .5; margin-bottom: 8px; }
.empty h3 { margin-bottom: 5px; color: var(--text); }

/* --- Forms / fields -------------------------------------------------------- */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 7px; min-width: 0; }
.field-full { grid-column: 1 / -1; }
.field-label { display: flex; align-items: center; gap: 7px; font-size: 12.5px; font-weight: 600; color: #c3ccd8; }
.field-hint { font-weight: 400; color: var(--muted); }
.input {
  width: 100%; background: #0c1016; border: 1px solid var(--border-2); color: var(--text);
  border-radius: 9px; padding: 10px 12px; font-size: 13.5px; font-family: inherit; transition: .15s;
}
.input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-ghost); }
.textarea { resize: vertical; line-height: 1.5; }
select.input { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%238b97a7'%3E%3Cpath d='M6 8L1 3h10z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 32px; }

/* Switch */
.switch { position: relative; display: inline-flex; width: 44px; height: 25px; cursor: pointer; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; inset: 0; background: #364152; border-radius: 20px; transition: .2s; }
.slider::before { content: ""; position: absolute; height: 19px; width: 19px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; }
.switch input:checked + .slider { background: var(--primary); }
.switch input:checked + .slider::before { transform: translateX(19px); }

/* Range */
.range-wrap { display: flex; align-items: center; gap: 12px; }
.range { flex: 1; accent-color: var(--primary); }
.range-val { font-family: "JetBrains Mono", monospace; font-size: 12.5px; color: var(--primary-2); min-width: 38px; text-align: right; }

/* --- Info icon / tooltip --------------------------------------------------- */
.info-wrap { position: relative; display: inline-flex; }
.info-icon {
  width: 15px; height: 15px; border-radius: 50%; border: 1px solid var(--border-2);
  display: grid; place-items: center; font-size: 10px; font-style: italic; font-weight: 700;
  color: var(--muted); cursor: help; font-family: Georgia, serif;
}
.info-icon:hover { border-color: var(--primary); color: var(--primary-2); }
.info-pop {
  position: absolute; top: 22px; left: -8px; z-index: 50; width: 260px;
  background: #0b0f15; border: 1px solid var(--border-2); border-radius: 10px; padding: 11px 13px;
  box-shadow: var(--shadow); display: none; flex-direction: column; gap: 8px;
}
/* When a tooltip would spill off the right edge, open it leftward instead. */
.info-pop.pop-left { left: auto; right: -8px; }
.info-wrap:hover .info-pop, .info-icon:focus + .info-pop { display: flex; }
.info-pop-text { font-size: 12px; line-height: 1.5; color: #cdd6e1; font-weight: 400; }
.info-pop-link { font-size: 11.5px; font-weight: 600; }

/* --- Modal ----------------------------------------------------------------- */
.overlay {
  position: fixed; inset: 0; background: #06080ccc; backdrop-filter: blur(3px);
  display: grid; place-items: center; padding: 24px; z-index: 100; opacity: 0; transition: .15s;
}
.overlay.show { opacity: 1; }
.modal {
  width: 540px; max-width: 100%; max-height: 90vh; background: var(--bg-2);
  border: 1px solid var(--border-2); border-radius: 16px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; overflow: hidden;
}
.modal-wide { width: 720px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.modal-x { background: none; border: none; color: var(--muted); font-size: 24px; cursor: pointer; line-height: 1; }
.modal-x:hover { color: var(--text); }
.modal-body { padding: 22px; overflow-y: auto; overflow-x: clip; }
.modal-footer { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 22px; border-top: 1px solid var(--border); background: #12171f; }
.confirm-text { line-height: 1.5; }

/* --- Tabs ------------------------------------------------------------------ */
.tabbar { display: flex; gap: 3px; border-bottom: 1px solid var(--border); margin-bottom: 20px; overflow-x: auto; }
.tab {
  background: none; border: none; color: var(--muted); padding: 9px 14px; cursor: pointer;
  font-size: 13px; font-weight: 600; font-family: inherit; border-bottom: 2px solid transparent; white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary-2); border-bottom-color: var(--primary); }

/* Stack all panes in one grid cell so the box sizes to the tallest pane and
   never changes height when switching tabs. Inactive panes are hidden with
   visibility (which keeps their footprint) rather than display:none. */
.tab-panes { display: grid; }
.tab-panes > * { grid-area: 1 / 1; }
.tab-panes > .pane-hidden { visibility: hidden; }

/* --- Tools ----------------------------------------------------------------- */
.tools-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.tool-list { display: flex; flex-direction: column; gap: 9px; }
.tool-row { background: #0c1016; border: 1px solid var(--border); border-radius: 11px; padding: 12px 14px; display: flex; flex-direction: column; gap: 6px; }
.tool-row-main { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.tool-name { font-size: 13px; color: var(--primary-2); }
.method-badge { font-size: 10.5px; font-weight: 700; background: var(--primary-ghost); color: var(--primary-2); padding: 2px 7px; border-radius: 5px; }
.tool-url { font-size: 11.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tool-desc { font-size: 12px; color: var(--muted); }
.tool-row-actions { display: flex; gap: 5px; }
.notice { background: #f59e0b14; border: 1px solid #f59e0b40; color: #fcd34d; padding: 12px 14px; border-radius: 10px; font-size: 13px; }

/* --- Toasts ---------------------------------------------------------------- */
.toast-host { position: fixed; bottom: 22px; right: 22px; display: flex; flex-direction: column; gap: 10px; z-index: 200; }
.toast {
  background: var(--panel); border: 1px solid var(--border-2); border-left: 3px solid var(--primary);
  color: var(--text); padding: 12px 16px; border-radius: 10px; font-size: 13px; box-shadow: var(--shadow);
  opacity: 0; transform: translateX(20px); transition: .25s; min-width: 220px;
}
.toast.show { opacity: 1; transform: translateX(0); }
.toast-success { border-left-color: var(--success); }
.toast-error { border-left-color: var(--danger); }

/* --- Responsive ------------------------------------------------------------ */
@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .form-grid { grid-template-columns: 1fr; }
}
