@layer tokens, base, layout, components, utilities;

@layer tokens {
  .app-page {
    --app-bg: #f4f8fc;
    --panel: #ffffff;
    --panel-2: #f7f9fc;
    --panel-3: #edf3f9;
    --surface: #ffffff;
    --surface-2: #f2f6fa;
    --line: #dce6f0;
    --line-strong: #c5d4e4;
    --text: #0e2a47;
    --text-2: #40576d;
    --text-3: #6b8094;
    --gold: #b48c43;
    --gold-soft: #7a571c;
    --cyan: #0e7490;
    --green: #147a55;
    --red: #b83d3d;
    --amber: #946412;
    --shadow:
      0 22px 60px -38px rgb(14 42 71 / 0.35),
      0 6px 18px -14px rgb(14 42 71 / 0.2);
    --focus: 0 0 0 3px #ffffff, 0 0 0 6px #0e7490;
  }
}

@layer base {
  html:has(.app-page) {
    background: #f4f8fc;
  }

  .app-page {
    color-scheme: light;
    background:
      radial-gradient(820px 520px at 84% -8%, rgb(200 160 90 / 0.1), transparent 66%),
      radial-gradient(760px 520px at 4% 4%, rgb(21 149 179 / 0.08), transparent 68%),
      var(--app-bg);
  }

  .app-page ::selection {
    color: #0e2a47;
    background: #f4e6c8;
  }
}

@layer layout {
  .app-main {
    background: linear-gradient(180deg, #ffffff 0, #f8fbfe 46%, #f3f8fc 100%);
  }

  .sidebar,
  .context-panel {
    background:
      radial-gradient(320px 240px at 0 0, rgb(200 160 90 / 0.08), transparent 66%),
      #f9fbfd;
  }
}

@layer components {
  .sidebar,
  .context-panel {
    background:
      radial-gradient(320px 240px at 0 0, rgb(200 160 90 / 0.08), transparent 66%),
      #f9fbfd;
  }

  .icon-button:hover,
  .history-item:hover,
  .history-item.is-active,
  .sidebar-link:hover,
  .tool-button:hover,
  .answer-action:hover,
  .answer-action[aria-pressed="true"] {
    background: rgb(14 42 71 / 0.055);
  }

  .new-chat-button {
    color: #ffffff;
    background: linear-gradient(120deg, #173a5e, #0e2a47);
    border-color: transparent;
    box-shadow: 0 12px 28px -18px rgb(14 42 71 / 0.62);
  }

  .new-chat-button:hover {
    background: linear-gradient(120deg, #24486e, #173a5e);
    border-color: transparent;
  }

  .app-topbar {
    background: rgb(255 255 255 / 0.9);
    box-shadow: 0 1px 0 rgb(14 42 71 / 0.03);
  }

  .status-pill {
    background: #f5f9fc;
  }

  .welcome-mark {
    color: #8a641f;
    background: linear-gradient(145deg, #fffaf0, #f6ead1);
    border-color: #ead6b1;
    box-shadow: 0 16px 38px -26px rgb(14 42 71 / 0.38);
  }

  .starter-card {
    color: var(--text-2);
    background: rgb(255 255 255 / 0.8);
  }

  .starter-card:hover {
    color: var(--text);
    background: #ffffff;
  }

  .message-user .message-bubble {
    color: #173a5e;
    background: #eaf3fb;
    border-color: #ccdeed;
  }

  .assistant-avatar {
    color: #8a641f;
    background: linear-gradient(145deg, #fffaf0, #f5e8ce);
  }

  .answer-body {
    color: #334a60;
  }

  .answer-body h2,
  .answer-body h3,
  .answer-body strong {
    color: var(--text);
  }

  .answer-body code {
    color: #6f4e18;
    background: #f5eee2;
  }

  .answer-sources {
    color: var(--text-3);
    background: #f6f9fc;
  }

  .error-answer {
    color: #922f2f;
    background: #fdf0ef;
    border-color: #f0c9c5;
  }

  .composer-wrap {
    background: linear-gradient(to top, #f4f8fc 68%, rgb(244 248 252 / 0.9) 86%, transparent);
  }

  .composer {
    background: #ffffff;
    border-color: #c7d7e6;
  }

  .upload-chip {
    background: #ffffff;
  }

  .upload-chip.is-error {
    color: #922f2f;
    border-color: #e5b8b4;
  }

  .save-button,
  .send-button {
    color: #ffffff;
    background: linear-gradient(145deg, #24486e, #0e2a47);
  }

  .send-button.is-stop {
    color: #ffffff;
    background: #a94444;
  }

  .composer-tools {
    background: #f8fbfd;
  }

  .estimate-inline strong {
    color: var(--gold-soft);
  }

  .validity-card {
    background: #fff9ed;
    border-color: #ecdbb9;
  }

  .file-row,
  .context-empty,
  .usage-box,
  .context-btn,
  .package-option {
    background: rgb(255 255 255 / 0.76);
  }

  .context-btn:hover,
  .file-delete:hover {
    background: rgb(14 42 71 / 0.055);
  }

  .credit-progress {
    background: #e5edf5;
  }

  .saas-nudge {
    background: linear-gradient(135deg, #fffaf0, #ffffff);
    border-color: #ead7b1;
  }

  .auth-required {
    background: #ffffff;
  }

  .app-page .btn {
    color: var(--text);
    background: #ffffff;
    border-color: var(--line);
  }

  .app-page .btn:hover {
    background: #f4f8fb;
  }

  .app-page .btn-primary {
    color: #ffffff;
    background: linear-gradient(145deg, #24486e, #0e2a47);
    border-color: transparent;
  }

  .app-page .btn-primary:hover {
    filter: none;
    background: linear-gradient(145deg, #315b83, #173a5e);
  }

  .app-page .modal-card {
    color: var(--text);
    background: #ffffff;
    border-color: #d5e1ec;
    box-shadow: 0 36px 100px -38px rgb(14 42 71 / 0.5);
  }

  .modal-backdrop {
    background: rgb(14 42 71 / 0.36);
  }

  .app-page .toast {
    color: var(--text);
    background: #ffffff;
    border-color: var(--line-strong);
    box-shadow: 0 18px 54px -28px rgb(14 42 71 / 0.42);
  }

  .app-page .skeleton {
    background: #eaf1f7;
  }

  .modal-card--wide {
    inline-size: min(100%, 960px);
    max-block-size: min(90dvh, 780px);
  }

  .suggestion-layout {
    display: grid;
    grid-template-columns: minmax(0, 1.08fr) minmax(300px, 0.92fr);
    gap: 24px;
    align-items: start;
  }

  .suggestion-form {
    display: grid;
    gap: 15px;
  }

  .suggestion-field {
    display: grid;
    gap: 7px;
  }

  .suggestion-field > label,
  .suggestion-history-head h3 {
    color: var(--text);
    font-size: 0.82rem;
    font-weight: 700;
  }

  .suggestion-field > label span {
    color: var(--text-3);
    font-weight: 400;
  }

  .suggestion-textarea {
    min-block-size: 180px;
    resize: vertical;
  }

  .suggestion-help {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 8px 16px;
    color: var(--text-3);
    font-size: 0.68rem;
  }

  .suggestion-history {
    min-inline-size: 0;
    padding: 16px;
    background: #f7fafc;
    border: 1px solid var(--line);
    border-radius: 13px;
  }

  .suggestion-history-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
  }

  .suggestion-history-head p {
    margin-block-start: 3px;
    color: var(--text-3);
    font-size: 0.68rem;
  }

  .suggestion-list {
    display: grid;
    gap: 9px;
    max-block-size: 430px;
    margin-block-start: 13px;
    overflow-y: auto;
    scrollbar-width: thin;
  }

  .suggestion-item {
    padding: 12px;
    background: #ffffff;
    border: 1px solid var(--line);
    border-radius: 10px;
  }

  .suggestion-item-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
  }

  .suggestion-item-head b {
    min-inline-size: 0;
    color: var(--text);
    font-size: 0.76rem;
    overflow-wrap: anywhere;
  }

  .suggestion-item p {
    display: -webkit-box;
    margin-block-start: 6px;
    overflow: hidden;
    color: var(--text-2);
    font-size: 0.7rem;
    line-height: 1.55;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
  }

  .suggestion-item-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 5px 12px;
    margin-block-start: 9px;
    color: var(--text-3);
    font-size: 0.62rem;
  }

  .suggestion-status {
    flex: 0 0 auto;
    padding: 2px 7px;
    color: #5d471d;
    background: #f8eed9;
    border-radius: 999px;
    font-size: 0.61rem;
    font-weight: 700;
  }

  .suggestion-status[data-status="accepted"] {
    color: #12694a;
    background: #e1f5ec;
  }

  .suggestion-status[data-status="declined"] {
    color: #7d6262;
    background: #f3eeee;
  }

  .suggestion-status[data-status="reviewing"] {
    color: #0e667c;
    background: #e2f3f7;
  }

  @media (max-width: 820px) {
    .suggestion-layout {
      grid-template-columns: 1fr;
    }

    .suggestion-list {
      max-block-size: 300px;
    }
  }

  @media (max-width: 520px) {
    .modal-card--wide {
      max-block-size: 92dvh;
    }

    .suggestion-layout {
      gap: 18px;
    }
  }
}
