
    * {
      box-sizing: border-box;
    }

    body {
      margin: 0;
      font-family: Arial, sans-serif;
      background: #f5f5f5;
      color: #111;
    }

    button,
    input,
    textarea {
      font: inherit;
    }

    button {
      cursor: pointer;
    }

    .hidden {
      display: none !important;
    }

    .login-screen {
      min-height: 100vh;
      display: flex;
      align-items: center;
      justify-content: center;
      padding: 20px;
    }

    .login-card {
      width: 100%;
      max-width: 400px;
      background: white;
      border: 1px solid #ddd;
      border-radius: 12px;
      padding: 32px;
      box-shadow: 0 8px 30px rgba(0,0,0,0.06);
    }

    .login-card h1 {
      margin: 0 0 8px;
      font-size: 28px;
    }

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

    .field {
      margin-bottom: 18px;
    }

    .field label {
      display: block;
      margin-bottom: 7px;
      font-size: 13px;
      font-weight: 700;
      color: #444;
    }

    .field input,
    .field textarea,
    .field select {
      width: 100%;
      padding: 11px 12px;
      border: 1px solid #ccc;
      border-radius: 7px;
      background: white;
      color: #111;
    }

    .field textarea {
      min-height: 180px;
      resize: vertical;
      font-family: monospace;
      line-height: 1.5;
    }

    .login-card button,
    .primary-button {
      width: 100%;
      border: 0;
      border-radius: 7px;
      padding: 12px 16px;
      background: #111;
      color: white;
      font-weight: 700;
    }

    .error {
      margin-top: 14px;
      color: #c00;
      font-size: 14px;
    }

    .app {
      min-height: 100vh;
    }

    .topbar {
      height: 64px;
      background: #111;
      color: white;
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 0 28px;
    }

    .topbar-title {
      font-size: 20px;
      font-weight: 700;
    }

    .topbar-right {
      display: flex;
      align-items: center;
      gap: 16px;
    }

    .username {
      color: #ccc;
      font-size: 14px;
    }

    .logout-button {
      border: 1px solid #555;
      background: transparent;
      color: white;
      border-radius: 6px;
      padding: 7px 12px;
    }

    .content {
      max-width: 1100px;
      margin: 0 auto;
      padding: 32px 20px 60px;
    }

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

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

    .page-header p {
      margin: 6px 0 0;
      color: #666;
    }

    .secondary-button {
      border: 1px solid #ccc;
      background: white;
      color: #111;
      border-radius: 7px;
      padding: 10px 14px;
      font-weight: 700;
    }

    .analytics-header {
      margin-bottom: 22px;
    }

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

    .analytics-header p {
      margin: 6px 0 0;
      color: #666;
    }

    .kpi-grid {
      display: grid;
      grid-template-columns: repeat(4, minmax(0, 1fr));
      gap: 16px;
      margin-bottom: 18px;
    }

    .kpi-card {
      background: white;
      border: 1px solid #ddd;
      border-radius: 10px;
      padding: 20px;
    }

    .kpi-label {
      color: #777;
      font-size: 13px;
      font-weight: 700;
      margin-bottom: 8px;
    }

    .kpi-value {
      font-size: 30px;
      font-weight: 800;
      line-height: 1;
    }

    .analytics-grid {
      display: grid;
      grid-template-columns: 1.4fr 1fr;
      gap: 18px;
      margin-bottom: 32px;
    }

    .analytics-card {
      background: white;
      border: 1px solid #ddd;
      border-radius: 10px;
      padding: 22px;
    }

    .analytics-card.full {
      grid-column: 1 / -1;
    }

    .analytics-card h2 {
      margin: 0 0 18px;
      font-size: 18px;
    }

    .period-tabs {
      display: flex;
      flex-wrap: wrap;
      gap: 8px;
      margin-bottom: 20px;
    }

    .period-button {
      width: auto;
      border: 1px solid #ddd;
      background: white;
      color: #555;
      padding: 8px 12px;
      border-radius: 7px;
      font-weight: 700;
    }

    .period-button.active {
      background: #111;
      border-color: #111;
      color: white;
    }

    .period-stats {
      display: grid;
      grid-template-columns: repeat(3, 1fr);
      gap: 12px;
    }

    .period-stat {
      background: #f7f7f7;
      border-radius: 8px;
      padding: 16px;
    }

    .period-stat-label {
      color: #777;
      font-size: 12px;
      font-weight: 700;
      margin-bottom: 6px;
    }

    .period-stat-value {
      font-size: 22px;
      font-weight: 800;
    }

    .usage-row {
      display: grid;
      grid-template-columns: minmax(150px, 1fr) auto auto auto;
      gap: 18px;
      align-items: center;
      padding: 13px 0;
      border-bottom: 1px solid #eee;
      font-size: 13px;
    }

    .usage-row:last-child {
      border-bottom: 0;
    }

    .usage-name {
      min-width: 0;
    }

    .usage-name strong {
      display: block;
      font-size: 14px;
      margin-bottom: 3px;
    }

    .usage-name span {
      color: #888;
      font-family: monospace;
      font-size: 12px;
    }

    .usage-number {
      white-space: nowrap;
      color: #555;
    }

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

    .topic-row {
      display: flex;
      justify-content: space-between;
      gap: 16px;
      padding-bottom: 10px;
      border-bottom: 1px solid #eee;
      font-size: 13px;
    }

    .topic-row:last-child {
      border-bottom: 0;
      padding-bottom: 0;
    }

    .topic-name {
      font-weight: 700;
    }

    .topic-count {
      color: #777;
    }

    .recent-list {
      display: grid;
    }

    .recent-conversation {
      width: 100%;
      padding: 15px 0;
      border: 0;
      border-bottom: 1px solid #eee;
      background: transparent;
      color: inherit;
      text-align: left;
      cursor: pointer;
      transition: opacity .15s ease;
      font: inherit;
    }

    .recent-conversation:hover {
      opacity: .65;
    }

    /* Conversation viewer */

    .conversation-viewer {
      display: none;
      position: fixed;
      inset: 0;
      z-index: 9999;
      margin: 0;
      padding: 24px;
      background: rgba(0, 0, 0, .45);
      overflow: hidden;
    }

    .conversation-viewer.visible {
      display: flex;
      align-items: center;
      justify-content: center;
    }

    .conversation-viewer-inner {
      width: min(900px, 100%);
      height: min(820px, 100%);
      max-height: calc(100vh - 48px);
      display: flex;
      flex-direction: column;
      background: white;
      border-radius: 14px;
      box-shadow: 0 20px 60px rgba(0, 0, 0, .25);
      overflow: hidden;
    }

    .conversation-viewer-header {
      flex: 0 0 auto;
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 16px;
      padding: 18px 20px;
      background: white;
      border-bottom: 1px solid #e5e5e5;
    }

    .conversation-viewer-title {
      font-size: 18px;
      font-weight: 700;
      line-height: 1.3;
    }

    .conversation-viewer-meta {
      margin-top: 4px;
      color: #777;
      font-size: 12px;
      line-height: 1.4;
    }

    .conversation-viewer-close {
      width: auto;
      flex-shrink: 0;
    }

    .conversation-messages {
      flex: 1 1 auto;
      min-height: 0;
      display: flex;
      flex-direction: column;
      gap: 12px;
      overflow-y: auto;
      padding: 20px;
      background: #f7f7f7;
    }

    .conversation-message {
      width: fit-content;
      max-width: 70%;
      padding: 9px 12px;
      margin: 0;
      border-radius: 10px;
      font-size: 13px;
      line-height: 1.45;
      white-space: normal;
      word-break: break-word;
      flex: 0 0 auto;
    }

    .conversation-message.user {
      align-self: flex-end;
      background: #111;
      color: white;
    }

    .conversation-message.assistant {
      align-self: flex-start;
      background: white;
      border: 1px solid #ddd;
      color: #111;
    }

    .conversation-message-role {
      margin-bottom: 4px;
      font-size: 10px;
      font-weight: 700;
      line-height: 1.2;
      text-transform: uppercase;
      opacity: .6;
    }

    .conversation-message-time {
      margin-top: 5px;
      font-size: 9px;
      line-height: 1.2;
      opacity: .5;
    }

    @media (max-width: 700px) {
      .conversation-viewer {
        padding: 0;
      }

      .conversation-viewer-inner {
        width: 100%;
        height: 100%;
        max-height: none;
        border-radius: 0;
      }

      .conversation-viewer-header {
        padding: 15px;
      }

      .conversation-messages {
        padding: 14px;
      }

      .conversation-message {
        max-width: 84%;
      }
    }

    .recent-conversation:last-child {
      border-bottom: 0;
    }

    .recent-top {
      display: flex;
      justify-content: space-between;
      gap: 18px;
      align-items: flex-start;
      margin-bottom: 6px;
    }

    .recent-bot {
      font-weight: 700;
      font-size: 14px;
    }

    .recent-time {
      color: #888;
      font-size: 12px;
      white-space: nowrap;
    }

    .recent-preview {
      color: #555;
      font-size: 13px;
      line-height: 1.5;
      margin-bottom: 7px;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }

    .recent-meta {
      display: flex;
      flex-wrap: wrap;
      gap: 12px;
      color: #888;
      font-size: 12px;
    }

    .analytics-empty {
      color: #888;
      font-size: 13px;
      padding: 8px 0;
    }

    .dashboard-divider {
      height: 1px;
      background: #ddd;
      margin: 8px 0 32px;
    }

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

      .analytics-grid {
        grid-template-columns: 1fr;
      }

      .analytics-card.full {
        grid-column: auto;
      }

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

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

      .period-stats {
        grid-template-columns: 1fr;
      }

      .usage-row {
        grid-template-columns: 1fr;
        gap: 5px;
      }

      .recent-top {
        display: block;
      }

      .recent-time {
        display: block;
        margin-top: 4px;
      }
    }

    .bot-grid {
      display: grid;
      gap: 16px;
    }

    .bot-card {
      background: white;
      border: 1px solid #ddd;
      border-radius: 10px;
      padding: 20px;
      display: grid;
      grid-template-columns: 1fr auto;
      gap: 20px;
      align-items: center;
    }

    .bot-name {
      font-size: 19px;
      font-weight: 700;
      margin-bottom: 5px;
    }

    .bot-slug {
      color: #777;
      font-family: monospace;
      font-size: 13px;
    }

    .bot-meta {
      display: flex;
      flex-wrap: wrap;
      gap: 14px;
      margin-top: 13px;
      color: #555;
      font-size: 13px;
    }

    .status {
      display: inline-flex;
      align-items: center;
      gap: 6px;
      font-size: 13px;
      font-weight: 700;
      margin-bottom: 8px;
    }

    .status-dot {
      width: 8px;
      height: 8px;
      border-radius: 50%;
      background: #888;
    }

    .status.active .status-dot {
      background: #159447;
    }

    .editor-header {
      display: flex;
      align-items: flex-start;
      gap: 16px;
      margin-bottom: 28px;
    }

    .back-button {
      border: 0;
      background: transparent;
      padding: 4px 0;
      font-weight: 700;
      color: #555;
    }

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

    .editor-header p {
      margin: 5px 0 0;
      color: #777;
      font-family: monospace;
      font-size: 13px;
    }

    .editor-grid {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 18px;
    }

    .section {
      background: white;
      border: 1px solid #ddd;
      border-radius: 10px;
      padding: 22px;
    }

    .section.full {
      grid-column: 1 / -1;
    }

    .section h2 {
      margin: 0 0 18px;
      font-size: 17px;
    }

    .checkbox-row {
      display: flex;
      align-items: center;
      gap: 9px;
      margin-bottom: 13px;
    }

    .checkbox-row input {
      width: 17px;
      height: 17px;
    }

    .checkbox-row label {
      font-size: 14px;
    }

    .tools-note {
      color: #777;
      font-size: 13px;
      margin-top: 8px;
    }

    .bot-management-section {
      margin-top: 18px;
    }

    .bot-status-row {
      display: flex;
      justify-content: space-between;
      align-items: center;
      gap: 24px;
    }

    .bot-status-row h2 {
      margin: 0 0 6px;
      font-size: 18px;
    }

    .bot-status-row p {
      margin: 0;
      color: #777;
      font-size: 13px;
    }

    .toggle-control {
      display: flex;
      align-items: center;
      gap: 10px;
      cursor: pointer;
      user-select: none;
    }

    .toggle-control input {
      position: absolute;
      opacity: 0;
      pointer-events: none;
    }

    .toggle-slider {
      position: relative;
      width: 48px;
      height: 26px;
      border-radius: 999px;
      background: #bbb;
      transition: background .18s ease;
    }

    .toggle-slider::after {
      content: "";
      position: absolute;
      width: 20px;
      height: 20px;
      left: 3px;
      top: 3px;
      border-radius: 50%;
      background: white;
      box-shadow: 0 1px 4px rgba(0,0,0,.25);
      transition: transform .18s ease;
    }

    .toggle-control input:checked +
    .toggle-slider {
      background: #159447;
    }

    .toggle-control input:checked +
    .toggle-slider::after {
      transform: translateX(22px);
    }

    .toggle-control input:disabled +
    .toggle-slider {
      opacity: .55;
      cursor: wait;
    }

    .toggle-label {
      min-width: 28px;
      font-size: 12px;
      font-weight: 800;
    }

    .danger-zone {
      margin-top: 22px;
      padding-top: 20px;
      border-top: 1px solid #eee;
      display: flex;
      justify-content: space-between;
      align-items: center;
      gap: 24px;
    }

    .danger-zone strong {
      display: block;
      margin-bottom: 5px;
      font-size: 14px;
    }

    .danger-zone p {
      margin: 0;
      color: #777;
      font-size: 13px;
      line-height: 1.5;
    }

    .danger-button {
      width: auto;
      flex-shrink: 0;
      border: 1px solid #c93636;
      background: white;
      color: #b52c2c;
      border-radius: 7px;
      padding: 10px 14px;
      font-weight: 700;
    }

    .danger-button:hover {
      background: #fff5f5;
    }

    @media (max-width: 600px) {
      .bot-status-row,
      .danger-zone {
        align-items: flex-start;
        flex-direction: column;
      }
    }

    .editor-actions {
      display: flex;
      justify-content: flex-end;
      gap: 10px;
      margin-top: 22px;
    }

    .editor-actions button {
      width: auto;
      min-width: 130px;
    }

    .save-button {
      border: 0;
      border-radius: 7px;
      padding: 11px 18px;
      background: #111;
      color: white;
      font-weight: 700;
    }

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

    .loading {
      padding: 40px;
      text-align: center;
      color: #666;
    }

    .builder-note {
      margin: -5px 0 18px;
      color: #777;
      font-size: 13px;
      line-height: 1.5;
    }

    .builder-actions {
      display: flex;
      justify-content: flex-end;
      gap: 10px;
      margin-top: 22px;
    }

    .builder-actions button {
      width: auto;
      min-width: 130px;
    }

    .success-card {
      max-width: 800px;
      margin: 0 auto;
      background: white;
      border: 1px solid #ddd;
      border-radius: 12px;
      padding: 28px;
    }

    .success-card h1 {
      margin: 0 0 8px;
    }

    .success-card > p {
      color: #666;
      margin: 0 0 28px;
    }

    .deployment-field {
      margin-bottom: 22px;
    }

    .deployment-field label {
      display: block;
      font-size: 13px;
      font-weight: 700;
      margin-bottom: 7px;
      color: #444;
    }

    .deployment-value {
      background: #f6f6f6;
      border: 1px solid #ddd;
      border-radius: 7px;
      padding: 12px;
      font-family: monospace;
      font-size: 13px;
      overflow-wrap: anywhere;
      white-space: pre-wrap;
    }

    .deployment-actions {
      display: flex;
      flex-wrap: wrap;
      gap: 10px;
      margin-top: 28px;
    }

    .deployment-actions button {
      width: auto;
    }

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

      .section.full {
        grid-column: auto;
      }

      .bot-card {
        grid-template-columns: 1fr;
      }

      .topbar {
        padding: 0 16px;
      }

      .username {
        display: none;
      }
    }

    .role-badge {
      display: inline-flex;
      align-items: center;
      padding: 5px 9px;
      border: 1px solid #d8d8d8;
      border-radius: 999px;
      font-size: 11px;
      font-weight: 700;
      text-transform: uppercase;
      letter-spacing: .05em;
      background: #f5f5f5;
      color: #444;
    }

    .topbar-nav {
      display: flex;
      gap: 8px;
      align-items: center;
      margin-left: auto;
      margin-right: 16px;
    }

    .nav-button {
      border: 0;
      background: transparent;
      cursor: pointer;
      padding: 8px 10px;
      border-radius: 7px;
      font-weight: 600;
      color: inherit;
    }

    .nav-button:hover,
    .nav-button.active {
      background: rgba(127,127,127,.12);
    }

    .audit-filters {
      display: grid;
      grid-template-columns:
        repeat(auto-fit, minmax(150px, 1fr));
      gap: 12px;
      margin: 20px 0;
      align-items: end;
    }

    .audit-table-wrap {
      overflow-x: auto;
    }

    .audit-table {
      width: 100%;
      border-collapse: collapse;
      font-size: 14px;
    }

    .audit-table th,
    .audit-table td {
      text-align: left;
      padding: 12px;
      border-bottom: 1px solid #e4e4e4;
      vertical-align: top;
    }

    .audit-table th {
      font-size: 12px;
      text-transform: uppercase;
      letter-spacing: .04em;
      opacity: .65;
    }

    .audit-success {
      font-weight: 700;
    }

    .audit-failure {
      font-weight: 700;
    }

    .audit-meta {
      white-space: pre-wrap;
      word-break: break-word;
      font-family: monospace;
      font-size: 12px;
      max-width: 360px;
    }

    .audit-pagination {
      display: flex;
      justify-content: flex-end;
      align-items: center;
      gap: 12px;
      margin-top: 18px;
    }

    .test-layout {
      display: grid;
      grid-template-columns: 260px 1fr;
      gap: 20px;
      margin-top: 20px;
    }

    .test-sidebar,
    .test-chat-card {
      border: 1px solid #ddd;
      border-radius: 12px;
      padding: 18px;
      background: #fff;
    }

    .test-messages {
      min-height: 420px;
      max-height: 58vh;
      overflow-y: auto;
      display: flex;
      flex-direction: column;
      gap: 12px;
      margin-bottom: 16px;
    }

    .test-message {
      padding: 12px 14px;
      border-radius: 10px;
      white-space: pre-wrap;
      word-break: break-word;
      max-width: 85%;
    }

    .test-message.user {
      align-self: flex-end;
      background: #eeeeee;
    }

    .test-message.assistant {
      align-self: flex-start;
      border: 1px solid #ddd;
    }

    .test-composer {
      display: flex;
      gap: 10px;
    }

    .test-composer textarea {
      flex: 1;
      min-height: 70px;
      resize: vertical;
    }

    @media (max-width: 760px) {
      .topbar-nav {
        margin-right: 8px;
      }

      .test-layout {
        grid-template-columns: 1fr;
      }
    }


    .users-toolbar {
      display: flex;
      justify-content: space-between;
      gap: 16px;
      align-items: center;
      margin: 20px 0;
      flex-wrap: wrap;
    }

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

    .user-card {
      border: 1px solid #ddd;
      border-radius: 12px;
      padding: 18px;
      background: #fff;
    }

    .user-card-header {
      display: flex;
      justify-content: space-between;
      gap: 16px;
      align-items: flex-start;
      flex-wrap: wrap;
    }

    .user-name {
      font-size: 18px;
      font-weight: 700;
    }

    .user-meta {
      margin-top: 5px;
      font-size: 13px;
      opacity: .7;
    }

    .user-actions {
      display: flex;
      gap: 8px;
      flex-wrap: wrap;
      margin-top: 16px;
    }

    .user-role-row {
      display: flex;
      gap: 10px;
      align-items: center;
      margin-top: 14px;
      flex-wrap: wrap;
    }

    .user-role-row select {
      min-width: 150px;
    }

    .create-user-panel {
      border: 1px solid #ddd;
      border-radius: 12px;
      padding: 18px;
      margin-bottom: 22px;
      background: #fff;
    }

    .create-user-grid {
      display: grid;
      grid-template-columns:
        repeat(auto-fit, minmax(180px, 1fr));
      gap: 14px;
      align-items: end;
    }

    .user-status-active {
      font-weight: 700;
    }

    .user-status-disabled {
      font-weight: 700;
      opacity: .6;
    }

  
    /* Phase 3F: Analytics & Health */
    .analytics-health-layout {
      display: grid;
      grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
      gap: 24px;
      align-items: start;
    }

    .analytics-health-business,
    .analytics-health-system {
      min-width: 0;
    }

    .analytics-health-business > h2,
    .analytics-health-panel > h2 {
      margin-top: 0;
    }

    .analytics-health-business .kpi-grid {
      grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .analytics-health-business .analytics-grid {
      grid-template-columns: minmax(0, 1fr);
    }

    .analytics-health-business .analytics-card {
      min-width: 0;
    }

    .analytics-health-business .period-tabs {
      flex-wrap: wrap;
    }

    .analytics-health-panel {
      display: flex;
      flex-direction: column;
      gap: 18px;
    }

    .health-description {
      opacity: .7;
      margin: 0;
    }

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

    .health-metric {
      padding: 20px;
      border: 1px solid #ddd;
      border-radius: 12px;
      background: #fff;
      min-width: 0;
    }

    .health-metric small {
      display: block;
      margin-top: 8px;
      opacity: .6;
    }

    .health-status-row {
      display: flex;
      justify-content: space-between;
      gap: 12px;
      padding: 12px 0;
      border-bottom: 1px solid #eee;
    }

    .health-status-row strong {
      font-size: 13px;
      opacity: .65;
    }

    @media (max-width: 1100px) {
      .analytics-health-layout {
        grid-template-columns: minmax(0, 1fr);
      }
    }

    @media (max-width: 600px) {
      .health-metric-grid {
        grid-template-columns: minmax(0, 1fr);
      }
    }


    /* Overview section separation */

    #dashboard .page-header {
      margin-bottom: 24px;
    }

    #dashboard .bot-grid {
      margin-bottom: 0;
    }

    #dashboard .overview-insights {
      margin-top: 56px;
      padding-top: 36px;
      border-top: 2px solid rgba(127,127,127,.22);
      gap: 24px;
    }

    #dashboard .overview-insights .analytics-card {
      padding: 26px;
    }

    #dashboard .overview-insights h2 {
      margin-bottom: 18px;
    }

    @media (max-width: 760px) {
      #dashboard .overview-insights {
        margin-top: 36px;
        padding-top: 24px;
      }
    }


    /* Phase 3F: live health filters */
    .health-period-controls { display: flex; flex-wrap: wrap; gap: 8px; }
    .health-period-button { border: 1px solid #ddd; background: transparent; color: inherit; padding: 9px 12px; border-radius: 8px; cursor: pointer; font-weight: 600; }
    .health-period-button.active { background: #222; color: #fff; border-color: #222; }
    .health-period-button:hover { border-color: #888; }



.test-message.assistant { white-space: normal; }
.test-message.assistant p { margin: 0 0 8px; }
.test-message.assistant p:last-child { margin-bottom: 0; }
.test-message.assistant ul,
.test-message.assistant ol {
  padding-left: 22px;
  margin: 6px 0;
}
.test-message.assistant li { margin: 3px 0; }
.test-message.assistant pre { overflow-x: auto; }


.tuner-settings-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(190px,1fr));gap:12px;margin:14px 0}
.tuner-settings-grid label{font-size:13px;display:flex;flex-direction:column;gap:5px}
.tuner-settings-grid input,.tuner-settings-grid select{width:100%;padding:9px;border-radius:8px;border:1px solid #888;background:transparent;color:inherit}
.tuner-settings-grid option{color:#111}
.tuner-actions{display:flex;gap:8px;flex-wrap:wrap}
.tuner-run-row{border:1px solid #7775;border-radius:9px;margin:10px 0;padding:13px;display:flex;flex-direction:column;gap:9px}
.tuner-run-row small{opacity:.75}
.tuner-stat-row{display:flex;flex-wrap:wrap;gap:14px}
.tuner-stat{display:flex;flex-direction:column;gap:4px}.tuner-stat strong{font-size:17px}
.tuner-proposal{white-space:pre-wrap;word-break:break-word;max-height:260px;overflow:auto;padding:10px;border:1px solid #7775;border-radius:8px;font-size:12px}
.tuner-transcript{white-space:pre-wrap;border-bottom:1px solid #7773;padding:10px 2px}
#aquilaTunerSection button{max-width:100%}


/* Astra conversation inspector v3: nested, readable and theme-friendly. */
.tuner-evidence[hidden]{display:none}
.tuner-evidence{display:grid;gap:12px;margin-top:10px;min-width:0}
.tuner-scenario{border:1px solid #7775;border-radius:10px;overflow:hidden;min-width:0}
.tuner-scenario-title{display:flex;gap:12px;align-items:center;flex-wrap:wrap;padding:12px 14px;cursor:pointer;font-size:13px}
.tuner-scenario-score{margin-left:auto;font-variant-numeric:tabular-nums}
.tuner-critical{color:#e1a0a0;font-size:12px}
.tuner-turn{margin:8px 12px 14px;padding:14px;border:1px solid #7774;border-radius:10px;min-width:0}
.tuner-turn-heading{display:flex;justify-content:space-between;gap:8px;align-items:center;flex-wrap:wrap;margin-bottom:10px}
.tuner-grade-number{font-size:13px;font-variant-numeric:tabular-nums}
.tuner-field{min-width:0;margin:10px 0}
.tuner-field-label{font-size:12px;font-weight:750;display:block;margin-bottom:3px}
.tuner-field-value{font-size:13px;white-space:pre-wrap;overflow-wrap:anywhere;margin:0;line-height:1.55}
.tuner-grading{background:rgba(128,128,128,.09);border:1px solid #8883;border-radius:8px;padding:10px 12px;margin:14px 0}
.tuner-plan{border:1px solid #5687c977;border-radius:10px;padding:14px;background:rgba(86,135,201,.07);min-width:0}
.tuner-plan-attempt{border-bottom:1px solid #8883;padding:8px 0}
.tuner-plan-attempt:last-child{border-bottom:0}
.tuner-plan-history{margin-top:10px}
.tuner-rag-group,.tuner-rag-item,.tuner-diagnostic-focus{border:1px solid #7774;border-radius:8px;margin:9px 0;min-width:0}
.tuner-rag-group>summary,.tuner-rag-item>summary,.tuner-diagnostic-focus>summary{cursor:pointer;padding:9px 12px;font-weight:650;font-size:12px;overflow-wrap:anywhere}
.tuner-rag-item{margin:7px 10px}
.tuner-rag-json{white-space:pre-wrap;overflow-wrap:anywhere;word-break:break-word;max-height:360px;overflow:auto;font-size:12px;line-height:1.4;margin:0 10px 10px;padding:11px;border:1px solid #7773;border-radius:6px;background:rgba(128,128,128,.075)}
.tuner-empty-evidence,.tuner-diagnostic-focus p{padding:8px 12px;margin:0;font-size:12px;opacity:.82}
@media(max-width:640px){.tuner-scenario-title{padding:10px}.tuner-scenario-score{margin-left:0}.tuner-turn{margin:7px;padding:10px}}

/* SmartForge administration refit. */
:root {
  color-scheme: light;
  --sf-bg: #f6f5f3;
  --sf-surface: #fff;
  --sf-surface-2: #f1eff1;
  --sf-ink: #1b1720;
  --sf-muted: #655e6a;
  --sf-border: #e7e0e7;
  --sf-purple: #4f0060;
  --sf-orange: #ed7900;
  --sf-accent: #4f0060;
  --sf-accent-ink: #fff;
  --sf-shadow: 0 24px 72px rgba(54,12,62,.09);
}

html[data-theme="dark"] {
  color-scheme: dark;
  --sf-bg: #0e131a;
  --sf-surface: #171d25;
  --sf-surface-2: #202631;
  --sf-ink: #f9f8fa;
  --sf-muted: #b8b6c2;
  --sf-border: #343844;
  --sf-purple: #fff;
  --sf-orange: #ff870a;
  --sf-accent: #ff870a;
  --sf-accent-ink: #201207;
  --sf-shadow: 0 24px 72px rgba(0,0,0,.28);
}

html[data-theme="dark"] .login-card h1,
html[data-theme="dark"] .topbar-title,
html[data-theme="dark"] .topbar-title strong {
  color: var(--sf-purple);
}

body {
  background: var(--sf-bg);
  color: var(--sf-ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body, .app, .content, .editor-panel, .analytics-card, .metric-card, .system-errors,
.login-card, dialog, .test-sidebar, .test-chat, .bot-card {
  transition: background-color .18s ease, border-color .18s ease, color .18s ease;
}

.app { background: var(--sf-bg); }
.topbar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 50;
  width: 264px;
  height: 100vh;
  padding: 30px 20px 20px;
  align-items: stretch;
  justify-content: flex-start;
  flex-direction: column;
  gap: 28px;
  color: var(--sf-ink);
  background: var(--sf-surface);
  border-right: 1px solid var(--sf-border);
}

.topbar-title { display: grid; gap: 5px; line-height: 1.05; }
.topbar-title span { color: var(--sf-orange); font-size: 11px; font-weight: 850; letter-spacing: .16em; }
.topbar-title strong { color: var(--sf-purple); font-size: 20px; letter-spacing: -.035em; }
.topbar-nav { display: grid; gap: 5px; align-content: start; }
.nav-button {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid transparent;
  border-radius: 10px;
  color: var(--sf-muted);
  background: transparent;
  text-align: left;
  font-weight: 680;
}
.nav-button:hover { color: var(--sf-ink); background: var(--sf-surface-2); }
.nav-button.active { color: var(--sf-accent); background: var(--sf-surface-2); border-color: var(--sf-border); }
.topbar-right { margin-top: auto; display: grid; gap: 9px; align-items: stretch; }
.topbar .username { color: var(--sf-ink); font-weight: 700; }
.role-badge { justify-self: start; background: var(--sf-surface-2); color: var(--sf-muted); border: 1px solid var(--sf-border); }
.theme-toggle, .logout-button {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--sf-border);
  border-radius: 10px;
  color: var(--sf-ink);
  background: var(--sf-surface-2);
  font-weight: 700;
}
.logout-button { color: var(--sf-muted); background: transparent; }
.theme-toggle:hover, .logout-button:hover { border-color: var(--sf-accent); }

.content { width: auto; max-width: 1440px; margin: 0 0 0 264px; padding: 42px clamp(24px,4vw,64px) 80px; }
.page-header, .analytics-header { margin-bottom: 28px; }
.page-header h1, .analytics-header h1 { color: var(--sf-purple); letter-spacing: -.035em; }
.page-header p, .analytics-header p, .section-intro { color: var(--sf-muted); line-height: 1.6; }
.section-intro { margin: -6px 0 18px; }

.section, .analytics-card, .metric-card, .system-errors, .test-sidebar, .test-chat, .bot-card,
.login-card, dialog, .conversation-viewer-inner {
  color: var(--sf-ink);
  background: var(--sf-surface);
  border-color: var(--sf-border);
  box-shadow: var(--sf-shadow);
}
.section, .analytics-card, .system-errors, .bot-card { border-radius: 16px; }
.section h2, .analytics-card h2, .system-errors h2 { color: var(--sf-ink); letter-spacing: -.02em; }
.bot-meta, .muted, small { color: var(--sf-muted); }

input, textarea, select, .field input, .field textarea, .field select {
  color: var(--sf-ink);
  background: var(--sf-surface);
  border-color: var(--sf-border);
  border-radius: 10px;
}
input::placeholder, textarea::placeholder { color: var(--sf-muted); opacity: .75; }
.field label, label { color: var(--sf-ink); }
button, .primary-button { border-radius: 10px; }
.primary-button, .login-card button[type="submit"] { background: var(--sf-accent); color: var(--sf-accent-ink); }
.secondary-button { color: var(--sf-ink); background: var(--sf-surface-2); border-color: var(--sf-border); }
table { color: var(--sf-ink); }
th { color: var(--sf-muted); background: var(--sf-surface-2); }
td, th { border-color: var(--sf-border); }

.editor-tabs { gap: 6px; padding: 6px; background: var(--sf-surface-2); border: 1px solid var(--sf-border); border-radius: 12px; }
.editor-tab { color: var(--sf-muted); border-radius: 8px; }
.editor-tab.active { color: var(--sf-accent-ink); background: var(--sf-accent); }

.tool-manager-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.tool-manager-summary { display: grid; gap: 3px; }
.tool-manager-summary strong { color: var(--sf-purple); font-size: 15px; }
.tool-manager-summary span { color: var(--sf-muted); font-size: 12px; }
.tool-search { width: min(100%,280px); padding: 10px 12px; }
.tool-list { display: grid; gap: 10px; }
.tool-card { padding: 17px; border: 1px solid var(--sf-border); border-radius: 14px; background: var(--sf-surface-2); }
.tool-card.is-enabled { border-color: color-mix(in srgb,var(--sf-accent) 50%,var(--sf-border)); background: var(--sf-surface); }
.tool-card-heading { display: flex; gap: 20px; justify-content: space-between; align-items: center; }
.tool-card-heading > div { min-width: 0; }
.tool-name-line { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.tool-card p { margin: 6px 0 0; color: var(--sf-muted); font-size: 13px; line-height: 1.5; }
.tool-status { padding: 3px 7px; border: 1px solid var(--sf-border); border-radius: 999px; color: var(--sf-muted); font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; }
.tool-status.enabled { color: var(--sf-accent); border-color: color-mix(in srgb,var(--sf-accent) 38%,var(--sf-border)); }
.tool-toggle { position: relative; flex: 0 0 46px; width: 46px; height: 26px; padding: 0; border: 1px solid var(--sf-border); border-radius: 999px; background: var(--sf-border); }
.tool-toggle span { position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 2px 7px rgba(0,0,0,.22); transition: transform .15s ease; }
.tool-toggle[aria-checked="true"] { background: var(--sf-accent); border-color: var(--sf-accent); }
.tool-toggle[aria-checked="true"] span { transform: translateX(20px); }
.tool-toggle:disabled { opacity: .45; cursor: not-allowed; }
.tool-config { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--sf-border); }
.tool-config > strong { display: block; margin-bottom: 12px; }
.tool-empty { padding: 24px; text-align: center; color: var(--sf-muted); border: 1px dashed var(--sf-border); border-radius: 12px; }

.login-screen { background: var(--sf-bg); }
.login-card { border-radius: 22px; }
.login-card h1 { color: var(--sf-purple); }

@media (max-width: 900px) {
  .topbar { position: sticky; inset: 0; width: 100%; height: auto; padding: 16px 20px; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 14px; border-right: 0; border-bottom: 1px solid var(--sf-border); }
  .topbar-title { margin-right: auto; }
  .topbar-nav { order: 3; width: 100%; display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; }
  .nav-button { width: auto; flex: 0 0 auto; text-align: center; }
  .topbar-right { margin: 0; display: flex; align-items: center; }
  .topbar .username, .role-badge { display: none; }
  .theme-toggle, .logout-button { width: auto; white-space: nowrap; }
  .content { margin-left: 0; padding: 30px 20px 64px; }
}

@media (max-width: 620px) {
  .topbar-title strong { font-size: 17px; }
  .theme-toggle { font-size: 0; width: 42px; }
  .theme-toggle::after { content: "◐"; font-size: 18px; }
  .tool-manager-header { align-items: stretch; flex-direction: column; }
  .tool-search { width: 100%; }
  .tool-card-heading { align-items: flex-start; }
}
