:root {
  color-scheme: light;
  --bg: #f6f7fb;
  --panel: #ffffff;
  --border: #d9deea;
  --text: #1f2430;
  --muted: #606880;
  --accent: #2d6cdf;
  --danger: #c0392b;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.07);
  --radius: 12px;
  --message-bg: #ffffff;
  --message-border: #e5e9f3;
  --timestamp: #6b7285;
}

.theme-dark {
  color-scheme: dark;
  --bg: #0f1624;
  --panel: #161f2f;
  --border: #273249;
  --text: #f2f5ff;
  --muted: #a6b0c5;
  --accent: #7db0ff;
  --danger: #e17055;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --message-bg: #1a2333;
  --message-border: #2d3a54;
  --timestamp: #9aa5c0;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", "SF Pro Display", -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
  background: radial-gradient(900px circle at 20% 10%, rgba(45, 108, 223, 0.05), transparent),
              radial-gradient(1100px circle at 80% 0%, rgba(125, 176, 255, 0.07), transparent),
              var(--bg);
  color: var(--text);
  min-height: 100vh;
}

#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 10;
}

.top-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.workspace-title {
  font-weight: 700;
  letter-spacing: 0.3px;
}

.workspace-path {
  font-size: 13px;
  color: var(--muted);
}

.top-actions {
  display: flex;
  gap: 10px;
}

.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  transition: transform 120ms ease, box-shadow 120ms ease, border-color 120ms ease, background 120ms ease;
}

.btn.primary {
  background: linear-gradient(120deg, var(--accent), #6bb8ff);
  color: #fff;
  border-color: transparent;
  box-shadow: 0 8px 20px rgba(45, 108, 223, 0.25);
}

.btn.danger {
  background: var(--danger);
  color: #fff;
  border-color: transparent;
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.layout {
  display: grid;
  grid-template-rows: 1fr auto;
  height: calc(100vh - 70px);
}

.timeline {
  overflow-y: auto;
  padding: 16px 20px 0 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.message {
  background: var(--message-bg);
  border: 1px solid var(--message-border);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: var(--shadow);
}

.message.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(45, 108, 223, 0.25), var(--shadow);
}

.message-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.timestamp {
  font-size: 12px;
  color: var(--timestamp);
}

.edited {
  font-size: 11px;
  color: var(--muted);
  margin-left: 6px;
}

.message-actions {
  display: flex;
  gap: 6px;
}

.message-content {
  font-size: 15px;
  line-height: 1.55;
}

.message-content a {
  color: var(--accent);
  text-decoration: none;
}

.message-content a:hover {
  text-decoration: underline;
}

.attachments {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.attachments img {
  max-width: 320px;
  max-height: 240px;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.composer {
  border-top: 1px solid var(--border);
  background: var(--panel);
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.composer-area {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  min-height: 90px;
  background: var(--message-bg);
  box-shadow: inset 0 1px 4px rgba(0, 0, 0, 0.08);
}

.composer-area[contenteditable="true"]:focus {
  outline: 2px solid var(--accent);
}

.composer-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.status-line {
  font-size: 13px;
  color: var(--muted);
  min-height: 18px;
}

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

.settings-panel {
  position: fixed;
  right: 16px;
  top: 84px;
  width: 320px;
  max-width: calc(100% - 32px);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  display: none;
  flex-direction: column;
  gap: 10px;
  z-index: 20;
}

.settings-panel.open {
  display: flex;
}

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

.settings-row input[type="number"] {
  width: 80px;
}

.diagnostics {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  background: var(--message-bg);
  min-height: 60px;
  max-height: 160px;
  overflow-y: auto;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 12px;
  white-space: pre-wrap;
}

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 40px 0;
}

.welcome {
  margin: auto;
  padding: 40px;
  max-width: 520px;
  background: var(--panel);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  text-align: center;
}

.welcome h1 {
  margin-top: 0;
  margin-bottom: 12px;
}

.welcome p {
  color: var(--muted);
}

@media (max-width: 720px) {
  .top-bar {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }

  .top-actions {
    width: 100%;
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .attachments img {
    max-width: 100%;
  }
}
