:root {
  color-scheme: light;
  --ink: #17181d;
  --muted: #656b75;
  --line: #d9dde3;
  --paper: #f8f7f3;
  --panel: #ffffff;
  --teal: #0f766e;
  --teal-soft: #d9f2ee;
  --wine: #8c1f3f;
  --amber: #b78321;
  --steel: #334155;
  --shadow: 0 18px 48px rgba(23, 24, 29, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

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

.rail {
  position: sticky;
  top: 0;
  height: 100vh;
  border-right: 1px solid var(--line);
  background: #111217;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 14px 10px;
  gap: 28px;
}

.brand {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
}

.brand img {
  width: 44px;
  height: 44px;
}

.rail-nav {
  display: grid;
  gap: 12px;
}

.icon-button,
.quiet-button,
.send-button {
  border: 0;
  cursor: pointer;
  display: grid;
  place-items: center;
}

.icon-button {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  color: #cbd5e1;
  background: transparent;
}

.icon-button:hover,
.icon-button.active {
  background: #252832;
  color: #ffffff;
}

svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.workspace {
  min-width: 0;
  padding: 28px;
}

.topbar {
  min-height: 72px;
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
  margin-bottom: 22px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--teal);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(28px, 5vw, 44px);
  line-height: 1.05;
}

h2 {
  margin-bottom: 0;
  font-size: 22px;
  line-height: 1.2;
}

h3 {
  margin-bottom: 8px;
  font-size: 16px;
  line-height: 1.25;
}

.status-stack {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 36px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--steel);
  font-size: 14px;
  white-space: nowrap;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--teal);
  box-shadow: 0 0 0 4px var(--teal-soft);
}

.status-dot.offline {
  background: var(--amber);
  box-shadow: 0 0 0 4px rgba(183, 131, 33, 0.18);
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.desk-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 18px;
  align-items: start;
}

.conversation-panel,
.context-panel,
.mini-panel,
.tile,
.channel-row,
.toggle-row {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.conversation-panel {
  min-height: 620px;
  display: grid;
  grid-template-rows: auto minmax(340px, 1fr) auto;
  box-shadow: var(--shadow);
}

.panel-head,
.section-head {
  padding: 20px;
  border-bottom: 1px solid var(--line);
}

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

.panel-actions {
  display: inline-flex;
  gap: 8px;
}

.quiet-button {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background: var(--teal-soft);
  color: var(--teal);
  text-decoration: none;
}

.auth-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 420px);
  gap: 16px;
  align-items: end;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  background: #f7fbfa;
}

.auth-panel[hidden] {
  display: none;
}

.auth-panel p {
  margin-bottom: 0;
  color: var(--muted);
}

.auth-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 10px;
  align-items: center;
}

.auth-form input[type="password"] {
  min-width: 0;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  outline: none;
}

.auth-form input[type="password"]:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px var(--teal-soft);
}

.remember-row {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--steel);
  font-size: 13px;
  white-space: nowrap;
}

.auth-button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  background: var(--teal);
  color: #fff;
  cursor: pointer;
  font-weight: 800;
  padding: 0 14px;
}

.message-list {
  display: grid;
  align-content: start;
  gap: 14px;
  padding: 20px;
  overflow: auto;
}

.message {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr);
  gap: 12px;
  max-width: 760px;
}

.message p:last-child {
  margin-bottom: 0;
}

.message-meta {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 4px;
}

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: var(--wine);
  color: #fff;
  font-weight: 800;
}

.avatar.dark {
  background: var(--steel);
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 46px;
  gap: 10px;
  padding: 16px;
  border-top: 1px solid var(--line);
}

.composer input {
  min-width: 0;
  height: 46px;
  border-radius: 8px;
  border: 1px solid var(--line);
  padding: 0 14px;
  outline: none;
}

.composer input:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px var(--teal-soft);
}

.composer input:disabled {
  background: #f3f4f6;
  color: var(--muted);
  cursor: not-allowed;
}

.send-button {
  width: 46px;
  height: 46px;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
}

.context-panel {
  display: grid;
  gap: 14px;
  padding: 14px;
  background: #f1f3f5;
}

.mini-panel {
  padding: 16px;
}

.mini-panel.accent {
  border-color: rgba(140, 31, 63, 0.3);
  background: #fff4f6;
}

.mini-panel p:last-child {
  margin-bottom: 0;
}

.metric-row,
.link-row {
  min-height: 36px;
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
  border-top: 1px solid var(--line);
  padding-top: 10px;
  margin-top: 10px;
}

.metric-row span {
  color: var(--muted);
}

.link-row {
  color: var(--ink);
  text-decoration: none;
  font-weight: 700;
}

.primary-link {
  min-height: 42px;
  margin-top: 14px;
  padding: 0 14px;
  border-radius: 8px;
  background: #111217;
  color: #fff;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  font-weight: 800;
}

.primary-link svg {
  width: 18px;
  height: 18px;
}

.tile-grid,
.settings-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  padding: 20px;
}

.tile {
  min-height: 160px;
  padding: 18px;
}

.tile.locked {
  background: #f3f4f6;
  color: var(--steel);
}

.channel-list {
  display: grid;
  gap: 12px;
  padding: 20px;
}

.channel-row {
  min-height: 86px;
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  padding: 14px;
}

.channel-row p {
  margin-bottom: 0;
  color: var(--muted);
}

.channel-icon {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: var(--amber);
  color: #fff;
  font-weight: 800;
}

.channel-icon.telegram {
  background: #2481cc;
}

.channel-icon.gateway {
  background: var(--wine);
}

.toggle-row {
  min-height: 64px;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 16px;
}

.toggle-row input {
  width: 46px;
  height: 26px;
  accent-color: var(--teal);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

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

  .rail {
    position: fixed;
    inset: auto 12px 12px;
    z-index: 10;
    height: 64px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 16px;
    flex-direction: row;
    justify-content: space-between;
    padding: 10px;
    box-shadow: var(--shadow);
  }

  .brand {
    display: none;
  }

  .rail-nav {
    width: 100%;
    grid-template-columns: repeat(4, 1fr);
  }

  .icon-button {
    width: 100%;
  }

  .workspace {
    padding: 20px 16px 96px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .desk-grid,
  .tile-grid,
  .settings-grid,
  .auth-panel {
    grid-template-columns: 1fr;
  }

  .auth-form {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .conversation-panel {
    min-height: 560px;
  }
}

@media (max-width: 520px) {
  h1 {
    font-size: 30px;
  }

  .status-stack {
    width: 100%;
    justify-content: center;
  }

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

  .channel-row strong {
    grid-column: 2;
  }
}
