import { css } from '@genesislcap/web-core';

/** Styles for the assistant settings modal (tabs, sections, toggles, cost summary). */
export const settingsModalStyles = css`
  *,
  *::before,
  *::after {
    box-sizing: border-box;
  }

  .settings-modal {
    --ai-tier-badge-bg-mix: 14%;
    --ai-tier-badge-text-lighten: 18%;
  }

  .settings-modal::part(dialog) {
    max-width: 620px;
    width: calc(100vw - 48px);
    max-height: calc(100vh - 48px);
    padding: 0;
  }

  .settings-modal::part(content) {
    display: flex;
    flex-direction: column;
    min-height: 0;
    padding: 0;
    width: 100%;
  }

  .settings-modal::part(top) {
    padding: calc(var(--design-unit) * 4px) calc(var(--design-unit) * 5px);
    border-bottom: 1px solid var(--neutral-stroke-rest);
  }

  .settings-modal::part(bottom) {
    padding: calc(var(--design-unit) * 4px) calc(var(--design-unit) * 5px);
    border-top: 1px solid var(--neutral-stroke-rest);
    border-bottom-left-radius: var(--card-border-radius, calc(var(--control-corner-radius) * 1px));
    border-bottom-right-radius: var(--card-border-radius, calc(var(--control-corner-radius) * 1px));
    background-color: var(--neutral-layer-2);
  }

  .settings-modal-header {
    display: flex;
    align-items: center;
    min-width: 0;
  }

  .settings-modal-title {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: calc(var(--design-unit) * 2px);
    color: var(--neutral-foreground-rest);
  }

  .settings-modal-content {
    display: flex;
    flex-direction: column;
    min-height: 0;
    flex: 1 1 auto;
  }

  .settings-modal-tabs::part(tablist) {
    border-bottom: 0;
    padding: 0 calc(var(--design-unit) * 5px);
    column-gap: calc(var(--design-unit) * 5px);
  }

  .settings-modal-tabs::part(activeIndicator) {
    height: 2px;
  }

  .settings-modal-tab {
    padding: 0;
    font-weight: 600;
    gap: 6px;
  }

  .settings-modal-tab[aria-selected='true'] {
    color: var(--neutral-foreground-rest);
  }

  .settings-modal-tabs::part(tabpanel) {
    border-top: 1px solid var(--neutral-stroke-rest);
  }

  .settings-modal-tab-panel {
    display: flex;
    flex-direction: column;
    min-height: 0;
    flex: 1 1 auto;
    padding: 0;
    border-radius: 0;
  }

  .settings-modal-tab-panel[hidden] {
    display: none !important;
  }

  .settings-modal-body {
    overflow-y: auto;
    padding: 0 calc(var(--design-unit) * 5px) calc(var(--design-unit) * 2px);
    max-height: min(60vh, 520px);
  }

  .settings-modal-section {
    padding: calc(var(--design-unit) * 5px) 0;
    border-bottom: 1px solid var(--neutral-stroke-rest);
  }

  .settings-modal-section:last-child {
    border-bottom: none;
  }

  .settings-modal-section-title {
    margin: 0 0 calc(var(--design-unit) * 3px);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--neutral-foreground-hint);
    display: flex;
    align-items: center;
    gap: calc(var(--design-unit) * 2px);
  }

  .settings-modal-section-note {
    margin: calc(var(--design-unit) * -2px) 0 calc(var(--design-unit) * 3px);
    font-size: 12px;
    line-height: 1.5;
    color: var(--neutral-foreground-hint);
  }

  .settings-modal-section-body {
    display: flex;
    flex-direction: column;
    gap: calc(var(--design-unit) * 4px);
  }

  .settings-toggle-row {
    display: flex;
    align-items: flex-start;
    gap: calc(var(--design-unit) * 3px);
    padding: 0 0 calc(var(--design-unit) * 4px) 0;
    border-bottom: 1px solid var(--neutral-stroke-rest);
  }

  .settings-toggle-row:last-child {
    border-bottom: none;
    padding-bottom: calc(var(--design-unit) * 1px);
  }

  .settings-toggle-row.is-stacked {
    flex-direction: column;
    gap: calc(var(--design-unit) * 2px);
  }

  .settings-animation-list {
    display: flex;
    flex-direction: column;
    width: 100%;
    border: 1px solid var(--neutral-stroke-rest);
    border-radius: calc(var(--control-corner-radius) * 1.2px);
    padding: calc(var(--design-unit) * 2px);
    gap: calc(var(--design-unit) * 2px);
  }

  .settings-animation-list .settings-toggle-row {
    border: 0;
  }

  .settings-animation-category {
    display: flex;
    flex-direction: column;
    gap: calc(var(--design-unit) * 4px);
  }

  .settings-animation-category-label {
    font-weight: 600;
    color: var(--neutral-foreground-hint);
  }

  .settings-toggle-row + .settings-animation-category-label {
    border-top: 1px solid var(--neutral-stroke-rest);
    padding-top: calc(var(--design-unit) * 2px);
  }

  .settings-animation-option {
    padding: 0;
    margin: 0;
  }

  .settings-animation-option:last-child {
    border-bottom: none;
    padding-bottom: calc(var(--design-unit) * 2px);
  }

  .settings-toggle-text {
    flex: 1;
    min-width: 0;
  }

  .settings-toggle-title {
    font-size: 14px;
    font-weight: 500;
    color: var(--neutral-foreground-rest);
  }

  .settings-toggle-desc {
    font-size: 12px;
    color: var(--neutral-foreground-hint);
    line-height: 1.5;
    max-width: 92%;
  }

  .settings-toggle-control {
    flex: 0 0 auto;
    min-width: 0;
  }

  .settings-toggle-control-wide {
    width: 100%;
    max-width: 280px;
  }

  .settings-toggle-row.is-stacked .settings-toggle-desc {
    max-width: none;
  }

  .settings-toggle-row.is-stacked .settings-toggle-control-wide {
    width: 100%;
    max-width: none;
  }

  .settings-app-toggle-block {
    display: flex;
    flex-direction: column;
    gap: calc(var(--design-unit) * 1px);
  }

  .settings-toggle-hint {
    font-size: 12px;
    color: var(--neutral-foreground-hint);
    line-height: 1.4;
    padding-left: calc(var(--design-unit) * 1px);
    font-style: italic;
  }

  .settings-context-header {
    display: flex;
    justify-content: space-between;
    gap: calc(var(--design-unit) * 2px);
    margin-bottom: calc(var(--design-unit) * 2px);
    font-size: 12px;
  }

  .settings-context-label {
    color: var(--neutral-foreground-hint);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
  }

  .settings-context-tokens {
    color: var(--neutral-foreground-rest);
  }

  .settings-current-build {
    background: var(--neutral-layer-2);
    border: 1px solid var(--neutral-stroke-rest);
    border-radius: calc(var(--control-corner-radius) * 1.5px);
    padding: calc(var(--design-unit) * 4px);
    margin: calc(var(--design-unit) * 3px) 0;
  }

  .settings-current-build-top {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: calc(var(--design-unit) * 2px);
    margin-bottom: calc(var(--design-unit) * 3px);
  }

  .settings-live-badge {
    display: inline-flex;
    align-items: center;
    gap: calc(var(--design-unit) * 1px);
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--accent-fill-rest);
  }

  .settings-live-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--accent-fill-rest);
    animation: settings-live-pulse 1.6s ease-out infinite;
  }

  @keyframes settings-live-pulse {
    0% {
      box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent-fill-rest) 55%, transparent);
    }

    70% {
      box-shadow: 0 0 0 7px transparent;
    }

    100% {
      box-shadow: 0 0 0 0 transparent;
    }
  }

  .settings-current-build-name {
    font-size: 14px;
    font-weight: 600;
  }

  .settings-current-build-stats {
    display: flex;
    flex-wrap: wrap;
    gap: calc(var(--design-unit) * 3px);
    margin-bottom: calc(var(--design-unit) * 3px);
  }

  .settings-build-stat {
    flex: 1;
    min-width: 0;
    background: var(--neutral-layer-1);
    border: 1px solid var(--neutral-stroke-rest);
    border-radius: calc(var(--control-corner-radius) * 1px);
    padding: calc(var(--design-unit) * 3px);
  }

  .settings-build-stat-label {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--neutral-foreground-hint);
  }

  .settings-build-stat-value {
    font-size: 22px;
    font-weight: 700;
    margin-top: calc(var(--design-unit) * 1px);
    color: var(--neutral-foreground-rest);
  }

  .settings-build-stat-value .prefix,
  .settings-build-stat-value .suffix {
    color: var(--accent-fill-rest);
  }

  .settings-model-tags {
    display: flex;
    flex-wrap: wrap;
    gap: calc(var(--design-unit) * 2px);
  }

  .settings-model-tag {
    font-size: 11px;
    font-weight: 600;
    padding: 3px 9px;
    border-radius: 20px;
    font-family: ui-monospace, monospace;
    border: 1px solid var(--neutral-stroke-rest);
  }

  .settings-model-tag,
  .settings-cost-history-icon {
    --model-tag-color: var(--neutral-foreground-rest);

    background: color-mix(
      in srgb,
      var(--model-tag-color) var(--ai-tier-badge-bg-mix),
      var(--neutral-layer-1)
    );
    border-color: color-mix(in srgb, var(--model-tag-color) 20%, var(--neutral-layer-1));
    color: color-mix(in srgb, var(--model-tag-color), white var(--ai-tier-badge-text-lighten));
  }

  .settings-cost-history-title {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--neutral-foreground-hint);
    font-weight: 600;
    margin: calc(var(--design-unit) * 4px) 0 calc(var(--design-unit) * 2px);
  }

  .settings-cost-history {
    display: flex;
    flex-direction: column;
    gap: calc(var(--design-unit) * 2px);
    padding-bottom: calc(var(--design-unit) * 2px);
  }

  .settings-cost-history-icon {
    flex: 0 0 auto;
    width: 36px;
    height: 36px;
    border-radius: calc(var(--control-corner-radius) * 1px);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 700;
    border: 1px solid var(--neutral-stroke-rest);
  }

  .settings-cost-history-row {
    display: flex;
    flex-direction: column;
    background: var(--neutral-layer-1);
    border: 1px solid var(--neutral-stroke-rest);
    border-radius: calc(var(--control-corner-radius) * 1.5px);
    padding: calc(var(--design-unit) * 4px);
  }

  .settings-cost-history-row-content {
    display: flex;
    align-items: flex-start;
    gap: calc(var(--design-unit) * 2px);
  }

  .settings-cost-history-row-content + .settings-cost-history-row-content {
    border-top: 1px solid var(--neutral-stroke-rest);
    margin-top: calc(var(--design-unit) * 2px);
    padding-top: calc(var(--design-unit) * 2px);
  }

  .settings-cost-history-row-body {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    gap: calc(var(--design-unit) * 2px);
    justify-content: space-between;
  }

  .settings-cost-history-row-right {
    align-items: flex-end;
  }

  .settings-cost-history-row-cost,
  .settings-cost-history-row-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--neutral-foreground-rest);
    min-width: 0;
  }

  .settings-cost-history-row-metrics {
    display: flex;
    flex-direction: column;
    flex: 0 0 auto;
    font-size: 13px;
    font-family: ui-monospace, monospace;
    color: var(--neutral-foreground-rest);
    white-space: nowrap;
  }

  .settings-cost-history-row-tokens,
  .settings-cost-history-row-date {
    font-size: 12px;
    color: var(--neutral-foreground-hint);
  }

  .settings-cost-history-delete {
    flex: 0 0 auto;
    margin-top: -2px;
    color: var(--neutral-foreground-hint);
  }

  .settings-cost-history-delete:hover {
    color: var(--error-color);
  }

  .settings-cost-history ::slotted(*) {
    display: block;
  }

  .settings-modal-footer {
    width: 100%;
  }

  .settings-done-button {
    margin-left: auto;
  }

  .settings-modal-footer-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: calc(var(--design-unit) * 2px);
    width: 100%;
  }

  .settings-disclaimer {
    font-size: 12px;
    color: var(--neutral-foreground-hint);
    max-width: 60%;
    line-height: 1.4;
  }

  /*
   * Inline spinner shown in the "Download agent log" button while the log builds
   * (GENC-1351 §5.8) — the lifetime-stitch path is an async provider round-trip.
   * Sized to the button label and tinted with currentColor so it tracks the
   * button's text colour in every appearance / theme.
   */
  [part='download-button'] .download-spinner {
    display: inline-block;
    width: 12px;
    height: 12px;
    margin-right: calc(var(--design-unit) * 1px);
    vertical-align: -1px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: download-spin 0.6s linear infinite;
  }

  @keyframes download-spin {
    to {
      transform: rotate(360deg);
    }
  }
`;
