  :root {
    color-scheme: light dark;
    --bg-body-light: #f3f4f6;
    --bg-body-dark: #050816;
    --bg-surface-light: #ffffff;
    --bg-surface-dark: #0f172a;
    --border-subtle-light: #e5e7eb;
    --border-subtle-dark: #1f2937;
    --text-main-light: #111827;
    --text-main-dark: #e5e7eb;
    --text-muted-light: #6b7280;
    --text-muted-dark: #9ca3af;
    --accent: #0b5cff;
    --accent-soft: rgba(11, 92, 255, 0.12);
    --danger: #ef4444;
    --radius-lg: 18px;
    --radius-sm: 999px;
    --shadow-soft-light: 0 18px 45px rgba(15, 23, 42, 0.12);
    --shadow-soft-dark: 0 18px 45px rgba(0, 0, 0, 0.8);
  }

  /* ====== ÁÀÇÀ ====== */

  body {
    margin: 0;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "SF Pro Text",
                 Segoe UI, Roboto, Ubuntu, Cantarell, "Helvetica Neue", Arial, sans-serif;
    background: radial-gradient(circle at top, rgba(59,130,246,0.12), transparent 55%),
                radial-gradient(circle at bottom, rgba(56,189,248,0.16), transparent 55%);
    color: var(--text-main-light);
    min-height: 100vh;
  }

  .wrap {
    max-width: 960px;
    margin: 0 auto;
    padding: 20px 16px 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
  }

  /* ====== ÕÅÄÅÐ ====== */

  header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 14px;
    border-radius: var(--radius-lg);
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid rgba(148, 163, 184, 0.35);
    backdrop-filter: blur(18px);
    box-shadow: var(--shadow-soft-light);
  }

  h1 {
    font-size: 18px;
    margin: 0;
    letter-spacing: 0.02em;
    display: flex;
    align-items: center;
    gap: 10px;
  }

  h1::before {
    content: "";
    width: 22px;
    height: 22px;
    border-radius: 8px;
    background: radial-gradient(circle at 30% 20%, #93c5fd, transparent 60%),
                radial-gradient(circle at 70% 80%, #0ea5e9, transparent 60%);
    box-shadow: 0 0 0 1px rgba(148, 163, 184, 0.35);
  }

  .controls {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .meta {
    font-size: 12px;
    color: var(--text-muted-light);
    padding: 4px 10px;
    border-radius: var(--radius-sm);
    background: rgba(148, 163, 184, 0.12);
  }

  /* ====== ÊÍÎÏÊÈ, ²ÍÏÓÒÈ ====== */

  button,
  input,
  textarea {
    font: inherit;
    border-radius: 999px;
    border: 1px solid rgba(148, 163, 184, 0.7);
    padding: 9px 14px;
    background: rgba(255, 255, 255, 0.95);
    color: inherit;
    transition: all 0.16s ease-out;
  }

  button {
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
  }

  button:hover {
    transform: translateY(-1px);
    box-shadow: 0 10px 22px rgba(15, 23, 42, 0.12);
    border-color: rgba(15, 23, 42, 0.16);
  }

  button:active {
    transform: translateY(0);
    box-shadow: none;
  }

  button.primary {
    background: linear-gradient(135deg, #2563eb, #0ea5e9);
    border-color: transparent;
    color: #ffffff;
  }

  button.primary:hover {
    box-shadow: 0 14px 30px rgba(37, 99, 235, 0.45);
  }

  button.danger {
    border-color: rgba(239, 68, 68, 0.6);
    color: #b91c1c;
    background: rgba(254, 242, 242, 0.9);
  }

  button.danger:hover {
    background: #ef4444;
    color: #fff;
    border-color: #ef4444;
    box-shadow: 0 12px 26px rgba(239, 68, 68, 0.5);
  }

  button[disabled],
  textarea[disabled] {
    opacity: 0.6;
    cursor: default;
    box-shadow: none;
    transform: none;
  }

  textarea {
    border-radius: 18px;
    flex: 1;
    min-height: 72px;
    resize: vertical;
    background: rgba(248, 250, 252, 0.9);
    border-color: rgba(148, 163, 184, 0.7);
  }

  textarea:focus,
  button:focus-visible {
    outline: none;
    box-shadow: 0 0 0 1px rgba(129, 140, 248, 0.8),
                0 0 0 5px rgba(129, 140, 248, 0.18);
    border-color: #4f46e5;
  }

  /* ====== Â²ÊÍÎ ×ÀÒÓ ====== */

  #history {
    border-radius: var(--radius-lg);
    padding: 16px 16px 12px;
    height: 50vh;
    overflow: auto;
    background: var(--bg-surface-light);
    border: 1px solid var(--border-subtle-light);
    box-shadow: var(--shadow-soft-light);
    display: flex;
    flex-direction: column;
  }

  /* Ñêðîëáàð */
  #history::-webkit-scrollbar {
    width: 8px;
  }
  #history::-webkit-scrollbar-track {
    background: transparent;
  }
  #history::-webkit-scrollbar-thumb {
    background: rgba(148, 163, 184, 0.8);
    border-radius: 999px;
  }

  .msg {
    padding: 10px 12px;
    border-radius: 16px;
    margin: 4px 0 8px;
    white-space: pre-wrap;
    line-height: 1.5;
    font-size: 14px;
    max-width: 90%;
    box-shadow: 0 6px 18px rgba(15, 23, 42, 0.06);
    position: relative;
    opacity: 0;
    transform: translateY(4px);
    animation: msg-in 0.18s ease-out forwards;
  }

  .msg.user {
    background: #e0ebff;
    color: #111827;
    margin-left: auto;
    border-bottom-right-radius: 4px;
  }

  .msg.assistant {
    background: #f3f4f6;
    color: #111827;
    margin-right: auto;
    border-bottom-left-radius: 4px;
  }

  @keyframes msg-in {
    from { opacity: 0; transform: translateY(6px) scale(0.99); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
  }

  .system-note {
    font-size: 12px;
    opacity: .75;
    margin-top: 4px;
    color: var(--text-muted-light);
  }

  .footer {
    font-size: 11px;
    opacity: .7;
    margin-top: 4px;
    color: var(--text-muted-light);
  }

  /* ====== ÔÎÐÌÀ ÂÂÎÄÓ ====== */

  form#askForm {
    display: flex;
    gap: 10px;
    margin-top: 12px;
    align-items: flex-end;
  }

  /* ====== ²ÑÒÎÐ²ß ×ÀÒ²Â ====== */

  #sessionsSection {
    margin-top: 10px;
    padding: 10px 12px 6px;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.88);
    border: 1px dashed rgba(148, 163, 184, 0.7);
  }

  #sessionsSection h2 {
    font-size: 13px;
    margin: 0 0 8px;
    color: var(--text-muted-light);
    text-transform: uppercase;
    letter-spacing: 0.08em;
  }

  #sessionsList {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
  }

  .session-item {
    border-radius: var(--radius-sm);
    border: 1px solid rgba(148, 163, 184, 0.7);
    padding: 5px 11px;
    font-size: 12px;
    background: rgba(248, 250, 252, 0.95);
    cursor: pointer;
    max-width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text-main-light);
    transition: all 0.16s ease-out;
  }

  .session-item:hover {
    background: var(--accent-soft);
    border-color: rgba(37, 99, 235, 0.7);
    color: #1d4ed8;
    box-shadow: 0 8px 22px rgba(37, 99, 235, 0.18);
    transform: translateY(-1px);
  }

  .session-item.active {
    border-color: var(--accent);
    background: var(--accent-soft);
    color: #1d4ed8;
    font-weight: 500;
  }

  /* ====== ÀÄÀÏÒÈÂ ====== */

  @media (max-width: 720px) {
    header {
      flex-direction: column;
      align-items: flex-start;
      gap: 8px;
    }
    .controls {
      width: 100%;
      justify-content: space-between;
    }
    #history {
      height: 55vh;
    }
    form#askForm {
      flex-direction: column;
      align-items: stretch;
    }
    textarea {
      width: 100%;
    }
    button.primary {
      width: 100%;
      justify-content: center;
    }
  }

  /* ====== DARK MODE ====== */

  @media (prefers-color-scheme: dark) {
    body {
      background: radial-gradient(circle at top, rgba(37,99,235,0.3), transparent 55%),
                  radial-gradient(circle at bottom, rgba(8,47,73,0.8), transparent 65%);
      color: var(--text-main-dark);
    }

    .wrap {
      color: var(--text-main-dark);
    }

    header {
      background: rgba(15, 23, 42, 0.96);
      border-color: rgba(51, 65, 85, 0.9);
      box-shadow: var(--shadow-soft-dark);
    }

    h1 {
      color: var(--text-main-dark);
    }

    .meta {
      background: rgba(15, 23, 42, 0.9);
      color: var(--text-muted-dark);
      border: 1px solid rgba(55, 65, 81, 0.9);
    }

    button,
    textarea {
      background: rgba(15, 23, 42, 0.9);
      color: var(--text-main-dark);
      border-color: rgba(55, 65, 81, 0.9);
    }

    textarea {
      background: rgba(15, 23, 42, 0.98);
    }

    #history {
      background: var(--bg-surface-dark);
      border-color: var(--border-subtle-dark);
      box-shadow: var(--shadow-soft-dark);
    }

    .msg.user {
      background: linear-gradient(135deg, #1d4ed8, #0ea5e9);
      color: #f9fafb;
    }

    .msg.assistant {
      background: #111827;
      color: #e5e7eb;
    }

    .system-note,
    .footer {
      color: var(--text-muted-dark);
    }

    #sessionsSection {
      background: rgba(15, 23, 42, 0.98);
      border-color: rgba(55, 65, 81, 0.9);
    }

    #sessionsSection h2 {
      color: var(--text-muted-dark);
    }

    .session-item {
      background: rgba(15, 23, 42, 0.94);
      border-color: rgba(55, 65, 81, 0.9);
      color: var(--text-main-dark);
    }

    .session-item:hover {
      background: rgba(37, 99, 235, 0.25);
      border-color: #3b82f6;
      color: #bfdbfe;
      box-shadow: 0 10px 24px rgba(37, 99, 235, 0.55);
    }

    .session-item.active {
      background: rgba(37, 99, 235, 0.2);
      border-color: #3b82f6;
      color: #bfdbfe;
    }
  }



#pdrRefsSection {
  margin-top: 10px;
  padding: 10px 12px 8px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(148, 163, 184, 0.6);
 #color:#111;
}

#pdrRefsSection h2 {
  font-size: 13px;
  margin: 0 0 6px;
#  color: #222;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

#pdrRefs {
  font-size: 13px;
#color:#111;
}

#pdrRefs ul {
  padding-left: 18px;
  margin: 4px 0 0;
}

#pdrRefs li {
  margin-bottom: 2px;
color:#111;
}


@media (prefers-color-scheme: dark) {
  #pdrRefsSection {
    background: rgba(30, 30, 30, 0.8);
    color: #f0f0f0;
    border-color: rgba(100, 100, 100, 0.6);
  }
  #pdrRefsSection h2,
  #pdrRefs li {
    color: #fafafa;
  }
}