:root {
  --bg: #f4f1ea;
  --surface: #fffdf8;
  --surface-soft: #f9f4ec;
  --line: rgba(76, 57, 35, 0.12);
  --text: #20170f;
  --muted: #756456;
  --accent: #0f766e;
  --accent-soft: #d8efec;
  --danger: #9d2b2b;
  --danger-soft: #f6e2de;
  --shadow: 0 24px 56px rgba(44, 31, 22, 0.1);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  background:
    radial-gradient(circle at top left, rgba(15, 118, 110, 0.12), transparent 28%),
    radial-gradient(circle at bottom right, rgba(197, 147, 88, 0.16), transparent 24%),
    var(--bg);
  color: var(--text);
  font-family: "Space Grotesk", sans-serif;
}
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.shell {
  min-height: 100vh;
  height: 100vh;
}

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

.login-card,
.sidebar,
.topbar,
.sidebar-card,
.conversation-card,
.empty-state,
.info-card,
.panel-card {
  background: rgba(255, 253, 248, 0.94);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

.login-card {
  width: min(520px, 100%);
  border-radius: 28px;
  padding: 36px;
}

.login-card h1 {
  margin: 0;
  font-size: clamp(36px, 5vw, 56px);
  line-height: 1;
  letter-spacing: 0.08em;
}

.eyebrow {
  margin: 0 0 8px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 12px;
  color: var(--muted);
}

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

.login-form {
  display: grid;
  gap: 16px;
  margin-top: 24px;
}

.login-form label {
  display: grid;
  gap: 8px;
}

input, textarea, select {
  width: 100%;
  padding: 14px 16px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.82);
  color: var(--text);
  resize: vertical;
}

input:focus, textarea:focus, select:focus {
  outline: 2px solid rgba(15, 118, 110, 0.24);
  border-color: rgba(15, 118, 110, 0.35);
}

button {
  border: 0;
  border-radius: 16px;
  padding: 14px 18px;
  background: var(--accent);
  color: #f9fffe;
  font-weight: 700;
}

.ghost-button {
  background: rgba(255, 255, 255, 0.82);
  color: var(--text);
  border: 1px solid var(--line);
}

.danger { background: var(--danger); color: #fff; }
.danger-soft { background: var(--danger-soft); color: var(--danger); }
.form-error { min-height: 20px; margin: 0; color: var(--danger); font-size: 14px; }

.app {
  min-height: 100vh;
  height: 100vh;
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
}

.sidebar {
  border-radius: 0 28px 28px 0;
  padding: 20px 16px;
  border-left: 0;
  min-height: 100vh;
  height: 100vh;
  overflow: auto;
}

.brand h2 {
  margin: 0;
  font-size: 28px;
}

.nav {
  display: grid;
  gap: 8px;
  margin-top: 24px;
}

.nav-item {
  text-align: left;
  background: transparent;
  color: var(--text);
  border: 1px solid transparent;
}

.nav-item.active {
  background: var(--accent);
  color: #fff;
}

.main {
  padding: 18px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 16px;
  min-height: 100vh;
  height: 100vh;
  overflow: hidden;
}

.topbar {
  border-radius: 28px;
  padding: 16px 18px;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
}

.topbar h1 { margin: 0; font-size: 34px; }
.topbar-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.mobile-nav {
  display: none;
}

.pill,
.badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.82);
  font-size: 13px;
}

.page { display: none; min-height: 0; height: 100%; overflow: auto; }
.page.active { display: block; }
.page[data-page="inbox"] {
  overflow: hidden;
}

.page[data-page="inbox"].active {
  display: flex;
  flex-direction: column;
}

.stats-grid,
.cards-grid {
  display: grid;
  gap: 16px;
}

.stats-grid {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  margin-bottom: 16px;
}

.stat-card,
.info-card,
.panel-card {
  border-radius: 24px;
  padding: 18px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.stat-card strong {
  display: block;
  font-size: 34px;
  margin-top: 4px;
}

.cards-grid {
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

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

.panel-head-stack {
  align-items: flex-start;
}

.workspace {
  display: grid;
  grid-template-columns: 310px minmax(0, 1fr);
  gap: 16px;
  flex: 1;
  height: calc(100vh - 156px);
  max-height: calc(100vh - 156px);
  min-height: 0;
  align-items: stretch;
}

.conversation {
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  display: grid;
}

.sidebar-card,
.conversation-card,
.empty-state {
  border-radius: 26px;
  min-height: 0;
}

.sidebar-card {
  padding: 14px;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  min-height: 0;
  height: 100%;
}

.sidebar-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.chat-list {
  margin-top: 12px;
  display: grid;
  gap: 8px;
  overflow: auto;
  min-height: 0;
  scrollbar-gutter: stable;
}

.chat-item {
  text-align: left;
  border: 1px solid #0c6a60;
  background: linear-gradient(135deg, #11857a, #0c6a60);
  color: #fff;
  border-radius: 16px;
  padding: 12px;
}

.chat-item.active {
  background: linear-gradient(135deg, #0c6a60, #094e48);
  box-shadow: inset 4px 0 0 rgba(255,255,255,.94);
}

.chat-item-row,
.chat-item-side {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.chat-item-side {
  flex-direction: column;
  align-items: flex-end;
}

.chat-preview { font-size: 12px; color: rgba(255,255,255,.84); }
.chat-time { font-size: 11px; color: rgba(255,255,255,.92); }

.empty-state {
  display: grid;
  place-items: center;
  text-align: center;
  padding: 40px;
  height: 100%;
}

.conversation-card {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  height: 100%;
  max-height: 100%;
  overflow: hidden;
}

.conversation-head,
.composer {
  padding: 16px;
}

.conversation-head {
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.conversation-head-main {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.conversation-head h3 {
  margin: 0;
  font-size: 28px;
}

.control-row,
.badges,
.composer-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.message-stream {
  overflow: auto;
  padding: 16px;
  display: grid;
  gap: 14px;
  height: 100%;
  max-height: 100%;
  min-height: 0;
  scrollbar-gutter: stable;
  background:
    linear-gradient(180deg, rgba(255,255,255,.2), rgba(255,255,255,.04)),
    rgba(255,255,255,.42);
}

.chat-list::-webkit-scrollbar,
.message-stream::-webkit-scrollbar,
.channel-form-card::-webkit-scrollbar,
.page::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

.chat-list::-webkit-scrollbar-thumb,
.message-stream::-webkit-scrollbar-thumb,
.channel-form-card::-webkit-scrollbar-thumb,
.page::-webkit-scrollbar-thumb {
  background: rgba(117, 100, 86, 0.35);
  border-radius: 999px;
}

.chat-list::-webkit-scrollbar-track,
.message-stream::-webkit-scrollbar-track,
.channel-form-card::-webkit-scrollbar-track,
.page::-webkit-scrollbar-track {
  background: rgba(117, 100, 86, 0.08);
  border-radius: 999px;
}

.message {
  max-width: min(700px, 84%);
  display: grid;
  gap: 6px;
}

.message.assistant { margin-left: auto; }

.message-bubble {
  padding: 14px 16px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: #ffffff;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.message.assistant .message-bubble { background: #def0eb; }
.message img { max-width: min(320px, 100%); border-radius: 14px; display: block; }
.message-time { font-size: 12px; color: var(--muted); }

.composer {
  border-top: 1px solid var(--line);
  display: grid;
  gap: 10px;
}

.contacts-list,
.settings-list,
.channel-list,
.assistant-list {
  display: grid;
  gap: 10px;
}

.contact-row,
.settings-row,
.channel-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,.66);
}

.contact-row {
  align-items: center;
}

.channel-layout {
  display: grid;
  grid-template-columns: minmax(360px, 430px) minmax(0, 1fr);
  gap: 16px;
  height: 100%;
}

.assistant-layout {
  display: grid;
  grid-template-columns: minmax(320px, 380px) minmax(0, 1fr);
  gap: 16px;
  height: 100%;
}

.channel-form-card {
  overflow: auto;
}

.assistant-editor-card {
  overflow: auto;
}

.settings-top-layout,
.settings-store-layout {
  margin-bottom: 16px;
}

.settings-download {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  display: grid;
  gap: 12px;
}

.assistant-form {
  display: grid;
  gap: 14px;
}

.assistant-form label {
  display: grid;
  gap: 8px;
}

.assistant-item {
  text-align: left;
  border: 1px solid var(--line);
  background: rgba(255,255,255,.76);
  color: var(--text);
  border-radius: 18px;
  padding: 14px;
  display: grid;
  gap: 10px;
}

.assistant-item.active {
  border-color: rgba(15, 118, 110, 0.4);
  box-shadow: inset 4px 0 0 rgba(15, 118, 110, 0.9);
  background: rgba(216, 239, 236, 0.55);
}

.assistant-item-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.assistant-preview {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.45;
}

.channel-form {
  display: grid;
  gap: 14px;
}

.channel-form label {
  display: grid;
  gap: 8px;
}

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

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

.external-link {
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.channel-row {
  align-items: flex-start;
}

.channel-row-meta {
  display: grid;
  gap: 6px;
}

.channel-number {
  font-size: 24px;
  font-weight: 700;
  line-height: 1.1;
}

.channel-row-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.channel-row.active-channel {
  border-color: rgba(15, 118, 110, 0.35);
  box-shadow: inset 0 0 0 1px rgba(15, 118, 110, 0.18);
}

.contact-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.small {
  font-size: 13px;
}

.placeholder-card {
  min-height: 320px;
  display: grid;
  align-content: start;
}

.download-card {
  display: grid;
  gap: 14px;
  align-content: start;
}

.download-meta,
.download-steps {
  display: grid;
  gap: 10px;
}

.inline-guide,
.advanced-box {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255,255,255,.58);
  padding: 14px 16px;
}

.inline-guide {
  display: grid;
  gap: 8px;
}

.inline-guide p {
  margin: 0;
  color: var(--muted);
}

.advanced-box summary {
  cursor: pointer;
  font-weight: 700;
}

.advanced-box-content {
  margin-top: 12px;
  display: grid;
  gap: 12px;
}

.empty-inline {
  padding: 18px;
  border: 1px dashed var(--line);
  border-radius: 16px;
  color: var(--muted);
  background: rgba(255,255,255,.4);
}

.mobile-back-button {
  display: none;
}

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

  .sidebar {
    min-height: auto;
    border-radius: 0 0 24px 24px;
  }

  .workspace {
    grid-template-columns: 1fr;
    height: auto;
    max-height: none;
    flex: initial;
  }

  .channel-layout {
    grid-template-columns: 1fr;
    height: auto;
  }

  .assistant-layout {
    grid-template-columns: 1fr;
    height: auto;
  }

  .page,
  .main,
  .app,
  .sidebar {
    height: auto;
    overflow: visible;
  }

  .conversation-card,
  .sidebar-card,
  .empty-state {
    height: auto;
    min-height: 360px;
  }

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

@media (max-width: 768px) {
  .shell,
  .app,
  .main {
    min-height: 100dvh;
    height: 100dvh;
  }

  .sidebar {
    display: none;
  }

  .main {
    padding: 10px;
    gap: 10px;
    overflow: hidden;
  }

  .topbar {
    border-radius: 22px;
    padding: 14px;
  }

  .topbar h1 {
    font-size: 28px;
  }

  .topbar-actions {
    gap: 8px;
  }

  .topbar-actions .pill {
    max-width: 110px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-nav {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 8px;
  }

  .mobile-nav-item {
    background: rgba(255, 255, 255, 0.82);
    color: var(--text);
    border: 1px solid var(--line);
    padding: 10px 8px;
    border-radius: 18px;
    display: grid;
    gap: 4px;
    justify-items: center;
    font-size: 11px;
    font-weight: 700;
  }

  .mobile-nav-item.active {
    background: var(--accent);
    color: #fff;
  }

  .mobile-nav-icon {
    font-size: 18px;
    line-height: 1;
  }

  .page {
    height: 100%;
    min-height: 0;
  }

  .page:not([data-page="inbox"]) {
    padding-bottom: 4px;
  }

  .workspace {
    display: block;
    height: 100%;
    max-height: 100%;
  }

  .sidebar-card {
    height: 100%;
    min-height: 0;
  }

  .conversation {
    display: none;
  }

  .page[data-page="inbox"].mobile-chat-open .sidebar-card {
    display: none;
  }

  .page[data-page="inbox"].mobile-chat-open .conversation {
    display: grid;
    position: fixed;
    inset: 0;
    z-index: 50;
    background:
      radial-gradient(circle at top left, rgba(15, 118, 110, 0.12), transparent 28%),
      radial-gradient(circle at bottom right, rgba(197, 147, 88, 0.16), transparent 24%),
      var(--bg);
    padding: 8px;
  }

  .page[data-page="inbox"].mobile-chat-open .conversation-card,
  .page[data-page="inbox"].mobile-chat-open .empty-state {
    display: grid !important;
    height: calc(100dvh - 16px);
    max-height: calc(100dvh - 16px);
    border-radius: 24px;
  }

  .conversation-head {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .conversation-head-main {
    align-items: flex-start;
  }

  .conversation-head h3 {
    font-size: 24px;
  }

  .mobile-back-button {
    display: inline-flex;
    flex: 0 0 auto;
  }

  .control-row {
    overflow: auto;
    flex-wrap: nowrap;
    padding-bottom: 2px;
  }

  .control-row .ghost-button,
  .control-row .danger,
  .control-row .danger-soft {
    white-space: nowrap;
  }

  .message {
    max-width: 92%;
  }

  .composer {
    gap: 8px;
  }

  .composer textarea {
    min-height: 84px;
  }

  .composer-actions {
    justify-content: space-between;
  }

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

  .contact-row,
  .channel-row,
  .settings-row {
    flex-direction: column;
    align-items: flex-start;
  }

  .contact-meta,
  .channel-row-actions {
    justify-content: flex-start;
  }
}
