:root {
  --bg-pure: #000000;
  --bg-sidebar: #0b0b0d;
  --bg-surface: #141417;
  --bg-surface-hover: #1c1c21;
  --bg-pill: #1f1f24;
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text-primary: #f4f4f5;
  --text-secondary: #a1a1aa;
  --text-muted: #71717a;
  --accent: #ffffff;
  --accent-text: #000000;
  --status-ok: #22c55e;
  --status-standby: #f59e0b;
  --sidebar-width: 268px;
  --radius-lg: 24px;
  --radius-md: 14px;
  --transition: 220ms cubic-bezier(0.22, 1, 0.36, 1);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background-color: var(--bg-pure);
  color: var(--text-primary);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button,
textarea {
  font-family: inherit;
  color: inherit;
}

.app-shell {
  display: flex;
  height: 100dvh;
  width: 100%;
  background-color: var(--bg-pure);
  position: relative;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  height: 100%;
  background-color: var(--bg-sidebar);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  padding: 14px 12px;
  transition: width var(--transition), min-width var(--transition), padding var(--transition), opacity var(--transition), transform var(--transition);
  z-index: 30;
  overflow: hidden;
}

.app-shell.sidebar-collapsed .sidebar {
  width: 0;
  min-width: 0;
  padding-left: 0;
  padding-right: 0;
  border-right-color: transparent;
  opacity: 0;
  pointer-events: none;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 4px 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
}

.brand-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background-color: #18181b;
  border: 1px solid var(--border-strong);
  color: var(--text-primary);
}

.brand-name {
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background-color 150ms ease, color 150ms ease;
}

.icon-btn:hover {
  background-color: var(--bg-surface-hover);
  color: var(--text-primary);
}

.sidebar-actions {
  margin-bottom: 12px;
}

.new-chat-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
  background-color: var(--bg-surface);
  color: var(--text-primary);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 150ms ease, border-color 150ms ease;
}

.new-chat-btn:hover {
  background-color: var(--bg-surface-hover);
  border-color: var(--border-strong);
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin-bottom: 16px;
}

.nav-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 10px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.86rem;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  white-space: nowrap;
  transition: background-color 150ms ease, color 150ms ease;
}

.nav-item:hover {
  background-color: var(--bg-surface);
  color: var(--text-primary);
}

.nav-item.active {
  background-color: var(--bg-surface-hover);
  color: var(--text-primary);
}

.nav-badge {
  margin-left: auto;
  font-size: 0.68rem;
  padding: 2px 7px;
  border-radius: 999px;
  background-color: #18181b;
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
}

.sidebar-section-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  padding: 6px 12px;
  white-space: nowrap;
}

.recent-list {
  list-style: none;
  margin: 0;
  padding: 0;
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.recent-list::-webkit-scrollbar {
  width: 4px;
}

.recent-list::-webkit-scrollbar-thumb {
  background: #27272a;
  border-radius: 4px;
}

.recent-item {
  width: 100%;
  padding: 8px 12px;
  border-radius: 9px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.82rem;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  transition: background-color 150ms ease, color 150ms ease;
}

.recent-item:hover {
  background-color: var(--bg-surface);
  color: var(--text-primary);
}

.sidebar-footer {
  padding-top: 10px;
  border-top: 1px solid var(--border-subtle);
}

.user-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 12px;
  cursor: pointer;
  transition: background-color 150ms ease;
}

.user-card:hover {
  background-color: var(--bg-surface);
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background-color: #27272a;
  border: 1px solid var(--border-strong);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 600;
  flex-shrink: 0;
}

.user-meta {
  min-width: 0;
  flex: 1;
}

.user-name {
  font-size: 0.84rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-sub {
  font-size: 0.72rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--status-ok);
  flex-shrink: 0;
}

/* Main Workspace */
.main-content {
  flex: 1;
  min-width: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  background-color: var(--bg-pure);
}

.topbar {
  height: 60px;
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.open-sidebar-btn {
  display: none;
}

.app-shell.sidebar-collapsed .open-sidebar-btn {
  display: inline-flex;
}

.topbar-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar-brand {
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.03em;
}

.topbar-pill {
  font-size: 0.74rem;
  color: var(--text-secondary);
  padding: 3px 10px;
  border-radius: 999px;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.mqtt-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 0.76rem;
  color: var(--text-secondary);
  padding: 6px 12px;
  border-radius: 999px;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
}

.mqtt-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background-color: var(--status-standby);
}

.auth-btn {
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background-color: var(--bg-surface);
  color: var(--text-primary);
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 150ms ease;
}

.auth-btn:hover {
  background-color: var(--bg-surface-hover);
}

/* Center Hero */
.hero-stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  overflow-y: auto;
}

.hero-container {
  width: 100%;
  max-width: 720px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  margin-top: -32px;
}

.hero-title {
  margin: 0 0 10px;
  font-size: clamp(1.75rem, 3.6vw, 2.4rem);
  font-weight: 500;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.hero-subtitle {
  margin: 0 0 28px;
  font-size: 0.92rem;
  color: var(--text-secondary);
  max-width: 540px;
  line-height: 1.5;
}

/* Composer */
.composer-box {
  width: 100%;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 14px 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: border-color 150ms ease;
}

.composer-box:focus-within {
  border-color: var(--border-strong);
}

.composer-textarea {
  width: 100%;
  background: transparent;
  border: none;
  outline: none;
  resize: none;
  font-size: 0.98rem;
  line-height: 1.5;
  color: var(--text-primary);
  max-height: 160px;
  padding: 2px 4px;
}

.composer-textarea::placeholder {
  color: var(--text-muted);
}

.composer-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.composer-left,
.composer-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.tool-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background-color 150ms ease, color 150ms ease;
}

.tool-btn:hover {
  background-color: var(--bg-surface-hover);
  color: var(--text-primary);
}

.model-dropdown-wrap {
  position: relative;
}

.model-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 150ms ease, color 150ms ease;
}

.model-btn:hover {
  background-color: var(--bg-surface-hover);
  color: var(--text-primary);
}

.model-menu {
  position: absolute;
  right: 0;
  bottom: calc(100% + 8px);
  width: 220px;
  background-color: #141417;
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.75);
  z-index: 40;
}

.model-menu[hidden] {
  display: none;
}

.model-option {
  width: 100%;
  padding: 9px 10px;
  border-radius: 9px;
  border: none;
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  cursor: pointer;
  text-align: left;
  transition: background-color 150ms ease;
}

.model-option:hover,
.model-option.active {
  background-color: var(--bg-surface-hover);
}

.model-option-name {
  font-size: 0.84rem;
  font-weight: 500;
  color: var(--text-primary);
}

.model-option-tag {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.send-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background-color: var(--accent);
  color: var(--accent-text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 120ms ease, opacity 150ms ease;
}

.send-btn:hover {
  opacity: 0.9;
  transform: scale(1.03);
}

/* Mode Pills */
.mode-pills {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 18px;
  flex-wrap: wrap;
  justify-content: center;
}

.mode-pill {
  padding: 7px 16px;
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
  background-color: transparent;
  color: var(--text-secondary);
  font-size: 0.84rem;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 150ms ease, color 150ms ease, border-color 150ms ease;
}

.mode-pill:hover {
  color: var(--text-primary);
  background-color: var(--bg-surface);
}

.mode-pill.active {
  background-color: var(--bg-pill);
  border-color: var(--border-strong);
  color: var(--text-primary);
}

/* Quick Chips */
.quick-chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 22px;
}

.chip-btn {
  padding: 7px 13px;
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
  background-color: #09090b;
  color: var(--text-secondary);
  font-size: 0.78rem;
  cursor: pointer;
  transition: border-color 150ms ease, color 150ms ease, background-color 150ms ease;
}

.chip-btn:hover {
  border-color: var(--border-strong);
  background-color: var(--bg-surface);
  color: var(--text-primary);
}

.main-footer {
  padding: 12px 20px;
  text-align: center;
  font-size: 0.74rem;
  color: var(--text-muted);
  flex-shrink: 0;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background-color: #18181b;
  color: var(--text-primary);
  border: 1px solid var(--border-strong);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.82rem;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.8);
  z-index: 60;
}

.toast[hidden] {
  display: none;
}

/* Mobile Drawer */
.sidebar-backdrop {
  display: none;
}

@media (max-width: 820px) {
  .topbar-pill,
  .mqtt-pill {
    display: none;
  }

  .open-sidebar-btn {
    display: inline-flex;
  }

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    transform: translateX(-100%);
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
  }

  .app-shell.sidebar-open-mobile .sidebar {
    transform: translateX(0);
  }

  .app-shell.sidebar-open-mobile .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.68);
    z-index: 25;
  }

  .app-shell.sidebar-collapsed .sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    padding: 14px 12px;
    opacity: 1;
    pointer-events: auto;
  }
}
