@import url("https://fonts.googleapis.com/css2?family=Manrope:wght@500;600;700&family=Sora:wght@500;600;700&display=swap");

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
}

body {
  font-family: "Manrope", "Segoe UI", sans-serif;
  background: #090a0d;
}

.app-shell {
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --radius-sm: 12px;
  --radius-md: 16px;
  --radius-lg: 20px;

  --bg-1: #08090d;
  --bg-2: #12151d;
  --surface-1: rgba(19, 24, 34, 0.92);
  --surface-2: rgba(24, 30, 42, 0.84);
  --surface-3: rgba(29, 36, 52, 0.82);
  --border: rgba(255, 255, 255, 0.12);
  --text-main: #f5f7ff;
  --text-muted: #b3bbcf;
  --text-soft: #8992a8;
  --accent: #f3364f;
  --accent-2: #be1430;
  --accent-soft: rgba(243, 54, 79, 0.2);
  --success: #34d399;
  --error: #fb7185;
  --focus-ring: rgba(243, 54, 79, 0.44);
  --shadow-soft: 0 8px 24px rgba(2, 6, 23, 0.45);
  --shadow-strong: 0 14px 28px rgba(2, 6, 23, 0.55);

  position: relative;
  width: 100%;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: var(--space-3);
  padding: var(--space-3);
  color: var(--text-main);
  background: linear-gradient(160deg, var(--bg-1), var(--bg-2));
  overflow: hidden;
  transition: background 220ms ease, color 220ms ease;
}

#appShell[data-theme="light"] {
  --bg-1: #f4f5f8;
  --bg-2: #e9ecf1;
  --surface-1: rgba(255, 255, 255, 0.92);
  --surface-2: rgba(255, 255, 255, 0.88);
  --surface-3: rgba(250, 251, 254, 0.94);
  --border: rgba(17, 24, 39, 0.12);
  --text-main: #131722;
  --text-muted: #505a6f;
  --text-soft: #6e7689;
  --accent: #d91f3f;
  --accent-2: #aa142f;
  --accent-soft: rgba(217, 31, 63, 0.14);
  --success: #059669;
  --error: #dc2626;
  --focus-ring: rgba(217, 31, 63, 0.28);
  --shadow-soft: 0 8px 20px rgba(17, 24, 39, 0.1);
  --shadow-strong: 0 14px 28px rgba(17, 24, 39, 0.14);
}

.bg-orb {
  position: absolute;
  border-radius: 999px;
  filter: blur(60px);
  pointer-events: none;
  z-index: 0;
  opacity: 0.44;
}

.bg-orb-top {
  width: 210px;
  height: 210px;
  top: -90px;
  right: -80px;
  background: radial-gradient(circle, rgba(243, 54, 79, 0.42), rgba(243, 54, 79, 0));
}

.bg-orb-bottom {
  width: 190px;
  height: 190px;
  left: -84px;
  bottom: -80px;
  background: radial-gradient(circle, rgba(190, 20, 48, 0.34), rgba(190, 20, 48, 0));
}

.panel {
  position: relative;
  z-index: 1;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface-1);
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition: background 220ms ease, border-color 220ms ease, box-shadow 220ms ease;
}

.topbar {
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
}

.brand-block {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-logo {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  font-family: "Sora", "Segoe UI", sans-serif;
  font-size: 15px;
  font-weight: 700;
  color: #ffffff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 8px 16px rgba(190, 20, 48, 0.35);
}

.brand-copy {
  min-width: 0;
}

.brand-copy h1 {
  margin: 0;
  font-family: "Sora", "Segoe UI", sans-serif;
  font-size: 17px;
  line-height: 1.05;
  letter-spacing: 0.01em;
}

.brand-copy p {
  margin: 3px 0 0;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

button,
textarea,
select,
input {
  font-family: inherit;
}

.hamburger-btn,
.theme-toggle {
  width: 34px;
  height: 34px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-main);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 180ms ease, box-shadow 180ms ease, background 180ms ease;
}

.hamburger-btn {
  flex-direction: column;
  gap: 4px;
}

.hamburger-btn span {
  width: 14px;
  height: 2px;
  border-radius: 999px;
  background: currentColor;
}

.theme-toggle span {
  font-size: 12px;
  font-weight: 700;
}

.chat-panel {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: var(--space-2);
  padding: var(--space-3);
}

.chat-meta {
  display: flex;
}

.status-badge,
.status-pill {
  min-height: 30px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-muted);
  padding: 0 11px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 600;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--text-soft);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--text-soft) 35%, transparent);
}

.status-badge.is-success {
  color: var(--success);
}

.status-badge.is-success .status-dot {
  background: var(--success);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--success) 30%, transparent);
}

.status-badge.is-error {
  color: var(--error);
}

.status-badge.is-error .status-dot {
  background: var(--error);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--error) 30%, transparent);
}

.status-pill.connected {
  color: #ffffff;
  background: linear-gradient(135deg, #059669, #0d9488);
  border-color: transparent;
}

.chat-history {
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding-right: 2px;
}

.empty-state {
  margin: auto 0;
  border-radius: var(--radius-md);
  border: 1px dashed var(--border);
  background: var(--surface-2);
  padding: var(--space-3);
}

.empty-state h3 {
  margin: 0 0 4px;
  font-size: 15px;
  font-family: "Sora", "Segoe UI", sans-serif;
}

.empty-state p {
  margin: 0;
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.45;
}

.message {
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface-2);
  padding: 10px;
}

.message-user {
  align-self: flex-end;
  width: calc(100% - 16px);
  background: color-mix(in srgb, var(--accent-soft) 68%, var(--surface-2));
}

.message-assistant {
  align-self: flex-start;
  width: calc(100% - 12px);
}

.message-head {
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  color: var(--text-muted);
  font-size: 11px;
}

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

.message-text {
  margin: 0;
  white-space: pre-wrap;
  line-height: 1.42;
  font-size: 13px;
}

.composer-panel {
  display: grid;
  gap: var(--space-2);
  padding: var(--space-3);
}

.input-wrap {
  position: relative;
}

.input-wrap textarea,
.full-doc-edit textarea,
.floating-field textarea,
.floating-field input,
.floating-field select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface-2);
  color: var(--text-main);
  transition: border-color 180ms ease, box-shadow 180ms ease, background 180ms ease;
}

.input-wrap textarea {
  min-height: 108px;
  max-height: 180px;
  resize: vertical;
  padding: 12px 12px 30px;
  box-shadow: inset 0 1px 8px rgba(15, 23, 42, 0.2);
}

.input-wrap textarea::placeholder,
.full-doc-edit textarea::placeholder,
.floating-field textarea::placeholder {
  color: color-mix(in srgb, var(--text-muted) 74%, transparent);
}

.char-count {
  position: absolute;
  right: 10px;
  bottom: 8px;
  font-size: 11px;
  color: var(--text-muted);
}

.char-count.warning {
  color: #d97706;
}

.ghost-btn,
.primary-btn,
.drawer-chip,
.action-btn {
  min-height: 40px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-main);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 180ms ease, box-shadow 180ms ease, background 180ms ease, border-color 180ms ease;
}

.primary-btn {
  width: 100%;
  border-color: transparent;
  color: #ffffff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 10px 22px color-mix(in srgb, var(--accent) 40%, transparent);
}

button:hover {
  box-shadow: var(--shadow-strong);
}

button:active {
  transform: scale(0.97);
}

.drawer-backdrop {
  position: absolute;
  inset: 0;
  z-index: 10;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

.app-drawer {
  position: absolute;
  top: var(--space-3);
  left: var(--space-3);
  bottom: var(--space-3);
  width: min(92vw, 350px);
  z-index: 11;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--surface-1);
  box-shadow: var(--shadow-strong);
  padding: var(--space-3);
  overflow-y: auto;
  transform: translateX(-112%);
  opacity: 0;
  pointer-events: none;
  transition: transform 180ms ease, opacity 180ms ease;
}

.app-drawer.open {
  transform: translateX(0);
  opacity: 1;
  pointer-events: auto;
}

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-3);
}

.drawer-head p {
  margin: 0;
  font-size: 15px;
  font-family: "Sora", "Segoe UI", sans-serif;
}

.drawer-close-btn {
  width: 32px;
  height: 32px;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-main);
  cursor: pointer;
}

.drawer-section {
  margin-bottom: var(--space-3);
}

.surface-card {
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface-3);
  padding: var(--space-3);
}

.drawer-section h2 {
  margin: 0 0 10px;
  font-size: 12px;
  color: var(--text-soft);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-family: "Sora", "Segoe UI", sans-serif;
}

.connection-row {
  display: grid;
  gap: var(--space-2);
}

.action-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-2);
}

.action-btn {
  min-height: 42px;
  border-color: transparent;
  color: #ffffff;
  background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 94%, #ffffff), color-mix(in srgb, var(--accent-2) 92%, #ffffff));
}

.toolbar-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  padding: 4px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--surface-2);
}

.toolbar-row .ghost-btn {
  min-height: 36px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  box-shadow: none;
  font-size: 12px;
}

.toolbar-row .ghost-btn.is-active {
  border: 1px solid color-mix(in srgb, var(--accent) 38%, var(--border));
  background: color-mix(in srgb, var(--accent-soft) 70%, var(--surface-2));
  color: color-mix(in srgb, var(--accent) 86%, var(--text-main));
}

.settings-grid,
.doc-tools-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-2);
}

.floating-field {
  display: grid;
  gap: 6px;
}

.floating-field span {
  font-size: 11px;
  color: var(--text-muted);
}

.floating-field input,
.floating-field select {
  min-height: 38px;
  padding: 0 10px;
}

.floating-field input[type="number"] {
  appearance: textfield;
}

.floating-field input[type="color"] {
  padding: 4px;
  min-height: 38px;
}

.floating-field textarea {
  min-height: 66px;
  max-height: 120px;
  resize: vertical;
  padding: 10px;
}

.compact-btn {
  min-height: 38px;
}

.chip-row {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.chip-toggle {
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.chip-toggle input {
  margin: 0;
}

.image-row {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr);
  gap: var(--space-2);
  align-items: stretch;
}

.image-preview {
  width: 56px;
  height: 56px;
  border-radius: 12px;
  border: 1px dashed var(--border);
  background: var(--surface-2);
  display: grid;
  place-items: center;
  overflow: hidden;
}

.image-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: none;
}

.image-preview img.has-image {
  display: block;
}

.image-preview span {
  color: var(--text-soft);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.image-controls {
  min-width: 0;
  display: grid;
  gap: 6px;
}

.image-btn-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.image-btn-row .ghost-btn {
  min-height: 34px;
  font-size: 12px;
}

.image-file-name {
  color: var(--text-muted);
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.drawer-chip-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.drawer-chip {
  min-height: 34px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 600;
  padding: 0 8px;
}

.hidden-file-input {
  position: absolute;
  width: 0;
  height: 0;
  opacity: 0;
  pointer-events: none;
}

.hidden {
  display: none !important;
}

button:disabled,
select:disabled,
textarea:disabled,
input:disabled {
  opacity: 0.58;
  cursor: not-allowed;
}

button:focus-visible,
textarea:focus-visible,
select:focus-visible,
input:focus-visible {
  outline: none;
  border-color: transparent;
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.chat-history::-webkit-scrollbar,
.app-drawer::-webkit-scrollbar {
  width: 8px;
}

.chat-history::-webkit-scrollbar-thumb,
.app-drawer::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: color-mix(in srgb, var(--text-soft) 42%, transparent);
}

@media (max-width: 420px) {
  .app-shell {
    padding: 10px;
    gap: 10px;
  }

  .topbar {
    padding: 8px 10px;
  }

  .brand-copy h1 {
    font-size: 16px;
  }

  .settings-grid,
  .doc-tools-grid,
  .drawer-chip-grid,
  .action-grid {
    grid-template-columns: 1fr;
  }

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

  .image-row {
    grid-template-columns: 52px minmax(0, 1fr);
  }
}

@media (max-height: 760px) {
  .app-shell {
    gap: var(--space-2);
  }

  .chat-panel,
  .composer-panel,
  .surface-card {
    padding: var(--space-2);
  }

  .input-wrap textarea {
    min-height: 94px;
  }
}