:root {
  --blue: #003399;
  --blue-dark: #001f5c;
  --blue-mid: #1a4db3;
  --blue-light: #e8eef8;
  --blue-glow: rgba(0, 51, 153, 0.15);
  --grey: #2d3748;
  --grey-muted: #64748b;
  --grey-light: #f1f5f9;
  --surface: #ffffff;
  --border: #e2e8f0;
  --success: #059669;
  --success-bg: #d1fae5;
  --error: #dc2626;
  --error-bg: #fee2e2;
  --warning: #d97706;
  --warning-bg: #fef3c7;
  --sidebar-width: 260px;
  --chat-rail-width: 48px;
  --chat-history-width: 280px;
  --topbar-height: 56px;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0, 31, 92, 0.08);
  --shadow-lg: 0 12px 40px rgba(0, 31, 92, 0.12);
  --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  color: var(--grey);
  background: var(--grey-light);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── App shell & sidebar ── */

.app-layout {
  min-height: 100dvh;
  width: 100%;
  max-width: 100%;
}

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: linear-gradient(180deg, var(--blue-dark) 0%, var(--blue) 100%);
  color: #fff;
  display: flex;
  flex-direction: column;
  z-index: 200;
  transform: translateX(-100%);
  transition: transform var(--transition);
  padding: 1.25rem 0;
  box-shadow: var(--shadow-lg);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0 1.25rem 1.5rem;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  margin-bottom: 0.5rem;
}

.brand-icon {
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border-radius: 11px;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.sidebar-brand:hover .brand-icon {
  transform: scale(1.06);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.28);
}

.app-logo {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
}

.app-logo--lg {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  box-shadow: 0 8px 24px rgba(0, 51, 153, 0.22);
}

.brand-text {
  color: #fff;
  font-weight: 700;
  font-size: 1.05rem;
  text-decoration: none;
  display: block;
  line-height: 1.2;
}

.brand-sub {
  font-size: 0.65rem;
  opacity: 0.65;
  letter-spacing: 0.02em;
  line-height: 1.3;
}

.sidebar-nav {
  flex: 1;
  padding: 0.5rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.7rem 1rem;
  border-radius: var(--radius-sm);
  color: rgba(255,255,255,0.8);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  transition: background var(--transition), color var(--transition);
}

.nav-item svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  opacity: 0.85;
}

.nav-item:hover {
  background: rgba(255,255,255,0.1);
  color: #fff;
}

.nav-item.active {
  background: rgba(255,255,255,0.18);
  color: #fff;
}

.sidebar-footer {
  padding: 1rem 0.75rem 0;
  border-top: 1px solid rgba(255,255,255,0.1);
}

.user-pill {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.75rem;
  margin-bottom: 0.5rem;
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 700;
  flex-shrink: 0;
}

.user-email {
  font-size: 0.75rem;
  opacity: 0.75;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav-logout { color: rgba(255,255,255,0.7); }

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 150;
  backdrop-filter: blur(2px);
}

.app-layout.sidebar-open .sidebar {
  transform: translateX(0);
}

.app-layout.sidebar-open .sidebar-backdrop {
  display: block;
}

.menu-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  background: var(--blue-light);
  color: var(--blue);
  border-radius: var(--radius-sm);
  cursor: pointer;
  flex-shrink: 0;
}

.menu-toggle svg { width: 22px; height: 22px; }

/* Tablet/desktop: grid a 2 colonne */
@media (min-width: 768px) {
  .app-layout {
    display: grid;
    grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
    align-items: start;
  }

  .sidebar {
    position: sticky;
    top: 0;
    grid-column: 1;
    grid-row: 1;
    height: 100dvh;
    transform: translateX(0);
  }

  .sidebar-backdrop {
    display: none !important;
  }

  .menu-toggle {
    display: none;
  }

  .main-wrapper {
    grid-column: 2;
    grid-row: 1;
    min-width: 0;
    min-height: 0;
    width: 100%;
    max-width: 100%;
  }
}

/* Mobile: sidebar overlay + hamburger */
@media (max-width: 767px) {
  .app-layout {
    display: block;
  }

  .main-wrapper {
    width: 100%;
    max-width: 100%;
  }
}

.main-wrapper {
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--topbar-height);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0 1rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
  min-width: 0;
  width: 100%;
  max-width: 100%;
}

.topbar-title {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--grey);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.page-content {
  flex: 1;
  padding: 1.25rem 1.25rem 2rem;
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  width: 100%;
  max-width: 100%;
}

.page-content:has(.chat-page-wrap) {
  padding: 0;
  overflow: hidden;
  flex: 1 1 0;
}

.main-wrapper:has(.chat-page-wrap) {
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
}

.content-inner {
  max-width: 1000px;
  margin: 0 auto;
  width: 100%;
  min-width: 0;
}

.content-inner.chat-page-wrap {
  max-width: none;
  margin: 0;
  flex: 1;
  min-height: 0;
}

/* ── Typography ── */

.page-header { margin-bottom: 1.25rem; }

h1 {
  color: var(--blue);
  margin-bottom: 0.25rem;
  font-size: clamp(1.4rem, 4vw, 1.75rem);
  font-weight: 700;
}

.subtitle {
  color: var(--grey-muted);
  font-size: 0.875rem;
}

.hint { color: var(--grey-muted); font-weight: 400; font-size: 0.8rem; }

/* ── Auth pages ── */

.auth-page { background: linear-gradient(135deg, var(--blue-light) 0%, var(--grey-light) 100%); min-height: 100dvh; }

.auth-container {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.auth-card, .form-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 2rem;
  max-width: 480px;
  width: 100%;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.auth-logo {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  margin-bottom: 1.25rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--border);
}

.auth-logo-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.auth-logo-title {
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--blue-dark);
  letter-spacing: -0.02em;
}

.auth-logo-sub {
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--grey-muted);
}

.auth-heading {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--grey);
  margin: 0 0 0.35rem;
}

.auth-intro {
  margin-top: 0;
  margin-bottom: 0.25rem;
}

.form-card {
  max-width: 100%;
  margin: 0;
}

/* ── Forms ── */

label {
  display: block;
  font-weight: 600;
  margin: 1rem 0 0.35rem;
  font-size: 0.875rem;
  color: var(--grey);
}

input, select, textarea {
  width: 100%;
  padding: 0.6rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.95rem;
  background: var(--surface);
  transition: border-color var(--transition), box-shadow var(--transition);
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--blue-mid);
  box-shadow: 0 0 0 3px var(--blue-glow);
}

textarea { resize: vertical; }

.remember-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 1rem 0 0;
  font-weight: 500;
  cursor: pointer;
}

.remember-row input[type="checkbox"] {
  width: auto;
  margin: 0;
  cursor: pointer;
}

/* ── Buttons ── */

.btn-primary {
  background: linear-gradient(135deg, var(--blue-mid) 0%, var(--blue) 100%);
  color: #fff;
  border: none;
  padding: 0.65rem 1.35rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 600;
  margin-top: 1.25rem;
  transition: transform 0.15s, box-shadow var(--transition);
  box-shadow: 0 2px 8px var(--blue-glow);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 16px var(--blue-glow);
}

.btn-primary:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.btn-outline {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--blue);
  padding: 0.45rem 0.95rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  transition: background var(--transition), border-color var(--transition);
}

.btn-outline:hover {
  background: var(--blue-light);
  border-color: var(--blue-mid);
}

.btn-outline:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  background: var(--surface);
  border-color: var(--border);
}

.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.8rem; }

.btn-danger { border-color: var(--error); color: var(--error); }
.btn-danger:hover { background: var(--error-bg); }

.inline-form { display: inline; }

.form-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1.5rem;
  flex-wrap: wrap;
}

.form-actions .btn-primary,
.form-actions .btn-outline {
  margin-top: 0;
}

.form-actions .btn-outline {
  padding: 0.65rem 1.35rem;
  font-size: 0.95rem;
  font-weight: 600;
}

/* ── Confirm modal ── */

body.confirm-modal-open {
  overflow: hidden;
}

.confirm-modal {
  position: fixed;
  inset: 0;
  z-index: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.confirm-modal[hidden] {
  display: none;
}

.confirm-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
}

.confirm-modal-panel {
  position: relative;
  width: min(420px, 100%);
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 1.35rem 1.5rem 1.25rem;
}

.confirm-modal-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--grey);
  margin-bottom: 0.5rem;
}

.confirm-modal-message {
  font-size: 0.95rem;
  color: var(--grey-muted);
  margin-bottom: 1.35rem;
  line-height: 1.55;
}

.confirm-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.65rem;
  flex-wrap: wrap;
}

.confirm-modal-actions .btn-primary,
.confirm-modal-actions .btn-outline {
  margin-top: 0;
  padding: 0.65rem 1.35rem;
  font-size: 0.95rem;
  font-weight: 600;
}

/* ── Chips / suggestions ── */

.suggestions-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1rem 1.15rem;
  margin-bottom: 1.25rem;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.suggestions-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--grey-muted);
  margin-bottom: 0.65rem;
}

.suggestion-chips, .chart-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 0.9rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--grey-light);
  color: var(--grey);
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
  line-height: 1.3;
  text-align: left;
}

.chip:hover {
  background: var(--blue-light);
  border-color: var(--blue-mid);
  color: var(--blue);
  transform: translateY(-1px);
}

.chip:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.chip:disabled:hover {
  background: var(--grey-light);
  border-color: var(--border);
  color: var(--grey);
}

.chip.active {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
}

.chip-sm {
  padding: 0.35rem 0.75rem;
  font-size: 0.78rem;
}

.chip-icon { font-size: 0.95rem; line-height: 1; }

/* ── Chat (Grok-style) ── */

.chat-page-wrap {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  height: 100%;
}

.chat-layout {
  display: flex;
  flex: 1;
  min-height: 0;
  height: 100%;
  position: relative;
}

.chat-history-rail {
  width: var(--chat-rail-width);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  padding: 0.75rem 0;
  border-right: 1px solid var(--border);
  background: var(--surface);
  z-index: 50;
}

.chat-history-rail-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--grey-muted);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}

.chat-history-rail-btn svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.chat-history-rail-btn:hover {
  background: var(--grey-light);
  color: var(--blue);
}

.chat-history-rail-btn.active {
  background: var(--blue-light);
  color: var(--blue);
}

.chat-history-panel {
  width: var(--chat-history-width);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--surface);
  min-height: 0;
  overflow: hidden;
  transition: width 0.25s ease, border-color 0.25s ease;
}

.chat-history-panel:not(.open) {
  width: 0;
  border-right-color: transparent;
}

.chat-history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.chat-history-title {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--grey);
}

.chat-history-close {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--grey-muted);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}

.chat-history-close:hover {
  background: var(--grey-light);
  color: var(--grey);
}

.chat-history-list-wrap {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  min-height: 0;
}

.chat-history-list {
  list-style: none;
  margin: 0;
  padding: 0.5rem;
}

.chat-history-item {
  display: flex;
  align-items: stretch;
  gap: 0.25rem;
  margin-bottom: 0.25rem;
}

.chat-history-link {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding: 0.65rem 0.75rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--grey);
  text-align: left;
  cursor: pointer;
  font-family: inherit;
  transition: background var(--transition), border-color var(--transition);
}

.chat-history-link:hover {
  background: var(--grey-light);
  border-color: var(--border);
}

.chat-history-item.active .chat-history-link {
  background: var(--blue-light);
  border-color: var(--blue-mid);
  color: var(--blue-dark);
}

.chat-history-item-title {
  font-size: 0.85rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-history-item-date {
  font-size: 0.72rem;
  color: var(--grey-muted);
}

.chat-history-rename,
.chat-history-delete {
  flex-shrink: 0;
  align-self: center;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--grey-muted);
  cursor: pointer;
  opacity: 0;
  transition: opacity var(--transition), background var(--transition), color var(--transition);
}

.chat-history-item:hover .chat-history-rename,
.chat-history-item:hover .chat-history-delete,
.chat-history-item:focus-within .chat-history-rename,
.chat-history-item:focus-within .chat-history-delete {
  opacity: 1;
}

.chat-history-rename:hover {
  background: var(--blue-light);
  color: var(--blue);
}

.chat-history-item-title.editing {
  white-space: normal;
  outline: 2px solid var(--blue-mid);
  outline-offset: 1px;
  border-radius: 4px;
  padding: 0.05rem 0.25rem;
}

.chat-history-delete:hover {
  background: var(--error-bg);
  color: var(--error);
}

.chat-history-empty {
  margin: 1.5rem 1rem;
  font-size: 0.82rem;
  color: var(--grey-muted);
  text-align: center;
}

@media (max-width: 900px) {
  .chat-history-panel {
    position: absolute;
    top: 0;
    left: var(--chat-rail-width);
    bottom: 0;
    z-index: 40;
    width: var(--chat-history-width);
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: var(--shadow);
    border-right: 1px solid var(--border);
  }

  .chat-history-panel:not(.open) {
    width: var(--chat-history-width);
    border-right-color: var(--border);
  }

  .chat-history-panel.open {
    transform: translateX(0);
  }

  .chat-history-backdrop {
    display: none;
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: var(--chat-rail-width);
    background: rgba(15, 23, 42, 0.35);
    z-index: 35;
  }

  .chat-history-backdrop.visible {
    display: block;
  }
}

.form-hint {
  margin: 0.35rem 0 0;
  font-size: 0.82rem;
  color: var(--grey-muted);
  line-height: 1.45;
}

.input-with-action {
  display: flex;
  align-items: stretch;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  overflow: hidden;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.input-with-action:focus-within {
  border-color: var(--blue-mid);
  box-shadow: 0 0 0 3px var(--blue-glow);
}

.input-with-action input {
  flex: 1;
  min-width: 0;
  width: auto;
  margin: 0;
  border: none;
  border-radius: 0;
  box-shadow: none;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9rem;
}

.input-with-action input:focus {
  box-shadow: none;
  outline: none;
}

.input-with-action .btn-outline {
  flex-shrink: 0;
  align-self: stretch;
  margin: 0;
  border: none;
  border-left: 1px solid var(--border);
  border-radius: 0;
  padding: 0 1.1rem;
  font-size: 0.875rem;
  font-weight: 600;
  background: var(--grey-light);
  color: var(--blue-dark);
  white-space: nowrap;
}

.input-with-action .btn-outline:hover {
  background: var(--blue-light);
  border-color: var(--border);
}

.credentials-share-box {
  position: relative;
  margin: 0.75rem 0 0.35rem;
}

.credentials-alert .credentials-box {
  margin: 0;
  padding: 0.85rem 2.75rem 0.85rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 0.88rem;
  line-height: 1.55;
  white-space: pre-wrap;
  user-select: all;
  color: var(--grey);
}

.copy-icon-btn {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--grey-light);
  color: var(--blue-dark);
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
}

.copy-icon-btn:hover {
  background: var(--blue-light);
  border-color: var(--blue-mid);
  color: var(--blue);
}

.copy-icon-btn.is-copied {
  background: var(--success-bg, #ecfdf5);
  border-color: var(--success, #059669);
  color: var(--success, #059669);
}

.credentials-alert .copy-feedback {
  display: inline-block;
  margin-top: 0.35rem;
  font-size: 0.85rem;
  color: var(--grey-muted);
}

.credentials-alert .copy-feedback.hidden {
  display: none;
}

.chat-conversation-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.chat-conversation-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  color: var(--grey);
  line-height: 1.35;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-save-prompt-actions {
  display: inline-flex;
  flex-wrap: nowrap;
  gap: 0.6rem;
  margin: 0.75rem 0 0.15rem;
  align-items: center;
}

.chat-save-prompt-actions.answered {
  opacity: 0.55;
  pointer-events: none;
}

.chat-save-prompt-actions.answered button,
.chat-save-prompt-actions button:disabled {
  pointer-events: none;
  cursor: not-allowed;
}

.chat-save-prompt-actions .btn-primary,
.chat-save-prompt-actions .btn-outline {
  margin: 0;
  min-width: 5rem;
  height: 2.25rem;
  padding: 0 1.1rem;
  font-size: 0.875rem;
  font-weight: 600;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  border-radius: 8px;
  vertical-align: middle;
}

.chat-save-prompt-actions .btn-primary {
  box-shadow: none;
}

.chat-save-prompt-actions .btn-primary:hover:not(:disabled) {
  transform: none;
  box-shadow: 0 2px 8px var(--blue-glow);
}

.chat-save-prompt-actions .btn-outline:hover:not(:disabled) {
  background: var(--blue-light);
  border-color: var(--blue-mid);
}

.chat-save-prompt-actions .btn-primary:disabled,
.chat-save-prompt-actions .btn-outline:disabled {
  transform: none;
  box-shadow: none;
}

.chat-page {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  gap: 0;
  padding-top: 0;
  padding-bottom: max(1.25rem, env(safe-area-inset-bottom, 0px));
}

.chat-messages {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  padding: 0.5rem 0 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  overscroll-behavior: contain;
  width: 100%;
}

.chat-messages > .chat-welcome,
.chat-messages > .chat-row {
  max-width: 1000px;
  margin-left: auto;
  margin-right: auto;
  padding-left: 1rem;
  padding-right: 1rem;
  width: 100%;
  box-sizing: border-box;
}

.chat-empty-state,
.chat-composer {
  max-width: 1000px;
  margin-left: auto;
  margin-right: auto;
  padding-left: 1rem;
  padding-right: 1rem;
  width: 100%;
  box-sizing: border-box;
}

.chat-welcome {
  text-align: center;
  padding: 2.5rem 1rem 1rem;
  margin: auto 0;
}

.chat-welcome.hidden { display: none; }

.chat-welcome-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.app-logo--xl {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  box-shadow: 0 10px 28px rgba(0, 51, 153, 0.2);
}

.chat-welcome-title {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--grey);
  margin-bottom: 0.35rem;
}

.chat-welcome-sub {
  color: var(--grey-muted);
  font-size: 0.875rem;
  max-width: 420px;
  margin: 0 auto;
}

.chat-empty-state {
  padding: 0 0.25rem 0.5rem;
  transition: opacity 0.25s, max-height 0.3s;
}

.chat-empty-state.hidden {
  display: none;
}

.chat-row {
  display: flex;
  width: 100%;
  animation: chatFadeIn 0.3s ease;
}

@keyframes chatFadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.chat-row-user { justify-content: flex-end; }

.chat-row-assistant { justify-content: flex-start; }

.chat-bubble {
  max-width: min(92%, 680px);
  border-radius: 18px;
  line-height: 1.55;
  font-size: 0.92rem;
}

.chat-bubble-user {
  background: linear-gradient(135deg, var(--blue-mid) 0%, var(--blue) 100%);
  color: #fff;
  padding: 0.75rem 1.1rem;
  border-bottom-right-radius: 6px;
  box-shadow: 0 2px 12px var(--blue-glow);
}

.chat-bubble-assistant {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 1rem 1.15rem;
  border-bottom-left-radius: 6px;
  box-shadow: var(--shadow);
  width: 100%;
  max-width: min(92%, 720px);
}

.chat-bubble-error {
  border-color: #fca5a5;
  background: #fff5f5;
}

.chat-bubble-error .response-text { color: #b91c1c; }

/* ── Inline progress card ── */

.chat-progress-card {
  padding: 1rem 1.15rem 1.1rem;
  background: linear-gradient(180deg, #fafbfd 0%, var(--surface) 100%);
}

.progress-card-header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.85rem;
}

.progress-card-title {
  font-weight: 600;
  font-size: 0.88rem;
  color: var(--grey);
}

.progress-pulse {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--blue);
  flex-shrink: 0;
  animation: progressPulse 1.4s ease-in-out infinite;
}

@keyframes progressPulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.85); }
}

.progress-steps {
  list-style: none;
  margin: 0 0 0.85rem;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.progress-step {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  font-size: 0.82rem;
  color: var(--grey-muted);
  transition: color 0.2s;
}

.progress-step-marker {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid var(--border);
  flex-shrink: 0;
  position: relative;
  background: var(--surface);
}

.progress-step.done {
  color: var(--grey);
}

.progress-step.done .progress-step-marker {
  border-color: var(--success);
  background: var(--success-bg);
}

.progress-step.done .progress-step-marker::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 8px;
  height: 8px;
  transform: translate(-50%, -50%);
  background-color: var(--success);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath fill='%23000' d='M10.2 2.8 4.5 8.5 1.8 5.8l-1 1 3.7 3.7 6.7-6.7z'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath fill='%23000' d='M10.2 2.8 4.5 8.5 1.8 5.8l-1 1 3.7 3.7 6.7-6.7z'/%3E%3C/svg%3E") center / contain no-repeat;
}

.progress-step.active {
  color: var(--blue);
  font-weight: 500;
}

.progress-step.active .progress-step-marker {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px var(--blue-glow);
}

.progress-step.active .progress-step-marker::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--blue);
  transform: translate(-50%, -50%);
  animation: progressDotPulse 1.4s ease-in-out infinite;
}

@keyframes progressDotPulse {
  0%, 100% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  50% { opacity: 0.55; transform: translate(-50%, -50%) scale(0.88); }
}

.progress-done .progress-step.active .progress-step-marker::after {
  animation: none;
}

.progress-bar-wrap {
  background: var(--grey-light);
  border-radius: 999px;
  height: 4px;
  overflow: hidden;
}

.progress-bar {
  background: linear-gradient(90deg, var(--blue-mid), var(--blue));
  height: 100%;
  transition: width 0.45s ease;
  border-radius: 999px;
}

/* ── Agent results ── */

.agent-result-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}

.badge-agent {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.response-text {
  font-family: inherit;
  font-size: 0.92rem;
  line-height: 1.65;
  color: var(--grey);
  margin: 0;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.markdown-body > :first-child { margin-top: 0; }
.markdown-body > :last-child { margin-bottom: 0; }

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
  margin: 1.1em 0 0.5em;
  font-weight: 600;
  line-height: 1.3;
  color: var(--grey);
}

.markdown-body h1 { font-size: 1.35rem; }
.markdown-body h2 { font-size: 1.2rem; }
.markdown-body h3 { font-size: 1.05rem; }
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 { font-size: 0.95rem; }

.markdown-body p { margin: 0.65em 0; }

.markdown-body strong { font-weight: 600; }

.markdown-body em { font-style: italic; }

.markdown-body ul,
.markdown-body ol {
  margin: 0.65em 0;
  padding-left: 1.4em;
}

.markdown-body li { margin: 0.25em 0; }

.markdown-body li > ul,
.markdown-body li > ol { margin: 0.25em 0; }

.markdown-body blockquote {
  margin: 0.75em 0;
  padding: 0.4em 0.9em;
  border-left: 3px solid var(--blue-mid);
  color: var(--grey-muted);
  background: var(--grey-light);
  border-radius: 0 6px 6px 0;
}

.markdown-body code {
  font-family: ui-monospace, "Cascadia Code", "Source Code Pro", Menlo, Consolas, monospace;
  font-size: 0.88em;
  padding: 0.15em 0.4em;
  border-radius: 4px;
  background: var(--grey-light);
  color: var(--grey);
}

.markdown-body pre {
  margin: 0.75em 0;
  padding: 0.85em 1em;
  border-radius: 8px;
  background: var(--grey-light);
  border: 1px solid var(--border);
  overflow-x: auto;
}

.markdown-body pre code {
  padding: 0;
  background: none;
  border-radius: 0;
  font-size: 0.85em;
  white-space: pre;
}

.markdown-body a {
  color: var(--blue);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.markdown-body a:hover { color: var(--blue-mid); }

.markdown-body hr {
  margin: 1em 0;
  border: none;
  border-top: 1px solid var(--border);
}

.markdown-body .table-wrap {
  display: block;
  width: 100%;
  overflow-x: auto;
  margin: 0.75em 0;
}

.markdown-body table {
  width: 100%;
  margin: 0;
  border-collapse: collapse;
  font-size: 0.88em;
  min-width: 280px;
}

.markdown-body th,
.markdown-body td {
  padding: 0.45em 0.65em;
  border: 1px solid var(--border);
  text-align: left;
}

.markdown-body th {
  background: var(--grey-light);
  font-weight: 600;
}

.markdown-body img {
  max-width: 100%;
  height: auto;
  border-radius: 6px;
}

.chat-bubble-user .markdown-body {
  color: #fff;
}

.chat-bubble-user .markdown-body a {
  color: #fff;
  font-weight: 500;
}

.chat-bubble-user .markdown-body code,
.chat-bubble-user .markdown-body pre {
  background: rgba(255, 255, 255, 0.15);
  border-color: rgba(255, 255, 255, 0.25);
  color: #fff;
}

.chat-bubble-user .markdown-body blockquote {
  border-left-color: rgba(255, 255, 255, 0.6);
  background: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.9);
}

.chat-bubble-user .markdown-body th {
  background: rgba(255, 255, 255, 0.12);
}

.chat-bubble-error .markdown-body { color: #b91c1c; }
.chat-bubble-error .markdown-body a { color: #991b1b; }

.agent-tabs {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
  margin-bottom: 0.85rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.agent-tab {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.4rem 0.85rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--grey-light);
  color: var(--grey-muted);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.2s;
}

.agent-tab:hover {
  border-color: var(--blue-mid);
  color: var(--blue);
}

.agent-tab.active {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
}

.agent-tab-icon { font-size: 0.9rem; line-height: 1; }

.agent-panels { position: relative; }

.agent-panel { display: none; }
.agent-panel.active { display: block; }

.chat-multi-result { padding: 0.9rem 1rem 1rem; }

/* ── Composer ── */

.chat-composer {
  flex-shrink: 0;
  margin-top: auto;
}

.chat-composer-inner {
  display: flex;
  align-items: flex-end;
  gap: 0.6rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 0.55rem 0.55rem 0.55rem 1rem;
  box-shadow: var(--shadow-lg);
  transition: border-color var(--transition), box-shadow var(--transition);
}

.chat-composer-inner:focus-within {
  border-color: var(--blue-mid);
  box-shadow: 0 4px 24px var(--blue-glow);
}

.chat-composer-inner textarea {
  flex: 1;
  border: none;
  background: transparent;
  padding: 0.4rem 0;
  box-shadow: none;
  resize: none;
  min-height: 24px;
  max-height: 160px;
  font-size: 0.95rem;
  line-height: 1.45;
}

.chat-composer-inner textarea:focus { box-shadow: none; }

.btn-send-round {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, var(--blue-mid), var(--blue));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.15s, opacity 0.2s;
}

.btn-send-round:hover { transform: scale(1.05); }
.btn-send-round:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
.btn-send-round svg { width: 18px; height: 18px; }
.btn-send-round .icon-stop { display: none; width: 14px; height: 14px; }
.btn-send-round.is-stop { background: var(--grey); }
.btn-send-round.is-stop .icon-send { display: none; }
.btn-send-round.is-stop .icon-stop { display: block; }

.chat-composer-hint {
  font-size: 0.72rem;
  color: var(--grey-muted);
  text-align: center;
  margin: 0.5rem 0 0;
  padding: 0 0.5rem 0.25rem;
}

.chat-composer.chat-composer-locked .chat-composer-inner {
  opacity: 0.72;
  border-color: var(--border);
  box-shadow: none;
  background: var(--grey-light);
}

.chat-composer.chat-composer-locked .chat-composer-inner textarea {
  cursor: not-allowed;
}

.chat-composer.chat-composer-locked .chat-composer-hint {
  color: var(--blue);
  font-weight: 500;
}

.hidden { display: none !important; }

/* ── Badges & alerts ── */

.badge {
  background: var(--blue-light);
  color: var(--blue);
  padding: 0.25rem 0.7rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
}

.badge-open { background: var(--success-bg); color: var(--success); }
.badge-closed { background: #f1f5f9; color: var(--grey-muted); }

.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
  font-size: 0.875rem;
}

.alert-error { background: var(--error-bg); color: var(--error); }
.alert-success { background: var(--success-bg); color: var(--success); }
.alert-warning { background: var(--warning-bg); color: var(--warning); }

.auth-footer { margin-top: 1.5rem; text-align: center; font-size: 0.9rem; }

/* ── Stats & charts ── */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.25rem;
  min-width: 0;
  max-width: 100%;
}

@media (max-width: 540px) {
  .stats-grid { grid-template-columns: 1fr; }
}

.stat-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1rem 1.15rem;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  text-align: center;
}

a.stat-card-link {
  text-decoration: none;
  color: inherit;
  display: block;
  transition: border-color 0.2s, box-shadow 0.2s, transform 0.15s;
}

a.stat-card-link:hover {
  border-color: var(--blue-mid);
  box-shadow: var(--shadow-md, 0 4px 12px rgba(0, 51, 153, 0.1));
  transform: translateY(-1px);
}

.stat-card-active {
  border-color: var(--blue);
  box-shadow: 0 0 0 2px rgba(0, 51, 153, 0.15);
}

.stat-value {
  display: block;
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--blue);
  line-height: 1.2;
}

.stat-open .stat-value { color: var(--success); }
.stat-closed .stat-value { color: var(--grey-muted); }

.stat-label {
  font-size: 0.75rem;
  color: var(--grey-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-top: 0.2rem;
  display: block;
}

.charts-section {
  margin-bottom: 1.5rem;
  min-width: 0;
  max-width: 100%;
}

.charts-toolbar {
  margin-bottom: 0.75rem;
  min-width: 0;
  max-width: 100%;
}

.charts-grid {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-width: 0;
  width: 100%;
  max-width: 100%;
}

.chart-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.15rem;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  transition: opacity var(--transition), transform var(--transition);
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
}

.chart-card.hidden-chart {
  display: none;
}

.chart-card h3 {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--grey-muted);
  margin-bottom: 0.75rem;
}

.chart-wrap {
  position: relative;
  width: 100%;
  height: 220px;
  min-width: 0;
}

.chart-wrap-tall { height: 260px; }

.empty-chart-msg {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--grey-muted);
  font-size: 0.85rem;
  text-align: center;
  padding: 1rem;
}

/* ── Calls table ── */

.calls-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.calls-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  min-width: 0;
  max-width: 100%;
}

@media (max-width: 480px) {
  .calls-header {
    flex-direction: column;
    align-items: stretch;
  }

  .calls-actions {
    width: 100%;
  }

  .calls-actions .btn-outline,
  .calls-actions .inline-form {
    flex: 1 1 auto;
  }

  .calls-actions .btn-outline {
    justify-content: center;
    text-align: center;
  }
}

.calls-back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--blue);
  text-decoration: none;
  margin-bottom: 0.35rem;
}

.calls-back-link:hover { text-decoration: underline; }

.calls-filter-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  background: var(--blue-light);
  border: 1px solid rgba(0, 51, 153, 0.15);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  color: var(--blue-dark, var(--blue));
}

.calls-filter-banner p { margin: 0; }

.calls-status-hint {
  display: flex;
  gap: 0.85rem;
  align-items: flex-start;
  padding: 0.85rem 1rem;
  margin-bottom: 1rem;
  background: var(--blue-light);
  border: 1px solid rgba(0, 51, 153, 0.12);
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  color: var(--blue-dark, var(--blue));
  line-height: 1.45;
}

.calls-status-hint-icon {
  flex-shrink: 0;
  width: 2rem;
  height: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--surface);
  color: var(--blue);
  box-shadow: 0 1px 3px rgba(0, 51, 153, 0.12);
}

.calls-status-hint-icon svg {
  width: 1.1rem;
  height: 1.1rem;
}

.calls-status-hint-body { min-width: 0; flex: 1; }

.calls-status-hint-title {
  margin: 0 0 0.45rem;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--blue);
}

.calls-status-hint-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.calls-status-hint-list li {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0.45rem;
  color: var(--text, #1e293b);
}

.calls-status-hint-list .badge {
  flex-shrink: 0;
  font-size: 0.72rem;
  padding: 0.15rem 0.55rem;
}

.calls-filter-nav {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.25rem;
  min-width: 0;
  max-width: 100%;
}

@media (max-width: 540px) {
  .calls-filter-nav { grid-template-columns: 1fr; }
}

.calls-filter-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 1rem 0.85rem;
  border-radius: var(--radius);
  text-decoration: none;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  text-align: center;
  transition: border-color 0.2s, box-shadow 0.2s, transform 0.15s;
}

.calls-filter-btn:hover {
  border-color: var(--blue-mid);
  transform: translateY(-1px);
}

.calls-filter-btn.active {
  border-color: var(--blue);
  box-shadow: 0 0 0 2px rgba(0, 51, 153, 0.15);
}

.calls-filter-btn .filter-value {
  display: block;
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--blue);
  line-height: 1.2;
}

.calls-filter-btn.filter-open .filter-value { color: var(--success); }
.calls-filter-btn.filter-closed .filter-value { color: var(--grey-muted); }

.calls-filter-btn .filter-label {
  font-size: 0.75rem;
  color: var(--grey-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-top: 0.2rem;
  font-weight: 600;
}

.calls-filter-btn.active .filter-label { color: var(--blue); }

.calls-list-section {
  margin-top: 0.5rem;
  margin-bottom: 1.5rem;
}

.calls-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-top: 0.85rem;
  padding: 0.5rem 0;
}

.pagination-btn {
  padding: 0.45rem 0.85rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--blue);
  font-size: 0.82rem;
  font-weight: 600;
  text-decoration: none;
  transition: border-color 0.2s, background 0.2s;
}

.pagination-btn:hover:not(.disabled) {
  border-color: var(--blue-mid);
  background: var(--blue-light);
}

.pagination-btn.disabled {
  opacity: 0.4;
  pointer-events: none;
  color: var(--grey-muted);
}

.pagination-info {
  font-size: 0.82rem;
  color: var(--grey-muted);
  font-weight: 500;
}

.calls-list-heading {
  font-size: 1rem;
  font-weight: 700;
  color: var(--blue);
  margin-bottom: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.calls-list-count {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--grey-muted);
  background: var(--grey-light, #f1f5f9);
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
}

.filter-bar {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  min-width: 0;
  max-width: 100%;
}

.filter-bar a {
  padding: 0.4rem 0.9rem;
  border-radius: 999px;
  text-decoration: none;
  color: var(--grey-muted);
  border: 1px solid var(--border);
  font-size: 0.82rem;
  font-weight: 500;
  background: var(--surface);
  transition: all 0.2s;
}

.filter-bar a:hover {
  border-color: var(--blue-mid);
  color: var(--blue);
}

.filter-bar a.active {
  background: var(--blue);
  color: #fff;
  border-color: var(--blue);
}

/* ── Calls detail panel ── */

.call-row {
  cursor: pointer;
  transition: background 0.15s;
}

.call-row:hover,
.call-row:focus-visible {
  background: var(--blue-light);
  outline: none;
}

.call-title-link {
  color: var(--blue);
  font-weight: 600;
  text-decoration: none;
}

.call-title-link:hover {
  text-decoration: underline;
}

.call-title-text {
  font-weight: 600;
  color: var(--grey);
}

.call-row-actions-col {
  width: 2.75rem;
  padding-left: 0.25rem;
  padding-right: 0.5rem;
}

.call-row-actions {
  width: 2.75rem;
  padding: 0;
  text-align: center;
}

.call-row-delete {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--grey-muted);
  cursor: pointer;
  opacity: 0;
  transition: opacity var(--transition), background var(--transition), color var(--transition);
}

.call-row:hover .call-row-delete,
.call-row:focus-within .call-row-delete {
  opacity: 1;
}

.call-row-delete:hover {
  background: var(--error-bg);
  color: var(--error);
}

body.call-detail-open {
  overflow: hidden;
}

.call-detail-overlay {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.call-detail-overlay[hidden] {
  display: none;
}

.call-detail-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
}

.call-detail-panel {
  position: relative;
  width: min(560px, 100%);
  max-height: min(85vh, 720px);
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.call-detail-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1.1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.call-detail-num {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--blue);
  background: var(--blue-light);
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  margin-bottom: 0.35rem;
}

.call-detail-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--blue-dark, var(--blue));
  line-height: 1.35;
}

.call-detail-close {
  border: none;
  background: transparent;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--grey-muted);
  cursor: pointer;
  padding: 0.15rem 0.35rem;
  border-radius: var(--radius-sm);
}

.call-detail-close:hover {
  background: var(--grey-light);
  color: var(--grey);
}

.call-detail-body {
  padding: 1rem 1.25rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.call-detail-row {
  display: grid;
  grid-template-columns: 7.5rem 1fr;
  gap: 0.5rem 0.75rem;
  font-size: 0.88rem;
  align-items: start;
}

.call-detail-label {
  color: var(--grey-muted);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.call-detail-value {
  color: var(--grey);
  word-break: break-word;
}

.call-detail-value a {
  color: var(--blue);
  text-decoration: none;
  font-weight: 500;
}

.call-detail-value a:hover {
  text-decoration: underline;
}

.call-detail-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0.85rem 1.25rem;
  border-top: 1px solid var(--border);
  background: var(--grey-light);
}

.call-detail-portal-link {
  margin-right: auto;
}

@media (max-width: 480px) {
  .call-detail-row {
    grid-template-columns: 1fr;
    gap: 0.15rem;
  }

  .call-detail-footer {
    flex-wrap: wrap;
  }

  .call-detail-portal-link {
    margin-right: 0;
    width: 100%;
    justify-content: center;
  }
}

.table-wrap {
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

.data-table {
  width: 100%;
  background: var(--surface);
  border-collapse: collapse;
  font-size: 0.82rem;
  table-layout: fixed;
}

.data-table th {
  background: linear-gradient(135deg, var(--blue-dark) 0%, var(--blue) 100%);
  color: #fff;
  padding: 0.7rem 0.85rem;
  text-align: left;
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.data-table td {
  padding: 0.6rem 0.85rem;
  border-bottom: 1px solid var(--border);
  word-break: break-word;
  overflow-wrap: anywhere;
  vertical-align: top;
}

.data-table th:nth-child(1),
.data-table td:nth-child(1) { width: 3rem; }

.data-table th:nth-child(2),
.data-table td:nth-child(2) { width: 34%; }

.data-table th:nth-child(3),
.data-table td:nth-child(3) { width: 18%; }

.data-table th:nth-child(4),
.data-table td:nth-child(4) { width: 12%; }

.data-table th:nth-child(5),
.data-table td:nth-child(5) { width: 14%; }

.data-table th:nth-child(6),
.data-table td:nth-child(6) { width: 4.5rem; }

@media (max-width: 720px) {
  .data-table th:nth-child(3),
  .data-table td:nth-child(3),
  .data-table th:nth-child(5),
  .data-table td:nth-child(5) {
    display: none;
  }

  .data-table th:nth-child(2),
  .data-table td:nth-child(2) { width: 50%; }
}

/* Tabella call salvate: larghezze per classe, indipendenti dall'ordine delle colonne */
.data-table.calls-table td {
  word-break: normal;
  overflow-wrap: break-word;
}

.data-table.calls-table th.col-num       { width: 3rem; }
.data-table.calls-table th.col-title     { width: auto; }
.data-table.calls-table th.col-theme     { width: 17%; }
.data-table.calls-table th.col-programme { width: 15%; }
.data-table.calls-table th.col-deadline  { width: 7rem; }
.data-table.calls-table th.col-budget    { width: 8.5rem; }
.data-table.calls-table th.col-status    { width: 6.5rem; }

.data-table.calls-table .col-deadline,
.data-table.calls-table .col-status { white-space: nowrap; }

@media (max-width: 1100px) {
  .data-table.calls-table th.col-theme     { width: 20%; }
  .data-table.calls-table th.col-programme,
  .data-table.calls-table td.col-programme { display: none; }
}

@media (max-width: 720px) {
  .data-table.calls-table th:nth-child(n),
  .data-table.calls-table td:nth-child(n) { display: table-cell; }

  .data-table.calls-table th.col-theme,
  .data-table.calls-table td.col-theme,
  .data-table.calls-table th.col-programme,
  .data-table.calls-table td.col-programme,
  .data-table.calls-table th.col-budget,
  .data-table.calls-table td.col-budget { display: none; }

  .data-table.calls-table th.col-title { width: auto; }
}

/* Chiavi API (creazione utente e Impostazioni) */
.api-keys-fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem 1rem;
  margin: 1rem 0;
}
.api-keys-fieldset legend { font-weight: 600; padding: 0 0.35rem; color: var(--blue); }
.api-keys-card { margin-top: 1.5rem; }
.api-keys-card h2 { margin-top: 0; }

/* Form nuovo utente: larghezza contenuta, username e password affiancati */
.new-user-form h2 { margin-top: 0; }
.credentials-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  column-gap: 1rem;
}
.credentials-row label { margin-top: 0.5rem; }
.new-user-form .api-keys-fieldset { margin: 0.9rem 0; }
.new-user-form .api-key-field { grid-template-columns: 6.5rem minmax(0, 1fr); }

@media (max-width: 560px) {
  .credentials-row { grid-template-columns: minmax(0, 1fr); }
}

/* Etichetta e campo sulla stessa riga */
.api-key-field {
  display: grid;
  grid-template-columns: 7.5rem minmax(0, 1fr) auto;
  align-items: center;
  column-gap: 0.75rem;
  margin-top: 0.5rem;
}
.api-key-field > label,
.api-key-field > .api-key-label {
  margin: 0;
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--grey);
}
.api-key-field > input { padding: 0.45rem 0.7rem; font-size: 0.9rem; }
.api-key-state { font-size: 0.85rem; color: var(--grey-muted); grid-column: 2 / -1; }
.api-keys-fieldset .form-hint,
.api-keys-card .form-hint { margin-bottom: 0.25rem; }
.api-keys-card .btn-primary { margin-top: 0.9rem; }

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin: 0;
  font-weight: 400;
  font-size: 0.82rem;
  white-space: nowrap;
}
.checkbox-label input { width: auto; margin: 0; }

@media (max-width: 560px) {
  .api-key-field { grid-template-columns: minmax(0, 1fr) auto; row-gap: 0.25rem; }
  .api-key-field > label:first-child,
  .api-key-field > .api-key-label { grid-column: 1 / -1; }
}

/* Tabella chiamate agli agenti (pagina Utenti) */
.usage-section { margin-top: 2rem; }
.usage-heading { font-size: 1.05rem; color: var(--blue); margin: 0 0 0.25rem; }

.data-table.usage-table td {
  word-break: normal;
  overflow-wrap: break-word;
}

.data-table.usage-table th.col-user     { width: 13%; }
.data-table.usage-table th.col-agent    { width: 11%; }
.data-table.usage-table th.col-provider { width: 10%; }
.data-table.usage-table th.col-model    { width: 20%; }
.data-table.usage-table th.col-count    { width: 9%; }
.data-table.usage-table th.col-tokens   { width: 11%; }
.data-table.usage-table th.col-last     { width: 15%; }
.data-table.usage-table code            { white-space: normal; }
.data-table.usage-table .col-count,
.data-table.usage-table .col-tokens     { text-align: right; white-space: nowrap; }
.data-table.usage-table tfoot td        { font-weight: 600; background: var(--grey-light); }

@media (max-width: 720px) {
  .data-table.usage-table th:nth-child(n),
  .data-table.usage-table td:nth-child(n) { display: table-cell; }
  .data-table.usage-table th.col-provider,
  .data-table.usage-table td:nth-child(3),
  .data-table.usage-table th.col-last,
  .data-table.usage-table td:nth-child(8) { display: none; }
}

.data-table tr:last-child td { border-bottom: none; }

.data-table tbody tr:hover td { background: var(--grey-light); }

.empty-state {
  text-align: center;
  padding: 2.5rem 1rem;
  color: var(--grey-muted);
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px dashed var(--border);
}

.hidden { display: none !important; }
