* {
  box-sizing: border-box;
}

:root {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #18212f;
  background: #f4f7fb;
}

body {
  margin: 0;
  min-height: 100vh;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: .55;
}

.hidden {
  display: none !important;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at top left, rgba(62, 94, 255, .16), transparent 35%),
    radial-gradient(circle at bottom right, rgba(126, 67, 255, .16), transparent 35%),
    #f7f9fc;
}

.login-card {
  width: min(420px, 100%);
  background: white;
  padding: 34px;
  border-radius: 24px;
  box-shadow: 0 24px 60px rgba(25, 39, 70, .12);
}

.brand-mark {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  border-radius: 16px;
  background: #18212f;
  color: white;
  font-weight: 800;
  font-size: 24px;
}

.brand-mark.small {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  font-size: 18px;
}

.login-card h1 {
  margin: 20px 0 4px;
}

.login-card p {
  margin: 0 0 24px;
  color: #6f7a8a;
}

label {
  display: grid;
  gap: 8px;
  margin: 14px 0;
  font-size: 14px;
  font-weight: 650;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid #dce2eb;
  border-radius: 12px;
  padding: 12px 14px;
  background: white;
  outline: none;
}

input:focus,
textarea:focus,
select:focus {
  border-color: #6d73ff;
  box-shadow: 0 0 0 3px rgba(109, 115, 255, .12);
}

button {
  border: 0;
  border-radius: 12px;
  padding: 11px 16px;
  background: #18212f;
  color: white;
  font-weight: 700;
}

.login-card button {
  width: 100%;
  margin-top: 10px;
}

.secondary {
  background: #edf1f6;
  color: #283244;
}

.ghost {
  background: transparent;
  color: #737f91;
  border: 1px solid #e0e5ed;
}

.error {
  margin-top: 14px;
  color: #b52b38;
  background: #fff0f1;
  border-radius: 10px;
  padding: 10px 12px;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 250px 1fr;
}

.sidebar {
  height: 100vh;
  position: sticky;
  top: 0;
  background: #121925;
  color: #e9edf5;
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 8px 24px;
}

.sidebar-brand span {
  display: block;
  color: #8e9aae;
  font-size: 12px;
  margin-top: 2px;
}

.sidebar nav {
  display: grid;
  gap: 5px;
}

.nav-item {
  background: transparent;
  color: #aeb8c8;
  text-align: left;
  font-weight: 600;
}

.nav-item:hover,
.nav-item.active {
  color: white;
  background: #202b3c;
}

.sidebar-footer {
  margin-top: auto;
  border-top: 1px solid #273245;
  padding: 16px 4px 2px;
}

.sidebar-footer .secondary {
  width: 100%;
  margin-top: 12px;
}

#userBadge {
  font-size: 13px;
  color: #b9c2d0;
}

.main {
  min-width: 0;
  padding: 28px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.topbar h1 {
  margin: 0;
  font-size: 28px;
}

.topbar p {
  margin: 5px 0 0;
  color: #758093;
}

.status-pill,
.permission-pill {
  border-radius: 999px;
  padding: 7px 10px;
  background: #e9f8ef;
  color: #257144;
  font-size: 12px;
  font-weight: 800;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 16px;
}

.card,
.panel {
  background: white;
  border: 1px solid #e4e8ef;
  border-radius: 18px;
  box-shadow: 0 10px 25px rgba(32, 45, 70, .05);
}

.card {
  padding: 20px;
}

.card h3 {
  margin: 0 0 8px;
}

.card p {
  color: #6f7a8a;
  min-height: 42px;
}

.card button {
  width: 100%;
  margin-top: 8px;
}

.panel {
  padding: 22px;
}

.panel-header {
  display: flex;
  gap: 14px;
  align-items: start;
  justify-content: space-between;
  margin-bottom: 20px;
}

.panel-header h2 {
  margin: 0;
}

.panel-header p {
  margin: 5px 0 0;
  color: #778294;
}

.conversation {
  min-height: 380px;
  max-height: 55vh;
  overflow-y: auto;
  border: 1px solid #e5e9f0;
  border-radius: 14px;
  padding: 16px;
  background: #fbfcfe;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 340px;
  color: #8b95a4;
}

.message {
  margin: 10px 0;
  padding: 12px 14px;
  border-radius: 14px;
  white-space: pre-wrap;
  line-height: 1.45;
}

.message.user {
  margin-left: 12%;
  background: #18212f;
  color: white;
}

.message.agent {
  margin-right: 12%;
  background: white;
  border: 1px solid #e2e7ef;
}

.composer {
  margin-top: 16px;
}

.composer textarea {
  resize: vertical;
  min-height: 100px;
}

.composer-actions {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-top: 10px;
}

.future-tools {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.project-picker {
  margin-bottom: 10px;
}

.project-picker label {
  margin-bottom: 6px;
}

.users-grid {
  display: grid;
  gap: 18px;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  text-align: left;
  padding: 12px 10px;
  border-bottom: 1px solid #edf0f4;
}

th {
  color: #667285;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.user-row {
  cursor: pointer;
}

.user-row:hover {
  background: #f8faff;
}

.user-row.selected {
  background: #eef3ff;
}

.user-chip {
  display: inline-block;
  background: #edf1f6;
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 12px;
}

.selected-user-summary {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  padding: 14px;
  border-radius: 14px;
  background: #f6f8fb;
  margin-bottom: 18px;
}

.admin-section {
  border-top: 1px solid #edf0f4;
  padding-top: 18px;
  margin-top: 18px;
}

.admin-section h3 {
  margin: 0 0 4px;
}

.admin-section p {
  margin: 0 0 12px;
  color: #758093;
  font-size: 14px;
}

.inline-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

.form-message {
  margin-top: 10px;
  padding: 9px 11px;
  border-radius: 10px;
  background: #eef8f1;
  color: #2d7045;
  font-size: 13px;
}

.form-message.error-state {
  background: #fff0f1;
  color: #b52b38;
}

.permission-table {
  width: 100%;
}

.permission-table th:not(:first-child),
.permission-table td:not(:first-child) {
  text-align: center;
}

.permission-table input[type="checkbox"],
.checkbox-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  margin: 0;
}

.permission-agent {
  font-weight: 700;
}

.permission-description {
  display: block;
  color: #7e899a;
  font-size: 12px;
  font-weight: 400;
  margin-top: 3px;
}

.save-permissions {
  margin-top: 14px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(17, 25, 37, .48);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 1000;
}

.modal {
  width: min(520px, 100%);
  background: white;
  border-radius: 20px;
  padding: 24px;
  box-shadow: 0 24px 70px rgba(18, 29, 49, .25);
}

.modal-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 10px;
}

.modal-header h2 {
  margin: 0;
}

.modal-header p {
  margin: 5px 0 0;
  color: #778294;
}

.checkbox-row {
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 10px;
}

@media (max-width: 800px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    height: auto;
    position: static;
  }

  .main {
    padding: 18px;
  }

  .topbar {
    align-items: flex-start;
    gap: 14px;
  }

  .inline-form {
    grid-template-columns: 1fr;
  }

  .permission-table {
    font-size: 13px;
  }
}

/* AI provider selector */
.status-pill.warning {
  background: #fff4dc;
  color: #8c5a12;
}

.ai-panel {
  max-width: 980px;
}

.ai-note {
  margin: -4px 0 20px;
  padding: 12px 14px;
  border-radius: 12px;
  background: #f5f7fb;
  color: #5f6b7c;
  font-size: 14px;
  line-height: 1.5;
}

.provider-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.provider-card {
  width: 100%;
  min-height: 170px;
  padding: 20px;
  border: 2px solid #e0e5ed;
  border-radius: 18px;
  background: #fff;
  color: #18212f;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 14px;
  transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease;
}


.provider-card.selected {
  border-color: #6d73ff;
  box-shadow: 0 0 0 3px rgba(109, 115, 255, .10);
}

.provider-card.unconfigured {
  opacity: .62;
  background: #f8f9fb;
}

.provider-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.provider-card-header strong {
  font-size: 18px;
}

.provider-status {
  border-radius: 999px;
  padding: 6px 9px;
  font-size: 11px;
  font-weight: 800;
  white-space: nowrap;
}

.provider-status.ready {
  background: #e9f8ef;
  color: #257144;
}

.provider-status.missing {
  background: #fff0f1;
  color: #a93642;
}

.provider-model {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 13px;
  color: #3f4a5d;
  overflow-wrap: anywhere;
}

.provider-help {
  margin-top: auto;
  color: #768196;
  font-size: 13px;
  line-height: 1.45;
}

.provider-actions {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 22px;
  flex-wrap: wrap;
}

.provider-actions .form-message {
  margin: 0;
}

@media (max-width: 760px) {
  .provider-grid {
    grid-template-columns: 1fr;
  }
}

/* Nimvexa brand assets */
.login-logo {
  display: block;
  width: min(310px, 100%);
  height: auto;
  object-fit: contain;
  margin: 0 0 10px;
}

.sidebar-logo-icon {
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  object-fit: contain;
  border-radius: 12px;
}

/* Provider + model selectors */
.ai-readonly-notice {
  margin: -8px 0 18px;
  padding: 11px 14px;
  border-radius: 12px;
  background: #eef2ff;
  color: #48538b;
  font-size: 13px;
  font-weight: 650;
}

.ai-selector-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.ai-field {
  margin: 0;
}

.ai-field span {
  color: #4e596b;
}

.provider-card.clickable {
  cursor: pointer;
}

.provider-card.clickable:hover {
  transform: translateY(-1px);
  border-color: #aab2ff;
  box-shadow: 0 10px 24px rgba(49, 58, 125, .08);
}

.provider-model-count {
  color: #8a94a5;
  font-size: 12px;
  font-weight: 650;
}

.status-pill {
  max-width: min(46vw, 620px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 760px) {
  .ai-selector-grid {
    grid-template-columns: 1fr;
  }

  .status-pill {
    max-width: 100%;
    white-space: normal;
  }
}

/* Persistent conversation history */
.agent-chat-layout {
  display: grid;
  grid-template-columns: minmax(220px, 280px) minmax(0, 1fr);
  gap: 16px;
  align-items: stretch;
}

.history-panel {
  min-width: 0;
  padding: 16px;
  border: 1px solid #e3e8f0;
  border-radius: 18px;
  background: #ffffff;
  box-shadow: 0 10px 28px rgba(23, 33, 52, .05);
}

.history-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}

.history-header h3 {
  margin: 0;
  font-size: 16px;
}

.history-header p {
  margin: 4px 0 0;
  color: #8993a3;
  font-size: 12px;
  line-height: 1.35;
}

button.compact {
  padding: 8px 10px;
  border-radius: 10px;
  font-size: 12px;
  white-space: nowrap;
}

.conversation-list {
  display: grid;
  gap: 7px;
  max-height: calc(100vh - 270px);
  overflow-y: auto;
  padding-right: 3px;
}

.history-empty {
  padding: 18px 10px;
  color: #929cab;
  font-size: 13px;
  text-align: center;
  border: 1px dashed #dfe5ed;
  border-radius: 12px;
}

.history-item {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 4px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: #f7f9fc;
  transition: background .15s ease, border-color .15s ease;
}

.history-item:hover {
  border-color: #dce3ee;
  background: #f2f5fa;
}

.history-item.active {
  border-color: #9fa7ff;
  background: #eef0ff;
  box-shadow: 0 0 0 2px rgba(109, 115, 255, .08);
}

.history-open {
  min-width: 0;
  display: grid;
  gap: 4px;
  padding: 11px 8px 11px 12px;
  text-align: left;
  background: transparent;
  color: #263145;
  border-radius: 11px;
}

.history-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  font-weight: 700;
}

.history-meta {
  color: #8a95a6;
  font-size: 11px;
  font-weight: 500;
}

.history-delete {
  align-self: center;
  width: 28px;
  height: 28px;
  padding: 0;
  margin-right: 5px;
  border-radius: 9px;
  background: transparent;
  color: #929cab;
  font-size: 19px;
  line-height: 1;
}

.history-delete:hover {
  background: #fff0f1;
  color: #a93642;
}

.chat-panel {
  min-width: 0;
}

@media (max-width: 980px) {
  .agent-chat-layout {
    grid-template-columns: 1fr;
  }

  .conversation-list {
    max-height: 220px;
  }
}

/* Universal agent memory */
.agent-header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.memory-count {
  display: inline-flex;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: rgba(139, 92, 246, 0.16);
  color: #c4b5fd;
  font-size: 12px;
  margin-left: 5px;
}

.memory-panel {
  margin: 0 18px 12px;
  padding: 16px;
  border: 1px solid rgba(139, 92, 246, 0.25);
  border-radius: 14px;
  background: rgba(21, 24, 42, 0.94);
  max-height: 330px;
  overflow: auto;
}

.memory-panel-header,
.memory-item-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.memory-panel-header > div {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.memory-panel-header span,
.memory-note,
.memory-item small {
  color: #8f96b3;
  font-size: 12px;
}

.memory-note {
  margin: 12px 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(139, 92, 246, 0.08);
}

.memory-list {
  display: grid;
  gap: 10px;
}

.memory-item {
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.025);
}

.memory-item strong {
  display: block;
  margin-top: 8px;
  color: #f5f7ff;
}

.memory-item p {
  margin: 6px 0 8px;
  color: #c8cee3;
  line-height: 1.45;
  white-space: pre-wrap;
}

.memory-scope,
.memory-type {
  display: inline-flex;
  padding: 3px 7px;
  border-radius: 999px;
  font-size: 11px;
}

.memory-scope {
  background: rgba(139, 92, 246, 0.15);
  color: #c4b5fd;
}

.memory-type {
  background: rgba(255, 255, 255, 0.06);
  color: #aeb6d4;
}

.memory-empty {
  padding: 14px;
  color: #8f96b3;
  text-align: center;
}

/*/* Autonomous background developer v1.5.1 */
.autonomous-box {
  margin-top: 12px;
  padding: 16px 18px;
  border: 1px solid #ddd6fe;
  border-radius: 16px;
  background: #f7f5ff;
  box-shadow: 0 1px 2px rgba(76, 29, 149, 0.04);
}

.autonomous-toggle {
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr);
  align-items: start;
  gap: 12px;
  width: 100%;
  cursor: pointer;
  text-align: left;
}

.autonomous-toggle input[type="checkbox"] {
  -webkit-appearance: checkbox;
  appearance: auto;
  width: 18px;
  height: 18px;
  min-width: 18px;
  margin: 2px 0 0;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: transparent;
  box-shadow: none;
  accent-color: #5b5bd6;
  cursor: pointer;
}

.autonomous-toggle input[type="checkbox"]:focus {
  border: 0;
  box-shadow: none;
  outline: 2px solid rgba(91, 91, 214, 0.28);
  outline-offset: 2px;
}

.autonomous-toggle span {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 5px;
}

.autonomous-toggle strong {
  color: #252a3a;
  font-size: 14px;
  line-height: 1.35;
}

.autonomous-toggle small {
  color: #65708a;
  font-size: 12px;
  line-height: 1.5;
}

.autonomous-safety {
  margin-top: 12px;
  padding: 12px 0 0 32px;
  border-top: 1px solid #e7e2fb;
  color: #7a849b;
  font-size: 12px;
  line-height: 1.5;
}

.autonomous-safety b {
  color: #555f76;
}

.background-job-status {
  margin-top: 12px;
  margin-left: 32px;
  padding: 11px 12px;
  border-radius: 10px;
  background: #eef4ff;
  border: 1px solid #cfe0ff;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.background-job-status small,
.background-job-status span {
  color: #65708a;
  line-height: 1.45;
}

.background-job-status.job-completed {
  background: #effaf3;
  border-color: #ccebd8;
}

.background-job-status.job-error {
  background: #fff2f2;
  border-color: #f2caca;
}

@media (max-width: 720px) {
  .autonomous-box {
    padding: 14px;
  }

  .autonomous-safety,
  .background-job-status {
    margin-left: 0;
    padding-left: 0;
  }

  .autonomous-safety {
    padding-top: 10px;
  }
}

/* Installable mobile app: keep controls reachable without horizontal scrolling. */
.install-bar {padding: 8px max(16px, env(safe-area-inset-right)) 8px max(16px, env(safe-area-inset-left)); display:flex;gap:12px;align-items:center;flex-wrap:wrap;font-size:13px;}
.install-bar:has(> .hidden):not(:has(> :not(.hidden))) {display:none;}
.mobile-menu {display:none;}
.main {padding-bottom:max(24px,env(safe-area-inset-bottom));min-width:0;}
.conversation pre {max-width:100%;overflow:auto;}
@media(max-width:800px){
 .mobile-menu {display:block;min-height:44px;}
 .sidebar {display:none;height:auto;}
 .app-shell.mobile-menu-open .sidebar {display:flex;}
 .topbar {flex-wrap:wrap;}
 .topbar h1 {font-size:24px;}
 input,select,textarea {font-size:16px;max-width:100%;}
 .composer-actions,.agent-header-actions,.history-header {flex-wrap:wrap;}
 .future-tools {flex-wrap:wrap;}
 .panel {min-width:0;}
 .permission-table {display:block;max-width:100%;overflow:auto;}
 .main {padding-left:max(14px,env(safe-area-inset-left));padding-right:max(14px,env(safe-area-inset-right));}
}
