:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #17202a;
  --muted: #667085;
  --line: #d9dee7;
  --primary: #1565c0;
  --primary-dark: #0f4f97;
  --accent: #2e7d32;
  --danger: #b42318;
  --shadow: 0 12px 28px rgba(16, 24, 40, 0.08);
}

body.dark {
  color-scheme: dark;
  --bg: #111418;
  --panel: #1b2027;
  --text: #eef2f6;
  --muted: #aab4c0;
  --line: #303947;
  --primary: #64a7ff;
  --primary-dark: #3a83dc;
  --accent: #74c69d;
  --danger: #ff8a80;
  --shadow: 0 12px 28px rgba(0, 0, 0, 0.25);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

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

button, .primary-link {
  min-height: 40px;
  border: 0;
  border-radius: 8px;
  padding: 0 14px;
  cursor: pointer;
}

.primary-button, .primary-link {
  background: var(--primary);
  color: white;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.primary-button:hover, .primary-link:hover { background: var(--primary-dark); }

.secondary-button, .ghost-button, .actions button {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--line);
}

.welcome {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.welcome-panel {
  width: min(780px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: clamp(28px, 5vw, 56px);
  box-shadow: var(--shadow);
}

.welcome h1 {
  margin: 0 0 14px;
  font-size: clamp(2rem, 6vw, 4.4rem);
  line-height: 1;
}

.welcome p {
  color: var(--muted);
  max-width: 680px;
}

.eyebrow {
  margin: 0 0 10px;
  text-transform: uppercase;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 800;
}

.app-shell {
  display: grid;
  grid-template-columns: 290px 1fr;
  min-height: 100vh;
}

.sidebar {
  border-right: 1px solid var(--line);
  background: var(--panel);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.sidebar h1, .toolbar h2 {
  margin: 0;
}

.dashboard {
  padding: 24px;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.toolbar p, .notice, .muted {
  color: var(--muted);
}

.status-pill {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
  min-width: 92px;
  text-align: center;
  color: var(--muted);
}

.grid {
  display: grid;
  grid-template-columns: minmax(280px, 0.85fr) minmax(340px, 1.35fr);
  gap: 18px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  box-shadow: var(--shadow);
}

.panel-title {
  font-weight: 800;
  margin-bottom: 12px;
}

.panel-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.panel-row.compact {
  justify-content: flex-start;
  flex-wrap: wrap;
  margin-top: 12px;
}

.drop-zone {
  border: 1px dashed var(--line);
  border-radius: 8px;
  min-height: 126px;
  display: grid;
  place-items: center;
  text-align: center;
  cursor: pointer;
  color: var(--muted);
  padding: 16px;
}

.drop-zone input {
  display: none;
}

.preview {
  width: 100%;
  max-height: 260px;
  object-fit: contain;
  margin: 14px 0;
  border-radius: 8px;
  border: 1px solid var(--line);
  display: none;
}

textarea {
  width: 100%;
  min-height: 330px;
  resize: vertical;
  border-radius: 8px;
  border: 1px solid var(--line);
  padding: 12px;
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

select, input[type="text"] {
  min-height: 40px;
  border-radius: 8px;
  border: 1px solid var(--line);
  padding: 0 12px;
  color: var(--text);
  background: var(--bg);
}

.ai-output {
  white-space: pre-wrap;
  min-height: 300px;
  margin: 0;
  color: var(--text);
  line-height: 1.55;
}

.chat-history {
  min-height: 242px;
  max-height: 380px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.message {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  line-height: 1.45;
  white-space: pre-wrap;
}

.message.user {
  align-self: flex-end;
  max-width: 86%;
  border-color: var(--primary);
}

.message.assistant {
  align-self: flex-start;
  max-width: 92%;
}

.chat-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  margin-top: 14px;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-item {
  text-align: left;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  border-radius: 8px;
  padding: 10px;
}

.error { color: var(--danger); }

@media (max-width: 960px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

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

@media (max-width: 640px) {
  .dashboard, .sidebar {
    padding: 16px;
  }

  .toolbar, .panel-row {
    align-items: flex-start;
    flex-direction: column;
  }

  .chat-form {
    grid-template-columns: 1fr;
  }
}
