.piwi-page {
  --piwi-accent-soft: rgba(201, 169, 98, 0.14);
  --piwi-accent-border: rgba(201, 169, 98, 0.34);
  --piwi-mark-bg: linear-gradient(155deg, #e8d4a8 0%, #c9a962 52%, #a88644 100%);
  display: flex;
  flex-direction: column;
  gap: 16px;
  height: calc(100dvh - 48px);
  min-height: 520px;
}

@media (max-width: 1024px) {
  .piwi-page {
    height: auto;
    min-height: 0;
    flex: 1;
  }

  .piwi-header {
    flex-direction: column;
    align-items: stretch;
  }

  .piwi-actions {
    width: 100%;
  }

  .piwi-actions .btn {
    width: 100%;
    justify-content: center;
  }
}

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

.piwi-header-main {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.piwi-header-copy {
  min-width: 0;
}

.piwi-mark {
  flex-shrink: 0;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  padding: 8px;
  background: var(--piwi-mark-bg);
  border: 1px solid rgba(168, 134, 68, 0.35);
  box-shadow: 0 2px 8px rgba(168, 134, 68, 0.18);
}

.piwi-mark--compact {
  width: 34px;
  height: 34px;
  padding: 6px;
  margin-top: 1px;
}

.piwi-mark svg {
  width: 100%;
  height: 100%;
  display: block;
}

.piwi-brand-name {
  display: inline-flex;
  align-items: baseline;
  gap: 0;
  font-size: inherit;
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1.1;
}

.piwi-brand-pi {
  color: var(--text);
}

.piwi-page-title .piwi-brand-wi,
.piwi-empty-head h2 .piwi-brand-wi,
.piwi-brand-wi {
  color: var(--accent-deep);
}

.piwi-page-title {
  margin: 0 0 5px;
  font-size: 1.45rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.15;
}

.piwi-header-lead {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.5;
  max-width: 58ch;
}

.piwi-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.piwi-panel {
  flex: 1;
  display: grid;
  grid-template-rows: 1fr auto;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel);
  overflow: hidden;
  min-height: 0;
  font-size: 13px;
  line-height: 1.5;
}

.piwi-llm-notice {
  margin: 0 0 12px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(201, 169, 98, 0.45);
  background: rgba(201, 169, 98, 0.12);
  color: var(--text);
  font-size: 0.92rem;
  line-height: 1.45;
}

.piwi-messages {
  overflow-y: auto;
  padding: 20px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.piwi-empty {
  margin: auto;
  width: 100%;
  max-width: 540px;
  padding: 12px 0;
}

.piwi-empty-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel-raised, var(--panel));
  padding: 20px 22px;
  text-align: left;
}

.piwi-empty-head {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 16px;
}

.piwi-empty-head h2 {
  margin: 0 0 6px;
  font-size: 0.98rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.35;
}

.piwi-empty-headline {
  font-weight: 500;
  color: var(--muted);
}

.piwi-empty-lead {
  margin: 0;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.5;
}

.piwi-empty-topics {
  margin: 0 0 16px;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 8px;
}

.piwi-empty-topics li {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.82rem;
  color: var(--text);
  line-height: 1.4;
}

.piwi-empty-topics li::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #c9a56b;
  flex-shrink: 0;
}

.piwi-empty-prompts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.piwi-prompt-chip {
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel);
  padding: 6px 11px;
  font: inherit;
  font-size: 0.78rem;
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.12s ease, background 0.12s ease;
}

.piwi-prompt-chip:hover {
  border-color: var(--border-strong);
  background: var(--panel-raised, var(--panel));
}

.piwi-empty-note {
  margin: 0;
  font-size: 0.76rem;
  color: var(--muted);
  line-height: 1.45;
}

.piwi-row {
  display: flex;
  max-width: min(720px, 100%);
}

.piwi-row.user {
  align-self: flex-end;
}

.piwi-row.assistant {
  align-self: flex-start;
  max-width: min(760px, 100%);
  margin: 2px 0;
}

.piwi-msg {
  min-width: 0;
  line-height: 1.55;
}

.piwi-msg.user {
  padding: 10px 14px;
  border-radius: 18px;
}

.piwi-msg.assistant {
  padding: 10px 12px;
  border-radius: 12px;
}

.piwi-msg-body {
  min-width: 0;
}

.piwi-msg.user .piwi-msg-body {
  white-space: pre-wrap;
}

.piwi-msg .markdown-viewer {
  font-size: inherit;
  line-height: inherit;
}

.piwi-msg .markdown-viewer--rich > :first-child {
  margin-top: 0;
}

.piwi-msg .markdown-viewer--rich > :last-child {
  margin-bottom: 0;
}

.piwi-msg .markdown-viewer--rich p {
  margin: 0.45em 0;
}

.piwi-msg .markdown-viewer--rich ul,
.piwi-msg .markdown-viewer--rich ol {
  margin: 0.45em 0;
  padding-left: 1.25em;
}

.piwi-msg .markdown-viewer--rich li + li {
  margin-top: 0.25em;
}

.piwi-msg .markdown-viewer--rich h1 { font-size: 1.22rem; }
.piwi-msg .markdown-viewer--rich h2 { font-size: 1.1rem; }
.piwi-msg .markdown-viewer--rich h3 { font-size: 1rem; }
.piwi-msg .markdown-viewer--rich h4 { font-size: 0.94rem; }

.piwi-msg .markdown-viewer--rich strong {
  font-weight: 600;
}

.piwi-msg.user {
  background: linear-gradient(155deg, #1e1c18 0%, #141210 100%);
  color: #fff;
  border: 0;
}

.piwi-msg.assistant {
  background: #f3f5f7;
  border: 1px solid var(--border);
  color: var(--text);
}

.piwi-msg--typing .piwi-msg-body {
  display: flex;
  align-items: center;
  min-height: 1.35rem;
}

.piwi-typing-dots {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 0;
}

.piwi-typing-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted, #706f6a);
  opacity: 0.35;
  animation: piwi-typing-dot 1.2s ease-in-out infinite;
}

.piwi-typing-dots span:nth-child(2) {
  animation-delay: 0.15s;
}

.piwi-typing-dots span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes piwi-typing-dot {
  0%,
  60%,
  100% {
    opacity: 0.35;
    transform: translateY(0);
  }

  30% {
    opacity: 1;
    transform: translateY(-4px);
  }
}

.piwi-citations {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid rgba(0, 0, 0, 0.08);
  font-size: 0.78rem;
  color: var(--muted);
}

.piwi-msg.user .piwi-citations {
  border-top-color: rgba(255, 255, 255, 0.15);
  color: rgba(255, 255, 255, 0.75);
}

.piwi-msg.user .piwi-citations strong {
  color: rgba(255, 255, 255, 0.9);
}

.piwi-citations ul {
  margin: 6px 0 0;
  padding-left: 18px;
}

.piwi-compose {
  padding: 14px 16px;
  border-top: 1px solid var(--border);
  background: var(--panel);
}

.piwi-compose-field {
  position: relative;
}

.piwi-compose textarea {
  display: block;
  width: 100%;
  min-height: 52px;
  max-height: 160px;
  resize: vertical;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 48px 9px 11px;
  font: inherit;
  font-size: 13px;
  line-height: 1.45;
  box-sizing: border-box;
  background: var(--panel);
}

.piwi-compose textarea:focus {
  outline: none;
  border-color: var(--border-strong, var(--border));
  box-shadow: 0 0 0 3px var(--piwi-accent-soft, rgba(201, 169, 98, 0.18));
}

.piwi-compose-send {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  min-width: 32px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.piwi-compose-send:hover:not(:disabled) {
  background: var(--panel-soft);
  color: var(--text);
}

.piwi-compose-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.piwi-compose-send svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
