/* ============================================================
   app.css — logged-in product surface (login, signup, dashboard, settings)
   ============================================================ */

* {
  box-sizing: border-box;
}

.app-body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  margin: 0;
  padding: 0;
  background: var(--bg);
}

/* ----- Full-width navbar ----- */
.navbar.full-width-nav {
  width: 100%;
  padding: 0;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 100;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  height: 68px;
  flex-shrink: 0;
}
.navbar.full-width-nav .nav-inner {
  max-width: 100%;
  padding: 0 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 100%;
}
.navbar.full-width-nav .logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text-heading);
  font-weight: 500;
  font-size: 18px;
}
.navbar.full-width-nav .logo img {
  height: 32px;
  width: auto;
}
.navbar.full-width-nav .nav-links {
  display: flex;
  align-items: center;
  gap: 24px;
}
.navbar.full-width-nav .nav-links a {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 14px;
  transition: color 0.2s;
}
.navbar.full-width-nav .nav-links a:hover {
  color: var(--text-heading);
}
.navbar.full-width-nav .hamburger {
  display: none;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
}

/* ----- app navbar extras (org name pill) ----- */
.org-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--text-muted);
  background: var(--bg-raised);
  border: 1px solid var(--border);
  padding: 6px 16px;
  border-radius: var(--radius-pill);
}
.org-pill i {
  color: var(--accent);
}
.org-pill b {
  color: var(--text-heading);
  font-weight: 500;
}

/* ----- generic form controls (auth + agent forms) ----- */
label {
  font-size: 13px;
  color: var(--text-muted);
  display: block;
  margin-bottom: 4px;
}
input,
textarea,
select {
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 14px;
  border-radius: var(--radius-md);
  width: 100%;
  margin-bottom: 16px;
  font-family: inherit;
  font-size: 14px;
}
textarea {
  min-height: 80px;
  resize: vertical;
}
input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
}
.field-error {
  color: var(--danger);
  font-size: 13px;
  margin: -10px 0 14px;
  min-height: 1em;
}
.form-hint {
  color: var(--text-faint);
  font-size: 12px;
  margin: -12px 0 16px;
}

/* ----- AUTH PAGES (login / signup) ----- */
.auth-shell {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 120px 24px 60px;
  position: relative;
  overflow: hidden;
}
.auth-shell::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 80% 20%, #2a2456 0%, var(--bg) 60%);
  opacity: 0.6;
  z-index: 0;
}
.auth-card {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 420px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 40px 36px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
.auth-card .logo {
  justify-content: center;
  margin-bottom: 8px;
}
.auth-card h1 {
  font-size: 26px;
  font-weight: 400;
  color: var(--text-heading);
  text-align: center;
  margin-bottom: 6px;
}
.auth-card .auth-sub {
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 28px;
}
.auth-card form {
  margin-top: 8px;
}
.auth-card .btn {
  width: 100%;
  justify-content: center;
  margin-top: 4px;
}
.auth-switch {
  text-align: center;
  font-size: 14px;
  color: var(--text-muted);
  margin-top: 22px;
}
.auth-error {
  background: rgba(248, 113, 113, 0.08);
  border: 1px solid #4a2530;
  color: #fca5a5;
  font-size: 13px;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  margin-bottom: 16px;
  display: none;
}
.auth-error.show {
  display: block;
}

.auth-checkbox-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 13px;
  color: #555;
  margin: 14px 0;
  cursor: pointer;
}
 
.auth-checkbox-row input[type="checkbox"] {
  margin-top: 3px;
  flex-shrink: 0;
  width: auto;
}
 
.auth-forgot-row {
  text-align: right;
  margin: -8px 0 16px;
  font-size: 13px;
}
 
.auth-forgot-row a {
  color: #727FD5;
}
 
.auth-success {
  display: none;
  background: #eafaf0;
  color: #1f7a45;
  border: 1px solid #bfe8d0;
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 14px;
}
 
.auth-success.show {
  display: block;
}
 
/* ----- APP SHELL (dashboard / settings) ----- */
.app-main {
  flex: 1;
  padding-top: 68px;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  min-height: 0;
}
.app-header-bar {
  border-bottom: 1px solid var(--border-soft);
  padding: 12px 0;
  flex-shrink: 0;
}
.app-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}
.app-title {
  font-size: 28px;
  font-weight: 400;
  color: var(--text-heading);
}
.app-sub {
  color: var(--text-muted);
  font-size: 14px;
  margin-top: 4px;
}

/* ----- Dashboard workspace: sidebar + chat ----- */
.workspace-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 8px 0 40px;
  overflow: hidden;
  /* max-width: 1400px; */
  max-width: 1800px;
  margin: 0 auto;
  width: 100%;
  padding-left: 14px;
  padding-right: 24px;
}

.workspace {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.workspace-panel {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 9px;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.workspace-body {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  width: 100%;
}


/* ----- feature navigation rail ----- */
.feature-sidebar {
  width: 20px;
  min-width: 240px;
  max-width: 240px;
  border-right: 1px solid var(--border);
  padding: 16px 12px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
}
.feature-nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  text-align: left;
}
.feature-nav-item i { width: 18px; text-align: center; }
.feature-nav-item:hover:not(.disabled) { background: #1a1f36; color: var(--text-heading); }
.feature-nav-item.active { background: #1a1f36; border-color: var(--accent); color: var(--text-heading); }
.feature-nav-item.disabled { cursor: not-allowed; opacity: 0.5; }
.feature-nav-item .soon-tag {
  margin-left: auto;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-faint);
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  padding: 2px 6px;
  border-radius: var(--radius-pill);
}
.feature-nav-divider {
  height: 1px;
  background: var(--border);
  margin: 12px 8px 8px;
}
.feature-nav-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
  padding: 0 12px;
  margin: 4px 0 6px;
}

.nav-icon {
  width: 18px;
  height: 18px;
  object-fit: contain;
  vertical-align: middle;
}


/* ----- view switching ----- */
.workspace-content {
  flex: 1;
  min-width: 0;
  display: flex;
  overflow: hidden;
  min-height: 0;
}
.view { display: none; flex: 1; min-width: 0; overflow: hidden; }
.view.active { display: flex; }


/* ----- Agent Templates marketplace ----- */
.templates-marketplace {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 20px 24px;
  overflow-y: auto;
}

.marketplace-toolbar {
  display: flex;
  gap: 12px;
  margin-bottom: 18px;
  flex-shrink: 0;
}
.marketplace-search {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  color: var(--text-faint);
}
.marketplace-search input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-heading);
  font-size: 14px;
  font-family: inherit;
  margin: 0;
  padding: 0;
}
.marketplace-toolbar select {
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-muted);
  font-size: 14px;
  font-family: inherit;
  padding: 10px 14px;
  margin: 0;
}

.template-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
  align-content: start;
}

.template-card {
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.template-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.template-category {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-faint);
}

.template-card-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-heading);
}

.template-card-desc {
  font-size: 13px;
  color: var(--text-muted);
  flex: 1;
  line-height: 1.5;
}

.template-card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.template-tag {
  font-size: 11px;
  color: var(--text-muted);
  background: var(--bg-panel);
  border: 1px solid var(--border);
  padding: 2px 8px;
  border-radius: var(--radius-pill);
}

.template-add-btn {
  margin-top: 6px;
}

/* ----- Invites & organizations panel ----- */
.invites-panel {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
  align-content: start;
}

.invite-card {
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
}

.invite-card h3 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-heading);
  margin: 0 0 6px;
}

.invite-card-sub {
  font-size: 13px;
  color: var(--text-muted);
  margin: 0 0 14px;
  line-height: 1.5;
}

/* ----- coming soon placeholders ----- */
.coming-soon-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 12px;
  padding: 40px;
  color: var(--text-muted);
}
.coming-soon-icon { font-size: 34px; color: var(--text-faint); }
.coming-soon-panel h2 { color: var(--text-heading); font-weight: 500; font-size: 20px; }
.coming-soon-panel p { max-width: 380px; font-size: 14px; }
.coming-soon-badge {
  margin-top: 6px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 4px 14px;
  border-radius: var(--radius-pill);
}

/* ----- multi-agent flow node/edge builder ----- */
.node-card {
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  margin-bottom: 10px;
  position: relative;
}
.node-card label { margin-top: 8px; }
.node-card label:first-child { margin-top: 0; }
.node-card .node-remove {
  position: absolute;
  top: 8px;
  right: 8px;
  background: transparent;
  border: none;
  color: var(--text-faint);
  cursor: pointer;
  font-size: 13px;
}
.node-card .node-remove:hover { color: var(--danger); }
.add-node-btn { width: 100%; justify-content: center; margin-bottom: 14px; }
.edge-row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.edge-row select { margin-bottom: 0; }
.edge-row .edge-remove { background: transparent; border: none; color: var(--text-faint); cursor: pointer; flex-shrink: 0; }
.topology-tag {
  display: inline-block;
  font-size: 11px;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 1px 8px;
  border-radius: 20px;
}


.app-sidebar {
  width: 320px;
  min-width: 320px;  /* Add this to prevent shrinking */
  max-width: 320px;  /* Add this to prevent growing */
  padding: 22px;
  border-right: 1px solid var(--border);
  flex-shrink: 0;
  flex-grow: 0;      /* Add this to prevent flexing */
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  min-height: 0;
}

.sidebar-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  flex-shrink: 0;
}
.sidebar-heading span {
  font-weight: 500;
  color: var(--text-heading);
  font-size: 15px;
}
.pill-btn {
  padding: 3px 14px;
  font-size: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  flex-shrink: 0;
}
.pill-btn:hover {
  color: var(--text-heading);
  border-color: var(--accent);
}

#agent-list {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  overflow-x: hidden;
}

.agent-item {
  padding: 10px 12px;
  border-radius: var(--radius-md);
  cursor: pointer;
  margin-bottom: 6px;
  font-size: 14px;
  color: #c8cee4;
  border: 1px solid transparent;
  flex-shrink: 0;
}
.agent-item .agent-item-name {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.agent-item.active {
  background: #1a1f36;
  border-color: var(--accent);
}
.agent-item:hover {
  background: #1a1f36;
}
.agent-item .meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}
.status-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  margin-right: 5px;
}
.status-dot.active { background: var(--success); }
.status-dot.draft { background: var(--warning); }
.status-dot.archived { background: var(--text-faint); }

.empty-state {
  color: var(--text-faint);
  font-size: 13px;
  padding: 8px 4px;
}

#new-agent-form {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border-soft);
  flex-shrink: 0;
  overflow-y: auto;
  /* max-height: 50%; */
}
.tool-checkboxes {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}
.tool-check {
  font-size: 12px;
  color: #b0b8cf;
  display: flex;
  align-items: center;
  gap: 5px;
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  flex-shrink: 0;
}
.tool-check input {
  width: auto;
  margin: 0;
}

/* chat column */
.app-chat {
  flex: 1;
  min-width: 0;      /* Allow chat to shrink if needed */
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  min-height: 0;
}

.chat-header {
  padding: 16px 22px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  flex-shrink: 0;
}
.chat-header-title {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.chat-header-title .name {
  font-weight: 500;
  color: var(--text-heading);
  font-size: 16px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-header-title .sub {
  font-size: 12px;
  color: var(--text-faint);
}
.chat-header-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-shrink: 0;
}
.icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 6px 10px;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: 13px;
  flex-shrink: 0;
}
.icon-btn:hover {
  color: var(--text-heading);
  border-color: var(--accent);
}

.messages {
  flex: 1;
  padding: 22px;
  overflow-y: auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.msg {
  padding: 10px 16px;
  border-radius: 14px;
  max-width: 80%;
  word-break: break-word;
  font-size: 14px;
  flex-shrink: 0;
}
.msg.user {
  background: var(--accent);
  align-self: flex-end;
  color: #fff;
  border-bottom-right-radius: 3px;
}
.msg.assistant {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  align-self: flex-start;
  border-bottom-left-radius: 3px;
}
.msg .tool-tag {
  display: inline-block;
  font-size: 11px;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 1px 8px;
  border-radius: 20px;
  margin-bottom: 6px;
}
.composer {
  display: flex;
  gap: 10px;
  padding: 16px 22px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.composer input {
  flex: 1;
  margin-bottom: 0;
  border-radius: var(--radius-pill);
  padding: 10px 18px;
  min-width: 0;
}
.composer button {
  background: var(--accent);
  border: none;
  color: #fff;
  padding: 10px 26px;
  border-radius: var(--radius-pill);
  cursor: pointer;
  font-weight: 500;
  font-family: inherit;
  flex-shrink: 0;
}
.composer button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.typing-indicator {
  align-self: flex-start;
  color: var(--text-faint);
  font-size: 13px;
  padding: 6px 16px;
  flex-shrink: 0;
}

@media (max-width: 820px) {
  .app-sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
    height: auto;
    max-height: 50vh;
  }
  .workspace-body {
    grid-template-columns: 1fr;  /* Stack on mobile */
    flex-wrap: wrap;
    overflow-y: auto;
  }
  .app-chat {
    height: auto;
    min-height: 50vh;
  }
  .navbar.full-width-nav .hamburger {
    display: block;
  }
  .navbar.full-width-nav .nav-links {
    display: none;
    flex-direction: column;
    position: absolute;
    top: 68px;
    left: 0;
    right: 0;
    background: var(--bg-panel);
    padding: 20px;
    border-bottom: 1px solid var(--border);
    gap: 16px;
  }
  .navbar.full-width-nav .nav-links.open {
    display: flex;
  }

  .feature-sidebar {
    width: 100%;
    max-width: none;
    min-width: 0;
    flex-direction: row;
    overflow-x: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 10px 12px;
  }
  .feature-nav-item { flex-shrink: 0; white-space: nowrap; }
  .view.active { flex-direction: column; }
}





.org-switch-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border: 1px solid #2a3048;
  border-radius: 10px;
  margin-bottom: 10px;
  background: #161a2c;
}
.org-switch-item.active {
  border-color: #727FD5;
  background: rgba(114, 127, 213, 0.08);
}
.org-switch-item .fa-circle-check {
  color: #34d399;
  font-size: 18px;
}
.org-switch-name {
  font-weight: 600;
  color: #e6e8ef;
}

.role-badge {
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  text-transform: capitalize;
  border: 1px solid #2a3048;
  color: #8b93a7;
}
.role-badge.role-owner { color: #fbbf24; border-color: rgba(251,191,36,0.4); }
.role-badge.role-admin { color: #727FD5; border-color: rgba(114,127,213,0.4); }
.role-badge.role-member { color: #8b93a7; }

/* ----- SETTINGS PAGE ----- */
.settings-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 24px;
  margin-top: 24px;
}
.settings-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 26px 28px;
}
.settings-card h3 {
  color: var(--text-heading);
  font-weight: 500;
  font-size: 17px;
  margin-bottom: 4px;
}
.settings-card .settings-card-sub {
  color: var(--text-muted);
  font-size: 13px;
  margin-bottom: 20px;
}
.key-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--border-soft);
  gap: 12px;
  flex-wrap: wrap;
}
.key-row:last-child {
  border-bottom: none;
}
.key-row .key-name {
  color: var(--text);
  font-size: 14px;
}
.key-row .key-prefix {
  color: var(--text-faint);
  font-size: 12px;
  font-family: 'SFMono-Regular', Consolas, monospace;
}
.key-row .key-status {
  font-size: 12px;
  padding: 2px 10px;
  border-radius: 20px;
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.key-row .key-status.active {
  color: var(--success);
  border-color: #234d3d;
}
.raw-key-box {
  background: var(--bg-sunken);
  border: 1px solid var(--accent);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  font-family: 'SFMono-Regular', Consolas, monospace;
  font-size: 13px;
  color: #b8b2ff;
  word-break: break-all;
  margin-bottom: 12px;
}
.inline-form {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  flex-wrap: wrap;
  margin-top: 18px;
}
.inline-form > div {
  flex: 1;
  min-width: 180px;
}
.inline-form input {
  margin-bottom: 0;
}
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-faint);
  text-decoration: none;
  margin-bottom: 8px;
  transition: color 0.15s ease;
}
.back-link:hover {
  color: var(--text-muted);
}
.back-link i {
  font-size: 12px;
}
/* ----- MODAL (agent management) ----- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(6, 8, 12, 0.7);
  backdrop-filter: blur(2px);
  z-index: 500;
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding: 90px 20px 40px;
  overflow-y: auto;
}
.modal-overlay.open {
  display: flex;
}
.modal-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 30px 32px;
  width: 100%;
  max-width: 520px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}
.modal-header h3 {
  color: var(--text-heading);
  font-weight: 500;
  font-size: 19px;
}
.modal-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
}
.modal-close:hover {
  color: var(--text-heading);
}
.modal-actions {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 8px;
  flex-wrap: wrap;
}
.modal-actions .btn {
  flex: 1;
  justify-content: center;
  white-space: nowrap;
}

/* ----- Version tag ----- */
.version-tag {
  position: fixed;
  bottom: 20px;
  right: 20px;
  font-size: 12px;
  color: var(--text-faint);
  background: var(--bg-panel);
  border: 1px solid var(--border);
  padding: 6px 14px;
  border-radius: var(--radius-pill);
  z-index: 100;
  font-family: monospace;
  opacity: 0.7;
  transition: opacity 0.2s;
}
.version-tag:hover {
  opacity: 1;
}

/* ----- Logout button bottom left ----- */
/* .logout-bottom {
  position: fixed;
  bottom: 20px;
  left: 20px;
  z-index: 100;
} */
.logout-bottom .btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 8px 16px;
  border-radius: var(--radius-pill);
  cursor: pointer;
  font-size: 13px;
  transition: all 0.2s;
}
.logout-bottom .btn:hover {
  color: var(--danger);
  border-color: var(--danger);
  background: rgba(248, 113, 113, 0.05);
}







/* ============================================================
   TOOLS SECTION - Complete Styling Overhaul
   ============================================================ */

/* ---------- Subtab Bar ---------- */
.subtab-bar {
  /* display: flex; */
  gap: 4px;
  margin-bottom: 24px;
  border-bottom: 1px solid var(--border);
  padding: 0 2px 0 2px;
  flex-shrink: 0;
}
.subtab-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
  padding: 10px 20px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.2s ease;
  font-family: inherit;
  position: relative;
}
.subtab-btn:hover {
  color: var(--text-heading);
}
.subtab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* ---------- Subtab Panels ---------- */
.subtab-panel {
  display: none;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}
.subtab-panel.active {
  display: flex;
}

/* ---------- Usage Subtab (Tools Usage List) ---------- */
#tools-subtab-panel-usage.active {
  display: flex;
  flex-direction: column;
}

.tools-usage-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 4px 0;
}

.tool-usage-item {
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  transition: border-color 0.2s ease;
}
.tool-usage-item:hover {
  border-color: var(--accent);
}

.tool-usage-info {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
}

.tool-usage-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  flex-shrink: 0;
  font-size: 14px;
}

.tool-usage-details {
  flex: 1;
  min-width: 0;
}

.tool-usage-name {
  font-weight: 500;
  color: var(--text-heading);
  font-size: 14px;
}

.tool-usage-meta {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 2px;
}

.tool-usage-type {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 2px 10px;
  border-radius: 20px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
}

.tool-usage-type.api {
  color: var(--accent);
  border-color: rgba(114, 127, 213, 0.3);
  background: rgba(114, 127, 213, 0.08);
}

.tool-usage-type.document {
  color: #34d399;
  border-color: rgba(52, 211, 153, 0.3);
  background: rgba(52, 211, 153, 0.08);
}

.tool-usage-status {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--text-muted);
}

.tool-usage-status .status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  display: inline-block;
}

.tool-usage-status .status-dot.active {
  background: var(--success);
}

.tool-usage-status .status-dot.draft {
  background: var(--warning);
}

.tool-usage-status .status-dot.archived {
  background: var(--text-faint);
}

.tool-usage-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.tool-usage-actions .icon-btn-sm {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 6px;
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
}
.tool-usage-actions .icon-btn-sm:hover {
  color: var(--text-heading);
  border-color: var(--accent);
}

.tool-usage-connected {
  font-size: 11px;
  color: var(--text-faint);
  padding: 2px 10px;
  border-radius: 20px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  white-space: nowrap;
}

/* ---------- Custom Tools Subtab ---------- */
#tools-subtab-panel-manage.active {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* ---------- Sidebar in Custom Tools ---------- */
#tools-subtab-panel-manage .app-sidebar {
  width: 340px;
  min-width: 340px;
  max-width: 340px;
  padding: 20px;
  border-right: 1px solid var(--border);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

#tools-subtab-panel-manage .app-sidebar .sidebar-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  flex-shrink: 0;
}

#tools-subtab-panel-manage .app-sidebar .sidebar-heading span {
  font-weight: 500;
  color: var(--text-heading);
  font-size: 15px;
}

/* ---------- New Custom Tool Menu ---------- */
#new-custom-tool-menu {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
  padding: 4px 0;
}

.ctool-new-option {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s ease;
  justify-content: flex-start;
}

.ctool-new-option:hover {
  border-color: var(--accent);
  background: var(--bg-raised);
  color: var(--text-heading);
}

.ctool-new-option i {
  width: 18px;
  color: var(--accent);
  text-align: center;
}

/* ---------- New Tool Forms ---------- */
#new-api-tool-form,
#new-doc-tool-form,
#import-spec-form {
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 16px;
}

#new-api-tool-form label,
#new-doc-tool-form label,
#import-spec-form label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  display: block;
  margin-bottom: 4px;
  margin-top: 12px;
}

#new-api-tool-form label:first-child,
#new-doc-tool-form label:first-child,
#import-spec-form label:first-child {
  margin-top: 0;
}

#new-api-tool-form input,
#new-doc-tool-form input,
#import-spec-form input,
#new-api-tool-form select,
#import-spec-form select {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 12px;
  border-radius: var(--radius-md);
  width: 100%;
  font-family: inherit;
  font-size: 13px;
  margin-bottom: 0;
}

#new-api-tool-form textarea,
#new-doc-tool-form textarea {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 12px;
  border-radius: var(--radius-md);
  width: 100%;
  font-family: inherit;
  font-size: 13px;
  min-height: 60px;
  resize: vertical;
  margin-bottom: 0;
}

/* ---------- Type Filter Pills ---------- */
.ctool-type-filter {
  display: flex;
  gap: 6px;
  margin: 14px 0 12px;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.ctool-filter-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  padding: 4px 14px;
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
}

.ctool-filter-btn:hover {
  color: var(--text-heading);
  border-color: var(--text-muted);
}

.ctool-filter-btn.active {
  background: rgba(114, 127, 213, 0.12);
  border-color: var(--accent);
  color: var(--accent);
}

/* ---------- Custom Tool List ---------- */
#custom-tool-list {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 2px 0;
}

.custom-tool-item {
  padding: 10px 12px;
  border-radius: var(--radius-md);
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s ease;
  background: transparent;
}

.custom-tool-item:hover {
  background: var(--bg-raised);
  border-color: var(--border);
}

.custom-tool-item.active {
  background: var(--bg-raised);
  border-color: var(--accent);
}

.custom-tool-item .tool-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.custom-tool-item .tool-name {
  font-size: 14px;
  color: var(--text-heading);
  font-weight: 500;
}

.custom-tool-item .tool-badges {
  display: flex;
  gap: 4px;
  align-items: center;
  flex-shrink: 0;
}

.custom-tool-item .tool-desc {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- Chat/Detail Panel ---------- */
#tools-subtab-panel-manage .app-chat {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

#tools-subtab-panel-manage .chat-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

#tools-subtab-panel-manage .chat-header-title .name {
  font-weight: 500;
  color: var(--text-heading);
  font-size: 15px;
}

#tools-subtab-panel-manage .chat-header-title .sub {
  font-size: 12px;
  color: var(--text-faint);
}

.detail-panel {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
  min-height: 0;
}

/* ---------- Tool Detail View ---------- */
.tool-detail-card {
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 20px;
  margin-bottom: 16px;
}

.tool-detail-card .detail-row {
  display: flex;
  padding: 8px 0;
  border-bottom: 1px solid var(--border-soft);
}

.tool-detail-card .detail-row:last-child {
  border-bottom: none;
}

.tool-detail-card .detail-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  width: 100px;
  flex-shrink: 0;
}

.tool-detail-card .detail-value {
  font-size: 13px;
  color: var(--text);
  flex: 1;
  word-break: break-all;
}

.tool-detail-card .detail-value code {
  background: var(--bg-panel);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
  color: var(--accent);
}

/* ---------- Parameter List in Detail ---------- */
.param-detail-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 4px;
}

.param-detail-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
  background: var(--bg-panel);
  padding: 4px 10px;
  border-radius: 4px;
}

.param-detail-item .param-name {
  color: var(--text);
  font-weight: 500;
}

.param-detail-item .param-type {
  color: var(--text-faint);
  font-size: 11px;
}

.param-detail-item .param-required {
  font-size: 10px;
  color: var(--warning);
}

/* ---------- Responsive ---------- */
@media (max-width: 1024px) {
  #tools-subtab-panel-manage .app-sidebar {
    width: 280px;
    min-width: 280px;
    max-width: 280px;
    padding: 16px;
  }
}

@media (max-width: 820px) {
  .subtab-bar {
    overflow-x: auto;
    flex-wrap: nowrap;
  }
  .subtab-btn {
    white-space: nowrap;
    padding: 8px 14px;
    font-size: 13px;
  }

  #tools-subtab-panel-manage.active {
    flex-direction: column;
  }

  #tools-subtab-panel-manage .app-sidebar {
    width: 100%;
    min-width: 0;
    max-width: none;
    border-right: none;
    border-bottom: 1px solid var(--border);
    height: auto;
    max-height: 50vh;
    padding: 16px;
  }

  #tools-subtab-panel-manage .app-chat {
    height: auto;
    min-height: 40vh;
  }

  .tool-usage-item {
    flex-wrap: wrap;
  }

  .tool-usage-actions {
    width: 100%;
    justify-content: flex-end;
  }

  .param-row {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 480px) {
  .tool-usage-info {
    flex-wrap: wrap;
  }

  .tool-usage-meta {
    flex-wrap: wrap;
  }

  .tool-detail-card .detail-row {
    flex-direction: column;
    gap: 4px;
  }

  .tool-detail-card .detail-label {
    width: auto;
  }
}
