/* Theme tokens:
   se vuoi cambiare colori in futuro, qui hai il punto centrale. */
:root {
  --mobile-header-height: 48px;
  --mobile-safe-bottom: env(safe-area-inset-bottom, 0px);
  --app-height: 100dvh;
  --color-page-bg: #f5f8ff;
  --color-surface: #ffffff;
  --color-surface-soft: #f8faff;
  --color-surface-muted: #edf2fb;
  --color-border: #d9e2f1;
  --color-border-strong: #bfd0ea;
  --color-sidebar: linear-gradient(180deg, #edf3ff 0%, #f6f8ff 58%, #fff5f8 100%);
  --color-sidebar-item: #dbe5f7;
  --color-sidebar-item-hover: #cfdbf2;
  --color-sidebar-item-active: #a9bfe4;
  --color-header: linear-gradient(135deg, #eef4ff 0%, #f9fbff 52%, #fff6f8 100%);
  --color-header-text: #22324a;
  --color-user-msg: #e8f1ff;
  --color-accent: #2f6fed;
  --color-accent-strong: #2456c8;
  --color-accent-soft: #e4eeff;
  --color-accent-text: #ffffff;
  --color-text-muted: #64748b;
  --color-code-bg: #111;
  --color-code-text: #0f0;
  --color-bot-msg: #f4f6f8;
  --color-bot-avatar: #d8dee7;
  --color-user-avatar: #d4e2ff;
  --shadow-composer: 0 10px 24px rgba(15, 23, 42, 0.08);
  --shadow-composer-focus: 0 12px 30px rgba(37, 99, 235, 0.14);
  --shadow-header: 0 12px 30px rgba(36, 86, 200, 0.08);
}

body {
  margin: 0;
  font-family: Arial;
  background: var(--color-page-bg);
}

[hidden] {
  display: none !important;
}

.container {
  height: 100vh;
  height: var(--app-height);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#login {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  box-sizing: border-box;
  background:
    radial-gradient(circle at top left, rgba(47, 111, 237, 0.12), transparent 28%),
    radial-gradient(circle at bottom right, rgba(180, 35, 77, 0.08), transparent 24%),
    linear-gradient(180deg, #f8fbff 0%, #eef4ff 54%, #fff7fa 100%);
}

.login-card {
  width: min(920px, 100%);
  display: grid;
  grid-template-columns: 1.2fr 0.9fr;
  gap: 28px;
  align-items: stretch;
  padding: 26px;
  border: 1px solid rgba(191, 208, 234, 0.9);
  border-radius: 30px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: 0 24px 60px rgba(36, 86, 200, 0.12);
  backdrop-filter: blur(12px);
}

.login-brand {
  display: flex;
  gap: 18px;
  align-items: flex-start;
  padding: 18px;
  border-radius: 24px;
  background:
    radial-gradient(circle at top right, rgba(47, 111, 237, 0.12), transparent 34%),
    linear-gradient(180deg, rgba(244, 248, 255, 0.95) 0%, rgba(255, 255, 255, 0.88) 100%);
  border: 1px solid rgba(191, 208, 234, 0.6);
}

.login-brand img {
  width: 72px;
  height: 72px;
  padding: 12px;
  border-radius: 22px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.98) 0%, rgba(228, 238, 255, 0.92) 100%);
  box-shadow: 0 16px 32px rgba(47, 111, 237, 0.14);
  object-fit: contain;
}

.login-brand-copy {
  min-width: 0;
}

.login-kicker {
  display: inline-flex;
  align-items: center;
  margin-bottom: 8px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(47, 111, 237, 0.1);
  color: var(--color-accent-strong);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.login-brand h3 {
  margin: 0;
  font-size: clamp(28px, 4vw, 42px);
  line-height: 1.05;
  color: #162338;
}

.login-brand p {
  margin: 10px 0 0;
  max-width: 42ch;
  font-size: 15px;
  line-height: 1.55;
  color: var(--color-text-muted);
}

.login-fields {
  display: flex;
  flex-direction: column;
  gap: 12px;
  justify-content: center;
  padding: 18px;
  border-radius: 24px;
  background: linear-gradient(180deg, rgba(248, 250, 255, 0.98) 0%, rgba(255, 255, 255, 0.92) 100%);
  border: 1px solid rgba(191, 208, 234, 0.6);
}

.login-fields input {
  width: 100%;
  box-sizing: border-box;
  padding: 14px 15px;
  border: 1px solid rgba(191, 208, 234, 0.95);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.98);
  color: #162338;
  font-size: 15px;
  font-weight: 600;
}

.login-fields input:focus {
  outline: none;
  border-color: rgba(47, 111, 237, 0.55);
  box-shadow: 0 0 0 4px rgba(47, 111, 237, 0.12);
}

.login-btn {
  margin-top: 4px;
  padding: 14px 16px;
  border: none;
  border-radius: 16px;
  background: linear-gradient(180deg, #2f6fed 0%, #2457c8 100%);
  color: #fff;
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 14px 24px rgba(47, 111, 237, 0.18);
}

.chat-wrapper {
  display: flex;
  flex: 1;
  min-height: 0;
  transition: gap 0.25s ease;
}

/* ===== SIDEBAR ===== */
.sidebar {
  width: 220px;
  flex: 0 0 220px;
  background: var(--color-sidebar);
  padding: 12px 10px;
  overflow-y: auto;
  border-right: 1px solid rgba(191, 208, 234, 0.72);
  transition: width 0.26s ease, flex-basis 0.26s ease, padding 0.26s ease, border-color 0.26s ease, opacity 0.2s ease;
}

.sidebar > button {
  width: 100%;
  margin-bottom: 10px;
}

.chat-wrapper.sidebar-collapsed .sidebar {
  width: 0;
  flex-basis: 0;
  padding-left: 0;
  padding-right: 0;
  border-right-color: transparent;
  opacity: 0;
  overflow: hidden;
}

.new-chat-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-bottom: 10px;
  padding: 8px 10px;
  border: 1px solid rgba(37, 99, 235, 0.22);
  border-radius: 10px;
  background: linear-gradient(180deg, #f8fbff 0%, #eef4ff 100%);
  color: #1f2937;
  font-weight: 600;
  letter-spacing: 0.01em;
  font-size: 13px;
  box-shadow: 0 4px 10px rgba(15, 23, 42, 0.05);
  transition: transform 0.18s ease, box-shadow 0.18s ease,
    border-color 0.18s ease, background-color 0.18s ease;
}

.new-chat-btn:hover {
  transform: translateY(-1px);
  border-color: rgba(37, 99, 235, 0.35);
  box-shadow: 0 10px 18px rgba(15, 23, 42, 0.08);
}


.session {
  position: relative;
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  min-height: 20px;
  padding: 4px 28px 4px 10px;
  margin-bottom: 4px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.92) 0%, rgba(226, 235, 248, 0.96) 100%);
  cursor: pointer;
  border: 1px solid rgba(0, 0, 0, 0.05);
  border-radius: 10px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.55);
  transition: transform 0.15s ease, box-shadow 0.15s ease,
    background-color 0.15s ease, border-color 0.15s ease;
  overflow: visible;
  line-height: 1.15;
}

.session-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session.search-result {
  align-items: flex-start;
  align-content: flex-start;
  padding-top: 7px;
  padding-bottom: 7px;
}

.session:hover {
  background: linear-gradient(180deg, #f8fbff 0%, #dfe8f8 100%);
  transform: translateY(-1px);
  box-shadow: 0 8px 16px rgba(15, 23, 42, 0.08);
}

.session.active {
  background: linear-gradient(180deg, #d4e1fb 0%, #b6cbf2 100%);
  border-color: rgba(37, 99, 235, 0.42);
  box-shadow: inset 4px 0 0 #2563eb, 0 8px 18px rgba(37, 99, 235, 0.16);
  font-weight: bold;
}

.session.pending {
  background: linear-gradient(180deg, #f2f7ff 0%, #deebff 100%);
  border-color: rgba(47, 111, 237, 0.22);
}

.session-state {
  margin-left: 10px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--color-accent);
  white-space: nowrap;
  opacity: 0.9;
}

.session-search-snippet {
  display: block;
  margin-top: 4px;
  font-size: 11px;
  line-height: 1.35;
  color: #5b6b84;
  white-space: normal;
  width: 100%;
}

.session-search-meta {
  display: block;
  width: 100%;
  margin-top: 3px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #1d4ed8;
}

.session.pinned {
  box-shadow: inset 3px 0 0 var(--color-accent), inset 0 1px 0 rgba(255, 255, 255, 0.5);
}

.session.archived {
  opacity: 0.86;
}

.sidebar-search {
  margin: 8px 0 10px;
}

.sidebar-search-input {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid rgba(148, 163, 184, 0.35);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.9);
  font-size: 13px;
  color: #1e293b;
  box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.04);
}

.sidebar-search-input:focus {
  outline: none;
  border-color: rgba(37, 99, 235, 0.35);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.sidebar-search-input::placeholder {
  color: #64748b;
}

/* Sezioni collassabili della sidebar: tengono separati chat e allegati senza appesantire il composer. */
.sidebar-section {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid rgba(0, 0, 0, 0.08);
}

.sidebar-section-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0 0 8px;
  padding: 0;
  border: none;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.sidebar-section-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #42526b;
}

.sidebar-section-chevron {
  width: 8px;
  height: 8px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
  transition: transform 0.16s ease;
  flex: 0 0 auto;
  margin-top: -2px;
  color: #5b6b84;
}

.sidebar-section-toggle.collapsed .sidebar-section-chevron {
  transform: rotate(-45deg);
}

/* Ogni chat nella sidebar resta una riga pulita; le azioni secondarie vivono in un menu a comparsa. */
.session-row {
  position: relative;
  display: flex;
  align-items: stretch;
  gap: 0;
  margin-bottom: 4px;
}

.session-project-header {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 12px 4px 6px;
  padding: 0 6px;
  border: none;
  background: transparent;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #5b6b84;
  text-align: left;
  cursor: pointer;
}

.session-archive-header {
  margin: 14px 4px 6px;
  padding: 0 6px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #41516a;
}

.sessions-empty-state {
  margin: 8px 4px 10px;
  padding: 10px 12px;
  border: 1px dashed rgba(148, 163, 184, 0.5);
  border-radius: 12px;
  font-size: 12px;
  color: #64748b;
  background: rgba(255, 255, 255, 0.45);
}

.session-project-chevron {
  width: 8px;
  height: 8px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
  transition: transform 0.16s ease;
  flex: 0 0 auto;
  margin-top: -2px;
}

.session-project-header.collapsed .session-project-chevron {
  transform: rotate(-45deg);
}

.session-row.menu-open {
  z-index: 30;
}

.session-row .session {
  flex: 1;
  margin-bottom: 0;
}

.session-menu-shell {
  position: absolute;
  top: calc(100% + 6px);
  right: 4px;
  z-index: 40;
}

.session-menu-btn {
  position: absolute;
  top: 50%;
  right: 4px;
  transform: translateY(-50%);
  width: 24px;
  min-width: 24px;
  height: 24px;
  margin-bottom: 0;
  padding: 0;
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
  color: #111827;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s ease, transform 0.2s ease;
}

.session-menu-btn:hover {
  background: rgba(255, 255, 255, 0.98);
  transform: translateY(calc(-50% - 1px));
}

.session-menu-btn svg,
.session-menu-item svg {
  width: 11px;
  height: 11px;
  fill: currentColor;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.session-menu {
  position: absolute;
  top: 0;
  right: 0;
  min-width: 150px;
  padding: 6px;
  border: 1px solid var(--color-border);
  border-radius: 12px;
  background: var(--color-surface);
  box-shadow: 0 16px 32px rgba(15, 23, 42, 0.18);
  display: none;
  z-index: 1;
}

.session-menu.open {
  display: block;
}

.session-menu-item {
  width: 100%;
  margin-bottom: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 9px;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: #111827;
  cursor: pointer;
  font-size: 12px;
  text-align: left;
  transition: background-color 0.15s ease, transform 0.15s ease;
}

.session-menu-item:hover {
  background: var(--color-accent-soft);
  transform: translateX(1px);
}

.session-menu-item.danger {
  color: #991b1b;
}

.session-menu-item.danger:hover {
  background: rgba(239, 68, 68, 0.1);
}

.session-menu-item span {
  flex: 1;
}

.session-menu-section-title {
  padding: 8px 10px 4px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #64748b;
}

.session-menu-item-project {
  padding-left: 14px;
}

/* ===== MAIN ===== */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: 1;
  min-width: 0;
  min-height: 0;
}

.chat-main-view,
.admin-main-view {
  flex: 1;
  min-height: 0;
}

.chat-main-view {
  position: relative;
  display: flex;
  flex-direction: column;
}

.header {
  background: var(--color-header);
  color: var(--color-header-text);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  justify-content: space-between;
  border-bottom: 1px solid rgba(191, 208, 234, 0.9);
  box-shadow: var(--shadow-header);
  position: relative;
  z-index: 26;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex-shrink: 0;
}

.header-brand img {
  width: 38px;
  height: 38px;
  object-fit: contain;
  padding: 6px;
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.92) 0%, rgba(228, 238, 255, 0.88) 100%);
  box-shadow: 0 8px 18px rgba(47, 111, 237, 0.12);
}

.header-brand-copy {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.header-brand-title {
  font-size: 15px;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: 0.01em;
}

.header-brand-subtitle {
  font-size: 11px;
  color: var(--color-text-muted);
  line-height: 1.2;
}

.header-brand-version {
  margin-top: 2px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: rgba(34, 50, 74, 0.56);
  line-height: 1.2;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  justify-content: flex-start;
  min-width: 0;
}

.menu-btn {
  position: relative;
  z-index: 50;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  min-width: 42px;
  height: 42px;
  border: 1px solid rgba(191, 208, 234, 0.95);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.88);
  color: #22324a;
  font-size: 18px;
  box-shadow: 0 6px 16px rgba(36, 86, 200, 0.06);
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}

.menu-btn:hover {
  transform: translateY(-1px);
  border-color: rgba(47, 111, 237, 0.35);
  box-shadow: 0 10px 20px rgba(36, 86, 200, 0.1);
}

.menu-btn svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  stroke-width: 1.55;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

/* Select agent/model: compatte ma leggibili sia in desktop che in mobile. */
#agentSelect,
#modelSelect {
  min-width: 120px;
  max-width: 220px;
  padding: 9px 12px;
  border: 1px solid rgba(191, 208, 234, 0.95);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.88);
  color: #162338;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 6px 16px rgba(36, 86, 200, 0.06);
}

#modelSelect {
  max-width: 280px;
}

#thinkingSelect {
  min-width: 140px;
  max-width: 180px;
  padding: 9px 12px;
  border: 1px solid rgba(191, 208, 234, 0.95);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.88);
  color: #162338;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 6px 16px rgba(36, 86, 200, 0.06);
}

#agentSelect:disabled,
#modelSelect:disabled {
  opacity: 0.8;
  cursor: wait;
}

#thinkingSelect:focus,
#agentSelect:focus,
#modelSelect:focus {
  outline: none;
  border-color: rgba(47, 111, 237, 0.55);
  box-shadow: 0 0 0 4px rgba(47, 111, 237, 0.12);
}

.header-account {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.mobile-settings-btn {
  display: none;
}

.mobile-settings-ai {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 9px;
  background: linear-gradient(135deg, rgba(47, 111, 237, 0.18) 0%, rgba(109, 168, 255, 0.28) 100%);
  color: #2157c8;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.04em;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.75);
}

.user-pill {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 6px 10px 6px 6px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid rgba(191, 208, 234, 0.85);
  box-shadow: 0 8px 18px rgba(36, 86, 200, 0.06);
}

.user-pill-avatar {
  width: 34px;
  height: 34px;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #2f6fed 0%, #6da8ff 100%);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  box-shadow: 0 8px 16px rgba(47, 111, 237, 0.24);
}

.user-pill-copy {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.user-pill-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
}

.user-pill-name {
  font-size: 14px;
  font-weight: 700;
  color: #162338;
  white-space: nowrap;
}

.logout-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px 8px 8px;
  border: 1px solid rgba(255, 167, 187, 0.55);
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.92) 0%, rgba(255, 238, 243, 0.95) 100%);
  color: #b4234d;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 10px 20px rgba(180, 35, 77, 0.08);
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}

.logout-btn-icon {
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  background: rgba(255, 233, 239, 0.96);
  border: 1px solid rgba(180, 35, 77, 0.15);
  padding: 2px;
  color: #9f1239;
}

.logout-btn-icon svg {
  width: 17px;
  height: 17px;
  stroke: currentColor;
  stroke-width: 2.45;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

.logout-btn:hover {
  transform: translateY(-1px);
  border-color: rgba(180, 35, 77, 0.35);
  box-shadow: 0 14px 24px rgba(180, 35, 77, 0.12);
}

.admin-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px 8px 10px;
  border: 1px solid rgba(191, 208, 234, 0.95);
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.92) 0%, rgba(244, 248, 255, 0.98) 100%);
  color: #22324a;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 8px 18px rgba(36, 86, 200, 0.08);
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}

.admin-btn svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

.admin-btn:hover {
  transform: translateY(-1px);
  border-color: rgba(47, 111, 237, 0.35);
  box-shadow: 0 14px 24px rgba(36, 86, 200, 0.12);
}

.admin-btn.active {
  border-color: rgba(47, 111, 237, 0.55);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.98) 0%, rgba(227, 236, 255, 1) 100%);
  box-shadow: 0 14px 24px rgba(36, 86, 200, 0.14);
}

.admin-overlay {
  position: fixed;
  inset: 0;
  display: none;
  background: rgba(15, 23, 42, 0.34);
  backdrop-filter: blur(2px);
  z-index: 60;
}

.admin-overlay.show {
  display: block;
}

.admin-panel {
  position: relative;
  flex: 1;
  min-height: 0;
  width: auto;
  display: none;
  flex-direction: column;
  gap: 12px;
  padding: 18px;
  border-radius: 0;
  background: rgba(250, 252, 255, 0.98);
  border-left: 1px solid rgba(191, 208, 234, 0.66);
  overflow-y: auto;
}

.admin-panel.open {
  display: flex;
}

.admin-panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.admin-panel-kicker {
  display: inline-flex;
  align-items: center;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(47, 111, 237, 0.1);
  color: var(--color-accent-strong);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.admin-panel-title {
  margin: 6px 0 0;
  font-size: 22px;
  line-height: 1.1;
  color: #162338;
}

.admin-panel-subtitle {
  margin: 6px 0 0;
  font-size: 13px;
  line-height: 1.45;
  color: var(--color-text-muted);
}

.admin-panel-close {
  min-width: 76px;
  height: 38px;
  padding: 0 14px;
  border: 1px solid rgba(191, 208, 234, 0.9);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.95);
  color: #22324a;
  cursor: pointer;
  box-shadow: 0 8px 16px rgba(36, 86, 200, 0.08);
}

.admin-panel-status {
  min-height: 20px;
  font-size: 12px;
  line-height: 1.45;
  color: var(--color-text-muted);
}

.admin-panel-status[data-tone="success"] {
  color: #117a43;
}

.admin-panel-status[data-tone="error"] {
  color: #b4234d;
}

.admin-panel-status[data-tone="warning"] {
  color: #9a5b00;
}

.admin-tabbar {
  display: inline-flex;
  align-self: flex-start;
  gap: 8px;
  padding: 4px;
  border-radius: 16px;
  background: rgba(233, 240, 250, 0.88);
}

.admin-tab {
  border: 0;
  border-radius: 12px;
  padding: 8px 12px;
  background: transparent;
  color: #52637b;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
}

.admin-tab.active {
  background: rgba(255, 255, 255, 0.98);
  color: #162338;
  box-shadow: 0 6px 14px rgba(36, 86, 200, 0.08);
}

.admin-section {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.admin-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  padding: 14px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(191, 208, 234, 0.78);
}

.admin-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.admin-field span {
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-muted);
}

.admin-field input,
.admin-field select,
.admin-field textarea {
  width: 100%;
  box-sizing: border-box;
  padding: 10px 12px;
  border: 1px solid rgba(191, 208, 234, 0.95);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.98);
  color: #162338;
  font-size: 14px;
  font-weight: 600;
}

.admin-field input:focus,
.admin-field select:focus,
.admin-field textarea:focus {
  outline: none;
  border-color: rgba(47, 111, 237, 0.55);
  box-shadow: 0 0 0 4px rgba(47, 111, 237, 0.12);
}

.admin-field textarea {
  min-height: 160px;
  resize: vertical;
  font-family: inherit;
  line-height: 1.45;
}

.admin-field-wide,
.admin-field-full {
  grid-column: 1 / -1;
}

.admin-bootstrap-presets {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.admin-bootstrap-presets-label {
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-muted);
  margin-right: 4px;
}

.admin-switch {
  grid-column: 1 / -1;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 700;
  color: #22324a;
}

.admin-switch input {
  width: 16px;
  height: 16px;
  accent-color: var(--color-accent);
}

.admin-widget-policy-grid {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px 18px;
}

.admin-widget-policy-grid .admin-switch {
  grid-column: auto;
  min-height: 28px;
}

.admin-form-actions {
  grid-column: 1 / -1;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.admin-section-top-actions {
  margin-top: -2px;
  margin-bottom: 2px;
}

.admin-list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 8px;
}

.admin-list-title {
  color: #22324a;
  font-size: 16px;
  font-weight: 900;
}

.admin-inline-save-meta {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  color: var(--color-text-muted);
  font-size: 13px;
  font-weight: 800;
}

.admin-inline-save-meta[data-tone="success"] {
  color: #117a43;
}

.admin-inline-save-meta[data-tone="error"] {
  color: #b4234d;
}

.admin-inline-save-meta[data-tone="info"] {
  color: var(--color-accent-strong);
}

.admin-inline-save-meta[data-tone="warning"] {
  color: #ad6800;
}

.admin-primary-btn,
.admin-secondary-btn,
.admin-danger-btn {
  border: none;
  border-radius: 14px;
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
}

.admin-primary-btn {
  background: linear-gradient(180deg, #2f6fed 0%, #2457c8 100%);
  color: #fff;
  box-shadow: 0 12px 20px rgba(47, 111, 237, 0.18);
}

.admin-secondary-btn {
  background: rgba(233, 240, 250, 0.96);
  color: #22324a;
}

.admin-danger-btn {
  background: rgba(255, 233, 238, 0.98);
  color: #b42349;
  box-shadow: inset 0 0 0 1px rgba(228, 91, 129, 0.28);
}

.admin-user-list {
  display: block;
  padding-bottom: 6px;
  overflow-x: auto;
}

.admin-empty {
  padding: 8px 2px;
  color: var(--color-text-muted);
  font-size: 13px;
}

.admin-user-table {
  width: 100%;
  min-width: 620px;
  border-collapse: separate;
  border-spacing: 0;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid rgba(191, 208, 234, 0.82);
  border-radius: 20px;
  overflow: hidden;
  box-shadow: 0 10px 20px rgba(36, 86, 200, 0.06);
}

.admin-user-table th,
.admin-user-table td {
  padding: 14px 16px;
  border-bottom: 1px solid rgba(221, 230, 243, 0.88);
  text-align: left;
  vertical-align: middle;
}

.admin-user-table th {
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
  background: rgba(246, 249, 255, 0.94);
}

.admin-user-table tbody tr:last-child td {
  border-bottom: 0;
}

.admin-user-row.active {
  background: rgba(232, 241, 255, 0.6);
}

.admin-user-name-cell {
  font-size: 15px;
  font-weight: 800;
  color: #162338;
  word-break: break-word;
}

.admin-user-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.admin-badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.admin-badge.role-admin {
  background: rgba(47, 111, 237, 0.12);
  color: var(--color-accent-strong);
}

.admin-badge.role-user {
  background: rgba(233, 240, 250, 0.95);
  color: #52637b;
}

.admin-badge.status-on {
  background: rgba(17, 122, 67, 0.12);
  color: #117a43;
}

.admin-badge.status-off {
  background: rgba(180, 35, 77, 0.1);
  color: #b4234d;
}

.admin-user-actions {
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
  align-items: center;
}

.admin-actions-cell {
  width: 1%;
  white-space: nowrap;
}

.admin-workspace-list,
.admin-workspace-docs {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.admin-model-provider-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(520px, 1fr));
  gap: 14px;
  align-items: start;
}

.admin-models-note {
  padding: 12px 14px;
  border: 1px solid rgba(191, 208, 234, 0.78);
  border-radius: 16px;
  background: rgba(246, 249, 255, 0.86);
  color: #52637b;
  font-size: 13px;
  line-height: 1.45;
}

.admin-model-provider-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px;
  border: 1px solid rgba(191, 208, 234, 0.78);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.92);
}

.admin-model-provider-card.needs-env {
  background: rgba(248, 250, 253, 0.82);
}

.admin-model-provider-header,
.admin-model-key-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
}

.admin-model-key-row {
  grid-template-columns: minmax(0, 1fr);
}

.admin-model-provider-title {
  font-size: 16px;
  font-weight: 900;
  color: #162338;
}

.admin-model-provider-meta {
  margin-top: 4px;
  font-size: 12px;
  color: var(--color-text-muted);
}

.admin-model-provider-switch,
.admin-model-clear-switch {
  grid-column: auto;
  white-space: nowrap;
}

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

.admin-model-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid rgba(191, 208, 234, 0.78);
  border-radius: 14px;
  background: rgba(246, 249, 255, 0.72);
  color: #22324a;
  cursor: pointer;
}

.admin-model-option-label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  cursor: pointer;
}

.admin-model-option.disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

.admin-model-option input {
  width: 16px;
  height: 16px;
  accent-color: var(--color-accent);
}

.admin-model-option span {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.admin-model-option strong {
  font-size: 12px;
  word-break: break-word;
}

.admin-model-option em {
  flex: 0 0 auto;
  padding: 3px 7px;
  border-radius: 999px;
  background: rgba(47, 111, 237, 0.12);
  color: var(--color-accent-strong);
  font-size: 10px;
  font-style: normal;
  font-weight: 900;
  text-transform: uppercase;
}

.admin-model-remove-btn {
  flex: 0 0 auto;
  width: 24px;
  height: 24px;
  border: 1px solid rgba(255, 83, 126, 0.35);
  border-radius: 10px;
  background: rgba(255, 245, 248, 0.9);
  color: #c9184a;
  font-size: 18px;
  font-weight: 900;
  line-height: 1;
  cursor: pointer;
}

.admin-model-remove-btn:hover {
  border-color: rgba(255, 83, 126, 0.7);
  background: rgba(255, 231, 237, 0.95);
}

.admin-model-catalog-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}

.admin-model-catalog-select {
  min-width: 0;
}

.admin-telegram-card {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 14px;
  border: 1px solid rgba(191, 208, 234, 0.78);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.92);
}

.admin-card-heading h4 {
  margin: 0;
  font-size: 18px;
  color: #1d3557;
}

.admin-card-heading p {
  margin: 6px 0 0;
  color: var(--color-text-muted);
  font-size: 13px;
  line-height: 1.45;
}

.admin-telegram-settings,
.admin-telegram-form,
.admin-telegram-contact-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  align-items: end;
}

.admin-telegram-settings .admin-switch {
  min-height: 44px;
  align-self: end;
}

.admin-telegram-form .admin-form-actions {
  grid-column: auto;
  align-self: end;
}

.admin-telegram-contact-form {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.admin-telegram-contact-form .admin-form-actions {
  align-self: end;
}

.admin-telegram-pairing-controls {
  display: grid;
  grid-template-columns: 1.2fr 1fr 1fr;
  gap: 12px;
  align-items: end;
}

.admin-telegram-pairing-controls .admin-form-actions {
  grid-column: 1 / -1;
}

.admin-telegram-table {
  min-width: 760px;
}

.admin-telegram-table input,
.admin-telegram-table select {
  width: 100%;
  min-width: 160px;
}

/* In modalita' consultazione lasciamo visibili dati e ricarica, ma non azioni
   che modificherebbero configurazione o stato operativo. */
.admin-panel.admin-readonly #adminResetBtn,
.admin-panel.admin-readonly #adminWorkspaceForm,
.admin-panel.admin-readonly #adminModelProvidersSaveBtn,
.admin-panel.admin-readonly #adminTelegramSaveBtn,
.admin-panel.admin-readonly #adminTelegramAccountForm,
.admin-panel.admin-readonly #adminTelegramPairingApproveBtn,
.admin-panel.admin-readonly #adminTelegramContactsSaveBtn,
.admin-panel.admin-readonly #adminTelegramContactForm,
.admin-panel.admin-readonly #adminMailTab,
.admin-panel.admin-readonly #adminWorkspaceDocDeleteBtn,
.admin-panel.admin-readonly #adminDevtoolsSection .admin-primary-btn,
.admin-panel.admin-readonly #adminDevtoolsSection .admin-danger-btn,
.admin-panel.admin-readonly #adminSchedulerForm,
.admin-panel.admin-readonly #adminSchedulerClearRunsBtn,
.admin-panel.admin-readonly .admin-action-btn.danger,
.admin-panel.admin-readonly .admin-action-btn.warning,
.admin-panel.admin-readonly .admin-workspace-actions {
  display: none !important;
}

.admin-panel.admin-readonly #adminUserForm .admin-field:first-child,
.admin-panel.admin-readonly #adminUserForm .admin-field:nth-child(3),
.admin-panel.admin-readonly #adminUserForm .admin-switch {
  display: none;
}

.admin-panel.admin-readonly input:not(#adminPassword),
.admin-panel.admin-readonly select,
.admin-panel.admin-readonly textarea {
  pointer-events: none;
}

.admin-mail-table {
  min-width: 920px;
}

.admin-mail-form {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

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

.admin-devtools-token-form {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.admin-devtools-token-form .admin-switch {
  min-height: 44px;
  align-self: end;
}

.admin-devtools-grid textarea {
  min-height: 420px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.admin-scheduler-form {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.admin-scheduler-table {
  min-width: 1040px;
}

.admin-scheduler-runs-table {
  min-width: 980px;
}

.admin-scheduler-run-detail {
  padding: 14px;
  border: 1px solid rgba(191, 208, 234, 0.82);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 10px 20px rgba(36, 86, 200, 0.06);
}

.admin-scheduler-run-detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.admin-scheduler-run-detail-meta {
  margin-bottom: 10px;
  color: var(--color-text-muted);
  font-size: 12px;
  font-weight: 700;
}

.admin-scheduler-run-detail pre {
  max-height: 420px;
  overflow: auto;
  margin: 0;
  padding: 12px;
  border-radius: 14px;
  background: rgba(247, 250, 255, 0.98);
  color: #162338;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  line-height: 1.5;
}

@media (max-width: 1440px) {
  .admin-mail-form,
  .admin-scheduler-form {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 1180px) {
  .admin-devtools-grid {
    grid-template-columns: 1fr;
  }

  .admin-devtools-token-form {
    grid-template-columns: 1fr;
  }
}

.admin-workspace-actions {
  align-items: center;
}

.admin-workspace-table th:nth-child(1),
.admin-workspace-table td:nth-child(1) {
  width: 132px;
}

.admin-workspace-path-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.admin-workspace-path {
  font-size: 13px;
  color: var(--color-text-muted);
  word-break: break-word;
}

.admin-workspace-docs {
  padding: 14px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(191, 208, 234, 0.78);
}

.admin-workspace-docs-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.admin-workspace-assist {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  border: 1px solid rgba(191, 208, 234, 0.72);
  border-radius: 16px;
  background: rgba(246, 249, 255, 0.82);
}

.admin-workspace-create-note {
  padding: 12px 14px;
  border-radius: 16px;
  border: 1px dashed rgba(191, 208, 234, 0.86);
  background: rgba(246, 249, 255, 0.7);
  color: #52637b;
  font-size: 13px;
  line-height: 1.45;
}

.admin-workspace-assist-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.admin-workspace-assist-controls .admin-field {
  flex: 1 1 220px;
}

.admin-workspace-assist-controls .admin-builder-model-field {
  flex: 0 1 300px;
}

.admin-assist-cta {
  flex: 0 0 auto;
  align-self: end;
  min-height: 48px;
  border: none;
  border-radius: 14px;
  padding: 0 18px;
  color: #fff;
  background: linear-gradient(180deg, #2f6fed 0%, #174ec4 100%);
  box-shadow: 0 14px 24px rgba(47, 111, 237, 0.22);
  font-size: 13px;
  font-weight: 900;
  cursor: pointer;
  white-space: nowrap;
}

.admin-assist-cta:hover {
  transform: translateY(-1px);
  box-shadow: 0 18px 28px rgba(47, 111, 237, 0.28);
}

.admin-assist-cta:disabled {
  cursor: wait;
  opacity: 0.72;
  transform: none;
  box-shadow: none;
}

.admin-workspace-assist-meta {
  min-height: 18px;
  font-size: 12px;
  color: var(--color-text-muted);
}

.admin-workspace-assist-meta[data-tone="success"] {
  color: #117a43;
}

.admin-workspace-assist-meta[data-tone="error"] {
  color: #b4234d;
}

.admin-workspace-assist-meta[data-tone="info"] {
  color: #2157c8;
}

.admin-workspace-docs-alert {
  padding: 12px 14px;
  border-radius: 16px;
  border: 1px solid rgba(255, 196, 0, 0.32);
  background: rgba(255, 247, 214, 0.88);
  color: #8a5a00;
  font-size: 13px;
  line-height: 1.45;
}

.admin-agents-common-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid rgba(191, 208, 234, 0.78);
  background: rgba(246, 249, 255, 0.86);
  color: #52637b;
  font-size: 13px;
  line-height: 1.35;
}

.admin-agents-common-status[data-tone="success"] {
  border-color: rgba(40, 167, 69, 0.28);
  background: rgba(235, 249, 240, 0.9);
  color: #117a43;
}

.admin-agents-common-status[data-tone="warning"] {
  border-color: rgba(255, 196, 0, 0.38);
  background: rgba(255, 247, 214, 0.88);
  color: #8a5a00;
}

.admin-agents-common-status[data-tone="info"] {
  color: #2157c8;
}

.admin-workspace-skill-panel {
  margin: 12px 0;
  padding: 14px;
  border: 1px solid rgba(148, 163, 184, 0.35);
  border-radius: 8px;
  background: rgba(248, 250, 252, 0.86);
}

.admin-workspace-skill-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.admin-workspace-skill-head h4 {
  margin: 2px 0 0;
  font-size: 15px;
  color: #0f172a;
}

.admin-workspace-skill-panel p {
  margin: 10px 0 12px;
  color: #475569;
  line-height: 1.45;
}

.admin-workspace-skill-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
}

.admin-workspace-skill-config {
  margin-top: 12px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.admin-workspace-skill-description {
  margin-top: 12px;
  display: grid;
  gap: 8px;
}

.admin-workspace-skill-description p {
  margin: 0;
}

.admin-field-help {
  display: block;
  margin-top: 6px;
  color: #64748b;
  font-size: 12px;
  line-height: 1.45;
}

.admin-workspace-skill-status {
  width: fit-content;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
}

.admin-workspace-skill-status[data-tone="success"] {
  color: #117a43;
  background: rgba(40, 167, 69, 0.12);
}

.admin-workspace-skill-status[data-tone="info"] {
  color: #2157c8;
  background: rgba(37, 99, 235, 0.1);
}

.admin-workspace-skill-kind {
  width: fit-content;
  padding: 4px 8px;
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.06);
  color: #334155;
  font-size: 12px;
  font-weight: 800;
}

.admin-workspace-skill-rag-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}

.admin-workspace-skill-rag-result {
  padding: 10px 12px;
  border: 1px solid rgba(148, 163, 184, 0.32);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.76);
  color: #334155;
  font-size: 13px;
  line-height: 1.4;
}

.admin-workspace-skill-rag-result[data-tone="success"] {
  border-color: rgba(40, 167, 69, 0.28);
  background: rgba(235, 249, 240, 0.86);
}

.admin-workspace-skill-rag-result[data-tone="error"] {
  border-color: rgba(220, 38, 38, 0.32);
  background: rgba(254, 242, 242, 0.9);
  color: #991b1b;
}

.rag-progress-wrap {
  display: grid;
  gap: 6px;
}

.rag-progress-label {
  font-size: 13px;
  color: #475569;
}

.rag-progress-bar-track {
  height: 10px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.22);
  overflow: hidden;
}

.rag-progress-bar-fill {
  height: 100%;
  border-radius: 999px;
  background: #3b82f6;
  transition: width 0.4s ease;
}

.rag-progress-bar-fill[data-tone="success"] {
  background: #22c55e;
}

.rag-progress-bar-fill[data-tone="error"] {
  background: #ef4444;
}

.rag-progress-pct {
  font-size: 12px;
  font-weight: 700;
  color: #64748b;
  text-align: right;
}

.admin-workspace-skill-rag-result ul {
  margin: 8px 0 0;
  padding-left: 18px;
}

.admin-workspace-skill-rag-result li {
  margin: 6px 0;
}

.admin-workspace-skill-rag-result code {
  display: inline-block;
  max-width: 100%;
  overflow-wrap: anywhere;
  white-space: normal;
  color: #475569;
}

.admin-workspace-docs-help {
  padding: 12px 14px;
  border-radius: 16px;
  border: 1px solid rgba(191, 208, 234, 0.72);
  background: rgba(255, 255, 255, 0.82);
  color: #44546b;
  font-size: 13px;
  line-height: 1.5;
}

.admin-workspace-docs-help-title {
  margin-bottom: 8px;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #22324a;
}

.admin-workspace-docs-help ul {
  margin: 0 0 10px 18px;
  padding: 0;
}

.admin-workspace-docs-help p {
  margin: 0;
}

.admin-workspace-docs-help code {
  padding: 1px 5px;
  border-radius: 999px;
  background: rgba(233, 240, 250, 0.95);
  color: #22324a;
  font-size: 12px;
}

.admin-workspace-docs-title {
  margin: 6px 0 0;
  font-size: 18px;
  color: #162338;
}

.admin-workspace-docs-toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr) auto;
  gap: 10px;
}

.admin-workspace-docs-toolbar select,
.admin-workspace-docs-toolbar input {
  width: 100%;
  box-sizing: border-box;
  padding: 10px 12px;
  border: 1px solid rgba(191, 208, 234, 0.95);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.98);
  color: #162338;
  font-size: 14px;
  font-weight: 600;
}

.admin-workspace-doc-editor {
  width: 100%;
  box-sizing: border-box;
  min-height: 280px;
  padding: 12px 14px;
  border: 1px solid rgba(191, 208, 234, 0.95);
  border-radius: 16px;
  background: rgba(248, 250, 255, 0.98);
  color: #162338;
  font-size: 14px;
  line-height: 1.5;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.admin-action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(191, 208, 234, 0.9);
  border-radius: 12px;
  background: rgba(245, 248, 255, 0.96);
  color: #22324a;
  padding: 8px 10px;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
}

.admin-action-btn.icon-only {
  width: 38px;
  min-width: 38px;
  height: 38px;
  padding: 0;
}

.admin-action-btn svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

.admin-action-btn.warning {
  border-color: rgba(17, 122, 67, 0.32);
  background: rgba(238, 251, 244, 0.98);
  color: #117a43;
}

.admin-action-btn.success {
  border-color: rgba(191, 208, 234, 0.9);
  background: rgba(245, 248, 255, 0.96);
  color: #64748b;
}

.workspace-download-btn {
  position: relative;
  background: rgba(255, 255, 255, 0.98);
  border-color: rgba(191, 208, 234, 0.9);
  box-shadow: none;
}

.workspace-download-btn img {
  width: 18px;
  height: 18px;
  display: block;
  object-fit: contain;
}

.admin-action-btn.danger {
  border-color: rgba(255, 167, 187, 0.65);
  background: rgba(255, 241, 245, 0.98);
  color: #b4234d;
}

.overlay {
  z-index: 40;
  pointer-events: none;
}

.overlay.show {
  display: block;
  pointer-events: auto;
}
/* ===== CHAT ===== */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--color-surface);
  min-height: 0;
}

.scroll-to-bottom-btn {
  position: absolute;
  left: 50%;
  bottom: calc(var(--composer-offset, 92px) + 12px);
  width: 42px;
  height: 42px;
  border: 1px solid rgba(191, 208, 234, 0.95);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.96);
  color: #243041;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 12px 24px rgba(15, 23, 42, 0.12);
  cursor: pointer;
  z-index: 8;
  transform: translateX(-50%);
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}

.scroll-to-bottom-btn:hover {
  transform: translate(-50%, -1px);
  border-color: rgba(47, 111, 237, 0.35);
  box-shadow: 0 14px 28px rgba(15, 23, 42, 0.16);
}

.scroll-to-bottom-btn svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

.msg-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  max-width: 100%;
  scroll-margin-top: 18px;
}

.msg-row.user {
  justify-content: flex-end;
  align-items: flex-end;
  position: relative;
}

.msg-row.user .msg-avatar {
  order: 2;
}

.msg-row.user .msg {
  order: 1;
}

.msg-avatar {
  flex: 0 0 22px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #243041;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.5);
}

.msg-row.bot .msg-avatar {
  margin-top: 5px;
}

.msg-avatar.bot {
  border-radius: 9px;
  padding: 1px;
  overflow: hidden;
  background: linear-gradient(180deg, #eef3f8 0%, var(--color-bot-avatar) 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.72);
}

.msg-avatar.user {
  background: linear-gradient(180deg, #e8f0ff 0%, var(--color-user-avatar) 100%);
}

.msg-avatar.bot img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  border-radius: 6px;
  filter: saturate(1.08) contrast(1.02);
  transition: filter 0.2s ease, transform 0.2s ease;
}

.msg-avatar.bot.thinking img {
  transform: scale(0.98);
}

.msg-avatar.bot[data-thinking-level="off"] {
  background: linear-gradient(180deg, #f1f5f9 0%, #e2e8f0 100%);
}

.msg-avatar.bot[data-thinking-level="off"] img {
  filter: grayscale(1) saturate(0.7) brightness(1.06);
}

.msg-avatar.bot[data-thinking-level="minimal"] {
  background: linear-gradient(180deg, #ffffff 0%, #edf2f7 100%);
}

.msg-avatar.bot[data-thinking-level="minimal"] img {
  filter: none;
}

.msg-avatar.bot[data-thinking-level="low"] {
  background: linear-gradient(180deg, #edf2f7 0%, #cfd6e0 100%);
}

.msg-avatar.bot[data-thinking-level="low"] img {
  filter: hue-rotate(26deg) saturate(1.18) brightness(1.02) contrast(1.04);
}

.msg-avatar.bot[data-thinking-level="medium"] {
  background: linear-gradient(180deg, #b4bcc8 0%, #6d7583 100%);
}

.msg-avatar.bot[data-thinking-level="medium"] img {
  filter: hue-rotate(112deg) saturate(1.5) brightness(0.99) contrast(1.08);
}

.msg-avatar.bot[data-thinking-level="adaptive"] {
  background: linear-gradient(180deg, #6d7583 0%, #2f3440 100%);
}

.msg-avatar.bot[data-thinking-level="adaptive"] img {
  filter: hue-rotate(123deg) saturate(1.82) brightness(0.96) contrast(1.12);
}

.msg-avatar.bot[data-thinking-level="high"] {
  background: linear-gradient(180deg, #1a1c22 0%, #020203 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.msg-avatar.bot[data-thinking-level="high"] img {
  filter: hue-rotate(125deg) saturate(2.2) brightness(0.94) contrast(1.18);
}

.msg {
  margin: 0;
  padding: 11px 14px;
  border-radius: 16px;
  max-width: min(72%, 760px);
  min-width: 0;
  line-height: 1.6;
  font-size: 14px;
  box-sizing: border-box;
  overflow: visible;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.msg-row.search-hit .msg {
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.22), 0 10px 24px rgba(37, 99, 235, 0.12);
}

.msg-search-mark {
  padding: 0 2px;
  border-radius: 4px;
  background: rgba(250, 204, 21, 0.55);
  color: inherit;
}

.msg.user {
  background: var(--color-user-msg);
  border-bottom-right-radius: 6px;
}

.msg-attachments {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
}

.msg-attachment {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.16);
  border: 1px solid rgba(255, 255, 255, 0.24);
}

.msg-row.bot .msg-attachment {
  background: rgba(15, 23, 42, 0.04);
  border-color: rgba(15, 23, 42, 0.08);
}

.msg-attachment-icon {
  font-size: 20px;
  line-height: 1;
}

.msg-attachment-text {
  min-width: 0;
}

.msg-attachment-name {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.msg-attachment-meta {
  font-size: 12px;
  opacity: 0.82;
}

.msg-attachment-download {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(255,255,255,0.18);
  color: inherit;
  text-decoration: none;
  font-size: 14px;
  opacity: 0.7;
  transition: opacity 0.15s ease, background 0.15s ease;
}

.msg-attachment-download:hover {
  opacity: 1;
  background: rgba(255,255,255,0.34);
}

.msg-row.bot .msg-attachment-download {
  background: rgba(15,23,42,0.06);
  color: var(--color-text);
}

.msg-row.bot .msg-attachment-download:hover {
  background: rgba(15,23,42,0.12);
}

.user-msg-actions {
  position: absolute;
  top: -12px;
  right: 34px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 4px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid rgba(191, 208, 234, 0.9);
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.08);
  opacity: 0;
  transform: translateY(4px);
  pointer-events: none;
  transition: opacity 0.16s ease, transform 0.16s ease;
}

.msg-row.user:hover .user-msg-actions,
.msg-row.user:focus-within .user-msg-actions {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.user-msg-action-btn {
  width: 24px;
  height: 24px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: #42526b;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background-color 0.16s ease, color 0.16s ease, transform 0.16s ease;
}

.user-msg-action-btn:hover {
  background: rgba(47, 111, 237, 0.08);
  color: #22324a;
  transform: translateY(-1px);
}

.user-msg-action-btn.done {
  background: rgba(22, 163, 74, 0.12);
  color: #15803d;
}

.user-msg-action-btn svg {
  width: 14px;
  height: 14px;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

.msg.bot {
  background: var(--color-bot-msg);
  border: 1px solid rgba(15, 23, 42, 0.05);
  border-bottom-left-radius: 6px;
}

.msg.bot.streaming {
  border: 1px solid var(--color-border);
}

.msg > :first-child {
  margin-top: 0;
}

.msg > :last-child {
  margin-bottom: 0;
}

.msg p + p,
.msg p + ul,
.msg p + ol,
.msg ul + p,
.msg ol + p,
.msg pre + p {
  margin-top: 10px;
}

.msg a {
  color: var(--color-accent-strong);
  text-underline-offset: 2px;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.msg strong {
  color: #111827;
}

.msg li,
.msg td,
.msg th,
.msg blockquote {
  overflow-wrap: anywhere;
  word-break: break-word;
}

.msg-workspace-links {
  margin-top: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.msg-workspace-link {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 11px;
  border-radius: 11px;
  border: 1px solid rgba(47, 111, 237, 0.16);
  background: rgba(255, 255, 255, 0.88);
  color: #24407d;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(47, 111, 237, 0.08);
  transition: transform 0.16s ease, box-shadow 0.16s ease, background-color 0.16s ease;
}

.msg-workspace-link:hover {
  transform: translateY(-1px);
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 8px 16px rgba(47, 111, 237, 0.12);
}

.msg-workspace-link-missing {
  border-color: rgba(185, 28, 28, 0.16);
  background: rgba(254, 242, 242, 0.88);
  color: #991b1b;
  cursor: default;
  box-shadow: none;
}

.msg-workspace-link-missing:hover {
  transform: none;
  background: rgba(254, 242, 242, 0.88);
  box-shadow: none;
}

.msg-workspace-link svg {
  width: 14px;
  height: 14px;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
  flex: 0 0 auto;
}

.typing-dots {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-width: 34px;
}

.typing-dots span {
  width: 6px;
  height: 6px;
  background: var(--color-text-muted);
  border-radius: 50%;
  opacity: 0.35;
  animation: typingPulse 1s infinite ease-in-out;
}

.typing-dots span:nth-child(2) {
  animation-delay: 0.15s;
}

.typing-dots span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes typingPulse {
  0%,
  80%,
  100% {
    opacity: 0.35;
    transform: translateY(0);
  }

  40% {
    opacity: 1;
    transform: translateY(-3px);
  }
}

/* ===== INPUT CHATGPT ===== */
/* Il composer resta visivamente leggero, ma con bordo/ombra piu' chiari
   per avvicinarsi a una UI tipo chat moderna senza cambiare struttura HTML. */
.input {
  position: relative;
  padding: 10px;
  background: var(--color-surface-soft);
  border-top: 1px solid var(--color-border);
}

.slash-menu {
  position: absolute;
  z-index: 20;
  left: 14px;
  bottom: calc(100% - 8px);
  width: min(320px, calc(100% - 28px));
  padding: 6px;
  border: 1px solid var(--color-border);
  border-radius: 12px;
  background: var(--color-surface);
  box-shadow: var(--shadow-composer);
}

.slash-menu[hidden],
.slash-menu-item[hidden] {
  display: none;
}

.slash-menu-item {
  display: flex;
  align-items: baseline;
  width: 100%;
  gap: 10px;
  padding: 9px 10px;
  border: 0;
  border-radius: 8px;
  color: var(--color-text);
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.slash-menu-item:hover,
.slash-menu-item.is-active {
  background: var(--color-accent-soft);
}

.slash-menu-command {
  font-weight: 700;
}

.slash-menu-description {
  color: var(--color-text-muted);
  font-size: 12px;
}

/* box principale */
.input-box {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  border: 1px solid var(--color-border-strong);
  border-radius: 18px;
  padding: 10px 12px;
  background: var(--color-surface);
  gap: 8px;
  box-shadow: var(--shadow-composer);
  transition: border-color 0.2s ease, box-shadow 0.2s ease,
    background-color 0.2s ease;
  cursor: text;
}

/* Evidenzia il composer quando textarea o pulsanti interni hanno focus. */
.input-box:focus-within {
  border-color: var(--color-accent);
  box-shadow: var(--shadow-composer-focus);
}

/* Quando c'e' testo, il composer guadagna un po' piu' presenza visiva. */
.input-box.has-value {
  border-color: color-mix(in srgb, var(--color-accent) 30%, var(--color-border-strong));
}

/* textarea */
.input-box textarea {
  flex: 1;
  display: block;
  border: none;
  resize: none;
  outline: none;
  font-size: 14px;
  max-height: 150px;
  min-height: 32px;
  margin: 0;
  padding: 6px 2px;
  box-sizing: border-box;
  background: transparent;
  line-height: 1.45;
}

.composer-attachments {
  flex: 0 0 100%;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 2px 0 4px;
}

.composer-attachment-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--color-border);
  border-radius: 14px;
  background: rgba(15, 23, 42, 0.03);
}

.composer-attachment-icon {
  font-size: 16px;
  line-height: 1;
}

.composer-attachment-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.composer-attachment-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.composer-attachment-meta {
  font-size: 11px;
  color: var(--color-text-muted);
}

.composer-attachment-remove {
  border: none;
  background: transparent;
  color: var(--color-text-muted);
  cursor: pointer;
  border-radius: 999px;
  width: 24px;
  height: 24px;
  flex: 0 0 auto;
}

.composer-attachment-remove:hover {
  background: rgba(15, 23, 42, 0.08);
  color: var(--color-text);
}

.input-box textarea::placeholder {
  color: var(--color-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* tools */
.input-tools {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: default;
}

/* bottoni icona */
.icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 18px;
  padding: 6px;
  border-radius: 10px;
  transition: background-color 0.2s ease, transform 0.2s ease;
}

.icon-btn:hover {
  background: var(--color-accent-soft);
}

.attach-btn {
  color: #4b5563;
}

.icon-btn.reuse {
  color: #475467;
  background: rgba(15, 23, 42, 0.04);
  border: 1px solid rgba(15, 23, 42, 0.08);
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
}

.icon-btn.reuse:hover {
  background: rgba(15, 23, 42, 0.08);
}

/* invio */
.icon-btn.send {
  background: var(--color-accent);
  color: var(--color-accent-text);
  border-radius: 50%;
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
}

.icon-btn.send:hover {
  background: var(--color-accent-strong);
  transform: translateY(-1px);
}

/* Stato disabled semplice: il bottone resta visibile ma comunica che non puo' inviare. */
.icon-btn.send:disabled {
  background: var(--color-border-strong);
  cursor: not-allowed;
  transform: none;
  opacity: 0.75;
}

.icon-btn.send:disabled:hover {
  background: var(--color-border-strong);
}

.icon-btn.stop {
  background: #fff4f4;
  color: #b42318;
  border: 1px solid rgba(180, 35, 24, 0.15);
  border-radius: 50%;
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
}

.icon-btn.stop:hover {
  background: #ffe8e8;
  transform: translateY(-1px);
}

/* drag */
.input-box.dragover {
  border-color: var(--color-accent);
  background: var(--color-accent-soft);
}

/* Riga di supporto sotto il composer per scorciatoie e feedback upload. */
.composer-status {
  min-height: 18px;
  padding: 0;
  color: var(--color-text-muted);
  font-size: 12px;
  line-height: 1.4;
}

.composer-status.is-loading {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.composer-status.is-loading::before {
  content: "";
  width: 12px;
  height: 12px;
  border-radius: 999px;
  border: 2px solid rgba(37, 99, 235, 0.18);
  border-top-color: #2563eb;
  animation: composer-status-spin 0.8s linear infinite;
  flex: 0 0 auto;
}

@keyframes composer-status-spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

.composer-meta-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 6px;
  padding: 0 4px;
}

.activity-panel {
  display: inline-flex;
  align-items: flex-start;
  gap: 8px;
  min-height: 18px;
  flex-wrap: wrap;
}

.activity-log {
  font-size: 11px;
  color: #64748b;
}

.activity-log summary {
  cursor: pointer;
  user-select: none;
}

.activity-log-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 6px;
}

.activity-log-list .activity-chip {
  white-space: normal;
}

.activity-chip {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  line-height: 1.35;
  color: #334155;
  background: rgba(15, 23, 42, 0.05);
  border: 1px solid rgba(15, 23, 42, 0.06);
  white-space: nowrap;
}

.activity-chip.info {
  background: rgba(37, 99, 235, 0.08);
  color: #1d4ed8;
}

.activity-chip.success {
  background: rgba(22, 163, 74, 0.1);
  color: #15803d;
}

.activity-chip.warning {
  background: rgba(245, 158, 11, 0.12);
  color: #b45309;
}

.activity-chip.error {
  background: rgba(239, 68, 68, 0.1);
  color: #b91c1c;
}

/* Piccolo pannello informativo sugli upload recenti del workspace selezionato. */
.upload-panel {
  margin-top: 8px;
  padding: 8px 10px;
  border: 1px solid var(--color-border);
  border-radius: 12px;
  background: var(--color-surface);
  color: #374151;
  font-size: 12px;
  line-height: 1.45;
}

.upload-panel .upload-panel-title {
  display: block;
  margin-bottom: 6px;
  font-weight: 700;
  color: #111827;
}

.upload-panel .upload-panel-empty {
  color: var(--color-text-muted);
}

.upload-panel .upload-chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.upload-panel .upload-chip {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--color-accent-soft);
  color: #1f2937;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.upload-panel .upload-chip.upload-chip-detailed {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 6px;
  border-radius: 14px;
  white-space: normal;
}

.upload-panel .upload-chip.upload-chip-detailed > span,
.upload-panel .upload-chip.upload-chip-detailed > small {
  flex: 1 1 auto;
  min-width: 0;
  display: block;
}

.upload-chip-download {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  color: var(--color-text-muted);
  text-decoration: none;
  font-size: 13px;
  opacity: 0.7;
  transition: opacity 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.upload-chip-download:hover {
  opacity: 1;
  background: rgba(15,23,42,0.08);
  color: var(--color-text);
}

.upload-panel .upload-chip-time {
  font-size: 10px;
  color: var(--color-text-muted);
}

.upload-panel .upload-meta {
  display: block;
  margin-top: 6px;
  color: var(--color-text-muted);
  font-size: 11px;
}

.upload-panel-sidebar {
  margin-top: 0;
  padding: 0;
  border: none;
  background: transparent;
}

.upload-panel-sidebar .upload-meta {
  margin-top: 8px;
}

.workspace-file-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.workspace-file-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 7px 8px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.5);
  border: 1px solid rgba(15, 23, 42, 0.06);
}

.workspace-file-link {
  color: var(--color-accent-strong);
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.workspace-file-link:hover {
  text-decoration: underline;
}

.workspace-file-meta {
  color: var(--color-text-muted);
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.workspace-file-time {
  color: #64748b;
  font-size: 10px;
}

.workspace-file-actor {
  color: #64748b;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.workspace-file-source {
  display: inline-flex;
  align-self: flex-start;
  margin-top: 4px;
  padding: 2px 6px;
  border-radius: 999px;
  font-size: 10px;
  line-height: 1.2;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #475569;
  background: rgba(148, 163, 184, 0.14);
}


pre {
  background: #0f172a;
  color: #e5eefc;
  padding: 12px 14px;
  border-radius: 12px;
  overflow-x: auto;
  border: 1px solid rgba(148, 163, 184, 0.18);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

preGpt {
  background: #0d1117;
  color: #c9d1d9;
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

:not(pre) > code {
  padding: 0.18em 0.4em;
  border-radius: 6px;
  background: rgba(15, 23, 42, 0.06);
  color: #0f172a;
  font-size: 0.95em;
  white-space: break-spaces;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.msg p {
  margin: 0;
}

.msg pre {
  margin: 8px 0;
  max-width: 100%;
  white-space: pre-wrap;
  overflow-x: auto;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.msg ul,
.msg ol {
  margin: 8px 0;
  padding-left: 18px;
}

.msg-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
  margin-top: 10px;
}

.msg-footer-meta {
  font-size: 11px;
  line-height: 1.3;
  color: var(--color-text-muted);
  text-align: right;
}

.msg-footer-rag {
  border: 1px solid #b8ddc7;
  border-radius: 999px;
  background: #e6f4ec;
  color: #0f5d3c;
  font-size: 11px;
  line-height: 1.1;
  padding: 3px 8px;
  white-space: nowrap;
}

.msg-footer-rag[data-rag-status="no_match"],
.msg-footer-rag[data-rag-status="not_indexed"] {
  border-color: #d9d2a6;
  background: #f8f2d8;
  color: #6c5a12;
}

.msg-footer-rag[data-rag-status="disabled"] {
  border-color: #d8c5c5;
  background: #f6ecec;
  color: #7a3434;
}

.msg-thinking-block {
  margin: 0 0 12px;
  border: 1px solid #cfdcf8;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.66);
  overflow: clip;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.msg-thinking-block summary {
  cursor: pointer;
  list-style: none;
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 700;
  color: #4667b0;
  background: rgba(85, 126, 235, 0.08);
}

.msg-thinking-block summary::-webkit-details-marker {
  display: none;
}

.msg-thinking-block[open] summary {
  border-bottom: 1px solid #d9e4fb;
}

.msg-thinking-block > :not(summary) {
  margin: 0;
  padding: 12px 14px 14px;
  max-height: 360px;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* wrapper codice */
.code-wrapper {
  position: relative;
  margin: 8px 0;
}

/* bottone copia */
.copy-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  background: rgba(0,0,0,0.7);
  color: white;
  border: none;
  border-radius: 6px;
  padding: 3px 8px;
  font-size: 12px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s;
}

/* appare al hover */
.code-wrapper:hover .copy-btn {
  opacity: 1;
}


/* ===== OVERLAY ===== */
.overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.4);
  display: none;
  z-index: 5;
}

.overlay.show {
  display: block;
}

/* ===== MOBILE ===== */
@media (max-width: 768px) {
  body {
    overflow: hidden;
  }

  .container {
    height: var(--app-height);
  }

  .chat-wrapper {
    height: 100%;
  }

  .menu-btn {
    position: relative;
    z-index: 30;
    width: 38px;
    min-width: 38px;
    height: 38px;
    border-radius: 12px;
    font-size: 17px;
  }

  .header {
    position: sticky;
    top: 0;
    z-index: 25;
    min-height: var(--mobile-header-height);
    box-sizing: border-box;
    padding: 8px 10px;
    gap: 8px;
    align-items: center;
  }

  .header-brand-copy,
  .user-pill-label {
    display: none;
  }

  .header-brand img {
    width: 32px;
    height: 32px;
    padding: 5px;
    border-radius: 12px;
  }

  .header-brand-title {
    font-size: 13px;
  }

  .header-controls {
    display: none;
  }

  .mobile-settings-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    min-width: 38px;
    height: 38px;
    padding: 0;
    border: 1px solid rgba(191, 208, 234, 0.95);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.88);
    color: #22324a;
    box-shadow: 0 6px 16px rgba(36, 86, 200, 0.06);
    cursor: pointer;
  }

  .mobile-settings-ai {
    width: 23px;
    height: 23px;
    border-radius: 10px;
    font-size: 11px;
    letter-spacing: 0.05em;
  }

  .mobile-settings-btn:hover {
    border-color: rgba(47, 111, 237, 0.35);
    box-shadow: 0 10px 20px rgba(36, 86, 200, 0.1);
  }

  .mobile-toolbar-panel {
    display: none;
    padding: 10px 12px 12px;
    background: rgba(255, 255, 255, 0.92);
    border-bottom: 1px solid rgba(191, 208, 234, 0.72);
    box-shadow: 0 10px 20px rgba(36, 86, 200, 0.08);
  }

  .mobile-toolbar-panel.open {
    display: block;
  }

  .mobile-toolbar-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
  }

  .mobile-toolbar-row:last-child {
    margin-bottom: 0;
  }

  .mobile-toolbar-row label {
    min-width: 64px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-text-muted);
  }

  #agentSelectMobile,
  #modelSelectMobile,
  #thinkingSelectMobile {
    flex: 1;
    min-width: 0;
    padding: 8px 10px;
    border: 1px solid rgba(191, 208, 234, 0.95);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.98);
    color: #162338;
    font-size: 12px;
    font-weight: 600;
  }

  #modelSelect,
  #agentSelect,
  #thinkingSelect {
    display: none;
  }

  .header-account {
    gap: 6px;
  }

  .admin-btn {
    padding: 7px 9px;
    border-radius: 14px;
  }

  .admin-btn span {
    display: none;
  }

  .header-brand-version {
    font-size: 9px;
  }

  .user-pill {
    padding: 4px 8px 4px 4px;
    border-radius: 14px;
  }

  .user-pill-avatar {
    width: 28px;
    height: 28px;
    border-radius: 10px;
    font-size: 12px;
  }

  .user-pill-name {
    font-size: 12px;
    max-width: 72px;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .logout-btn {
    padding: 7px;
    min-width: 38px;
    height: 38px;
    border-radius: 12px;
    justify-content: center;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.98) 0%, rgba(255, 235, 241, 0.98) 100%);
    border-color: rgba(180, 35, 77, 0.38);
    box-shadow: 0 8px 16px rgba(180, 35, 77, 0.1);
  }

  .logout-btn > span:not(.logout-btn-icon) {
    display: none;
  }

  .logout-btn-icon {
    width: 26px;
    height: 26px;
    padding: 0;
    border-radius: 8px;
    background: rgba(255, 231, 238, 1);
    border-color: rgba(180, 35, 77, 0.2);
    color: #9f1239;
  }

  .logout-btn-icon svg {
    width: 18px;
    height: 18px;
    stroke-width: 2.7;
    fill: none;
  }

  #login {
    padding: 14px;
  }

  .login-card {
    grid-template-columns: 1fr;
    gap: 16px;
    padding: 16px;
    border-radius: 22px;
  }

  .login-brand {
    padding: 14px;
    align-items: center;
  }

  .login-brand img {
    width: 56px;
    height: 56px;
    padding: 10px;
    border-radius: 18px;
    flex: 0 0 auto;
  }

  .login-brand h3 {
    font-size: 28px;
  }

  .login-brand p {
    font-size: 14px;
  }

  .login-fields {
    padding: 14px;
  }

  .sidebar {
    position: fixed;
    top: var(--mobile-header-height);
    left: calc(-260px - 20px);       /* nascosta davvero, incluso il padding */
    width: 260px;
    flex-basis: auto;
    height: calc(var(--app-height) - var(--mobile-header-height) - var(--mobile-safe-bottom));
    z-index: 20;
    transition: left 0.3s ease;
    padding-bottom: calc(10px + var(--mobile-safe-bottom));
    box-sizing: border-box;
    opacity: 1;
    border-right-color: rgba(191, 208, 234, 0.72);
  }

  .sidebar.open {
    left: 0;            /* visibile */
  }

  .chat-wrapper.sidebar-collapsed .sidebar {
    left: calc(-260px - 20px);
    width: 260px;
    flex-basis: auto;
    padding-left: 10px;
    padding-right: 10px;
    opacity: 1;
  }

  .main {
    width: 100%;
    overflow: hidden;
  }

  .overlay {
    z-index: 15;
  }

  .messages {
    padding: 12px 12px calc(12px + var(--mobile-safe-bottom));
    -webkit-overflow-scrolling: touch;
  }

  .scroll-to-bottom-btn {
    left: 50%;
    bottom: calc(84px + var(--mobile-safe-bottom));
    width: 40px;
    height: 40px;
  }

  .user-msg-actions {
    top: -10px;
    right: 32px;
    opacity: 1;
    transform: none;
    pointer-events: auto;
  }

  .input {
    position: sticky;
    bottom: 0;
    z-index: 10;
    padding: 8px 10px calc(8px + var(--mobile-safe-bottom));
    background: var(--color-surface-soft);
  }

  .input-box {
    align-items: center;
    border-radius: 20px;
  }

  .input-box textarea {
    max-height: min(150px, 30dvh);
  }

  .input-box textarea::placeholder {
    font-size: 13px;
  }

  textarea {
    font-size: 16px;
  }

  .admin-panel {
    border-left: 0;
    padding: 14px 12px calc(14px + var(--mobile-safe-bottom));
    overflow-x: hidden;
  }

  .admin-panel-header {
    align-items: flex-start;
  }

  .admin-panel-header > :first-child {
    min-width: 0;
    flex: 1;
  }

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

  .admin-form-actions,
  .admin-user-actions {
    gap: 8px;
  }

  .admin-user-table {
    min-width: 0;
  }

  .admin-user-table th,
  .admin-user-table td {
    padding: 12px 10px;
  }

  .admin-tabbar {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    width: 100%;
    align-self: stretch;
    box-sizing: border-box;
    gap: 6px;
  }

  .admin-tab {
    flex: none;
    min-width: 0;
    white-space: normal;
    line-height: 1.2;
    text-align: center;
    padding: 9px 8px;
  }

  .admin-model-provider-list {
    grid-template-columns: 1fr;
  }

  .admin-model-provider-header,
  .admin-model-key-row,
  .admin-model-grid,
  .admin-telegram-settings,
  .admin-telegram-form,
  .admin-telegram-contact-form,
  .admin-telegram-pairing-controls {
    grid-template-columns: 1fr;
  }

  .admin-telegram-form .admin-form-actions {
    grid-column: 1 / -1;
  }

  .admin-workspace-docs-toolbar {
    grid-template-columns: 1fr;
  }

  .admin-workspace-skill-grid,
  .admin-widget-policy-grid,
  .admin-workspace-skill-config {
    grid-template-columns: 1fr;
  }

  .admin-workspace-assist-controls {
    flex-direction: column;
    align-items: stretch;
  }

  .admin-workspace-assist-controls .admin-field {
    width: 100%;
  }

  .admin-assist-cta {
    width: 100%;
  }

  .admin-workspace-actions {
    gap: 8px;
  }

  .admin-primary-btn,
  .admin-secondary-btn,
  .admin-danger-btn,
  .admin-action-btn:not(.icon-only) {
    width: 100%;
    justify-content: center;
  }

  .admin-list-header {
    flex-direction: column;
    align-items: stretch;
  }

  .admin-workspace-table {
    min-width: 720px;
  }

  .msg {
    max-width: 90%;
  }

  .session {
    min-height: 30px;
    padding: 6px 28px 6px 10px;
  }
}

@media (max-width: 420px) {
  .admin-tabbar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.admin-widget-embed-panel {
  margin-top: 14px;
  padding: 16px;
  border: 1px solid #cfe0ff;
  border-radius: 18px;
  background: #f8fbff;
  box-shadow: 0 10px 26px rgba(33, 79, 170, 0.08);
}

.admin-widget-embed-title {
  font-weight: 800;
  color: #1f3155;
  margin-bottom: 6px;
}

.admin-widget-embed-hint {
  margin: 0 0 12px;
  color: #5d6b85;
  font-size: 0.92rem;
}

.admin-widget-embed-field {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
  color: #263856;
  font-weight: 700;
}

.admin-widget-embed-field textarea {
  width: 100%;
  min-height: 72px;
  resize: vertical;
  border: 1px solid #c9d8f2;
  border-radius: 12px;
  padding: 10px 12px;
  font: 0.88rem ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  color: #17233b;
  background: #ffffff;
}
