:root {
  color-scheme: light;
  --brand: #0f6f5c;
  --brand-dark: #085446;
  --brand-soft: #e4f2ed;
  --ink: #17201d;
  --muted: #66706c;
  --line: #dfe4e1;
  --surface: #ffffff;
  --surface-soft: #f4f6f4;
  --page: #f8f9f7;
  --danger: #b42318;
  --danger-soft: #fff0ee;
  --warning: #a15c00;
  --shadow: 0 14px 40px rgba(24, 44, 37, 0.12);
  --radius: 18px;
  --sidebar-width: 304px;
  --content-width: 860px;
  font-family: Pretendard, "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic",
    system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 17px;
  line-height: 1.62;
}

* {
  box-sizing: border-box;
}

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

body {
  background: var(--page);
  color: var(--ink);
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

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

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

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

a {
  color: var(--brand-dark);
}

[hidden] {
  display: none !important;
}

:focus-visible {
  outline: 3px solid #58bfa4;
  outline-offset: 3px;
}

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

.skip-link {
  position: fixed;
  z-index: 200;
  top: 10px;
  left: 10px;
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--ink);
  color: #fff;
  transform: translateY(-150%);
  transition: transform 150ms ease;
}

.skip-link:focus {
  transform: translateY(0);
}

.offline-banner {
  position: fixed;
  z-index: 150;
  top: 0;
  left: 50%;
  width: min(100% - 24px, 680px);
  padding: 8px 16px;
  border-radius: 0 0 12px 12px;
  background: #7a4300;
  color: #fff;
  font-size: 0.86rem;
  font-weight: 700;
  text-align: center;
  transform: translateX(-50%);
  box-shadow: 0 5px 20px rgba(0, 0, 0, 0.18);
}

.button,
.icon-button,
.text-button,
.starter-card {
  border: 0;
  background: none;
}

.button {
  display: inline-flex;
  min-height: 46px;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 17px;
  border: 1px solid transparent;
  border-radius: 12px;
  font-weight: 750;
  line-height: 1.3;
  text-decoration: none;
  transition: background-color 150ms ease, border-color 150ms ease, transform 100ms ease;
}

.button:active {
  transform: translateY(1px);
}

.button--primary {
  background: var(--brand);
  color: #fff;
}

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

.button--secondary {
  border-color: var(--line);
  background: var(--surface);
  color: var(--ink);
}

.button--secondary:hover {
  border-color: #b7c2be;
  background: var(--surface-soft);
}

.button--danger {
  background: var(--danger);
  color: #fff;
}

.button--large {
  min-height: 54px;
  padding: 13px 20px;
  border-radius: 14px;
  font-size: 1.02rem;
}

.button--compact {
  min-height: 42px;
  padding: 8px 13px;
  font-size: 0.9rem;
}

.icon-button {
  display: inline-grid;
  width: 46px;
  height: 46px;
  place-items: center;
  border-radius: 12px;
  color: var(--ink);
  font-size: 1.45rem;
}

.icon-button:hover {
  background: var(--surface-soft);
}

.brand-lockup {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-size: 1.15rem;
  font-weight: 850;
  letter-spacing: -0.03em;
  text-decoration: none;
}

.brand-lockup--center {
  justify-content: center;
}

.brand-mark {
  display: inline-grid;
  width: 52px;
  height: 52px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 16px;
  background: var(--brand);
  color: #fff;
  font-size: 1.45rem;
  font-weight: 900;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.2);
}

.brand-mark--small {
  width: 39px;
  height: 39px;
  border-radius: 12px;
  font-size: 1.05rem;
}

.access-gate {
  display: grid;
  min-height: 100dvh;
  place-items: center;
  padding: calc(24px + env(safe-area-inset-top)) 24px calc(24px + env(safe-area-inset-bottom));
  background:
    radial-gradient(circle at 15% 15%, rgba(15, 111, 92, 0.11), transparent 34%),
    radial-gradient(circle at 85% 85%, rgba(218, 163, 73, 0.1), transparent 34%),
    var(--page);
}

.gate-card,
.admin-auth-card {
  width: min(100%, 500px);
  padding: clamp(28px, 6vw, 48px);
  border: 1px solid var(--line);
  border-radius: 26px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.gate-card .brand-lockup {
  margin-bottom: 34px;
}

.gate-state {
  text-align: center;
}

.gate-state h1,
.stack-form h1 {
  margin: 18px 0 7px;
  font-size: clamp(1.45rem, 5vw, 1.85rem);
  line-height: 1.3;
  letter-spacing: -0.04em;
}

.gate-state p,
.stack-form > p {
  margin: 0 0 24px;
  color: var(--muted);
}

.gate-illustration {
  display: block;
  font-size: 3rem;
  line-height: 1;
}

.spinner {
  display: none;
  width: 20px;
  height: 20px;
  border: 3px solid rgba(255, 255, 255, 0.42);
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}

.spinner--large {
  display: inline-block;
  width: 42px;
  height: 42px;
  border-color: var(--line);
  border-top-color: var(--brand);
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.stack-form {
  display: flex;
  flex-direction: column;
  text-align: left;
}

.stack-form .gate-illustration,
.stack-form h1,
.stack-form > p {
  text-align: center;
}

.stack-form label,
.inline-form label,
.settings-form label,
.invite-result label {
  margin: 13px 0 6px;
  font-size: 0.93rem;
  font-weight: 760;
}

input,
textarea {
  width: 100%;
  border: 1px solid #c9d1ce;
  border-radius: 12px;
  background: var(--surface);
}

input {
  min-height: 50px;
  padding: 10px 13px;
}

input:focus,
textarea:focus {
  border-color: var(--brand);
  outline: 3px solid rgba(15, 111, 92, 0.14);
}

.stack-form .button {
  margin-top: 20px;
}

.form-error {
  margin: 12px 0 0 !important;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--danger-soft);
  color: var(--danger) !important;
  font-size: 0.9rem;
  font-weight: 700;
}

.form-status {
  margin: 0;
  color: var(--brand-dark);
  font-weight: 700;
}

/* Chat shell */
.app-shell {
  min-height: 100dvh;
}

.sidebar {
  position: fixed;
  z-index: 50;
  inset: 0 auto 0 0;
  display: flex;
  width: var(--sidebar-width);
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: #f1f3f1;
}

.sidebar__header {
  display: flex;
  min-height: calc(70px + env(safe-area-inset-top));
  align-items: center;
  justify-content: space-between;
  padding: calc(12px + env(safe-area-inset-top)) 15px 8px 18px;
}

.sidebar__close {
  display: none;
}

.button--new {
  justify-content: flex-start;
  margin: 7px 14px 13px;
  border-color: #cad4d0;
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(15, 34, 28, 0.05);
}

.button--new:hover {
  border-color: #9dafaa;
  background: #fbfcfb;
}

.button--new > span {
  font-size: 1.25rem;
  font-weight: 400;
}

.conversation-nav {
  min-height: 0;
  flex: 1;
  overflow-y: auto;
  padding: 0 10px 12px;
}

.eyebrow {
  margin: 10px 8px 7px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.conversation-list {
  display: grid;
  gap: 3px;
}

.conversation-item {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 38px;
  align-items: center;
  border-radius: 11px;
}

.conversation-item:hover,
.conversation-item.is-active {
  background: #e2e7e4;
}

.conversation-item__open {
  min-width: 0;
  min-height: 48px;
  padding: 8px 7px 8px 11px;
  border: 0;
  background: transparent;
  text-align: left;
}

.conversation-item__open strong,
.conversation-item__open small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-item__open strong {
  font-size: 0.88rem;
}

.conversation-item__open small {
  color: var(--muted);
  font-size: 0.72rem;
}

.conversation-item__delete {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font-size: 1rem;
}

.conversation-item__delete:hover {
  background: var(--danger-soft);
  color: var(--danger);
}

.sidebar-empty {
  margin: 24px 14px;
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
}

.sidebar__footer {
  padding: 13px 17px calc(14px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
}

.sidebar__footer p {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.74rem;
  line-height: 1.5;
}

.text-button,
.admin-link {
  display: block;
  min-height: 40px;
  padding: 8px 2px;
  color: var(--muted);
  font-size: 0.78rem;
  text-align: left;
  text-decoration: none;
}

.text-button:hover,
.admin-link:hover {
  color: var(--ink);
  text-decoration: underline;
}

.text-button--danger:hover {
  color: var(--danger);
}

.chat-area {
  display: grid;
  min-height: 100dvh;
  margin-left: var(--sidebar-width);
  grid-template-rows: auto minmax(0, 1fr) auto;
  background: var(--surface);
  transition: margin-left 180ms ease;
}

.topbar {
  position: sticky;
  z-index: 20;
  top: 0;
  display: grid;
  min-height: calc(66px + env(safe-area-inset-top));
  align-items: center;
  grid-template-columns: 48px minmax(0, 1fr) auto;
  gap: 8px;
  padding: calc(8px + env(safe-area-inset-top)) 18px 8px;
  border-bottom: 1px solid rgba(223, 228, 225, 0.86);
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(16px);
}

.topbar__menu {
  display: none;
}

.topbar__title {
  min-width: 0;
  text-align: center;
}

.topbar__title strong,
.topbar__title span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar__title strong {
  font-size: 0.95rem;
}

.topbar__title span {
  color: var(--muted);
  font-size: 0.69rem;
}

.chat-main {
  min-height: 0;
  overflow-y: auto;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}

.empty-state {
  display: flex;
  width: min(100% - 32px, 800px);
  min-height: calc(100dvh - 240px);
  margin: 0 auto;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 0 28px;
  text-align: center;
}

.welcome-mark {
  display: grid;
  width: 60px;
  height: 60px;
  place-items: center;
  border-radius: 20px;
  background: var(--brand);
  color: #fff;
  font-size: 1.55rem;
  font-weight: 900;
  box-shadow: 0 10px 25px rgba(15, 111, 92, 0.22);
}

.empty-state h1 {
  margin: 21px 0 4px;
  font-size: clamp(1.7rem, 5vw, 2.25rem);
  line-height: 1.25;
  letter-spacing: -0.05em;
}

.empty-state > p {
  margin: 0 0 28px;
  color: var(--muted);
}

.starter-grid {
  display: grid;
  width: 100%;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.starter-card {
  display: flex;
  min-height: 86px;
  align-items: center;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  color: var(--ink);
  text-align: left;
  transition: border-color 150ms ease, background-color 150ms ease, transform 100ms ease;
}

.starter-card:hover {
  border-color: #9dafaa;
  background: #fbfcfb;
}

.starter-card:active {
  transform: translateY(1px);
}

.starter-card__icon {
  display: grid;
  width: 46px;
  height: 46px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 14px;
  background: var(--surface-soft);
  font-size: 1.3rem;
}

.starter-card strong,
.starter-card small {
  display: block;
}

.starter-card strong {
  font-size: 0.92rem;
}

.starter-card small {
  margin-top: 1px;
  color: var(--muted);
  font-size: 0.76rem;
}

.message-list {
  width: min(100%, calc(var(--content-width) + 40px));
  margin: 0 auto;
  padding: 22px 20px 14px;
}

.message {
  display: grid;
  margin: 0 0 27px;
  grid-template-columns: 38px minmax(0, 1fr);
  gap: 13px;
  animation: message-in 180ms ease-out;
}

@keyframes message-in {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}

.message--user {
  display: flex;
  justify-content: flex-end;
}

.message__avatar {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border-radius: 11px;
  background: var(--brand);
  color: #fff;
  font-size: 0.82rem;
  font-weight: 900;
}

.message__content {
  min-width: 0;
  padding-top: 2px;
}

.message__content > .message__label {
  display: block;
  margin-bottom: 7px;
  font-size: 0.75rem;
  font-weight: 800;
}

.message--user .message__content {
  max-width: min(84%, 680px);
  padding: 11px 16px;
  border-radius: 19px 19px 5px 19px;
  background: #e9eeeb;
}

.message__body {
  overflow-wrap: anywhere;
  font-size: 1rem;
}

.message__body p {
  margin: 0 0 0.62em;
}

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

.message__body h2,
.message__body h3 {
  margin: 1.1em 0 0.45em;
  line-height: 1.35;
  letter-spacing: -0.03em;
}

.message__body h2 {
  font-size: 1.14rem;
}

.message__body h3 {
  font-size: 1.03rem;
}

.message__body ul,
.message__body ol {
  margin: 0.45em 0 0.8em;
  padding-left: 1.45em;
}

.message__body li + li {
  margin-top: 0.25em;
}

.message__body blockquote {
  margin: 0.6em 0;
  padding: 7px 13px;
  border-left: 4px solid #96b9ad;
  background: var(--surface-soft);
  color: #41514b;
}

.message__body code {
  padding: 0.12em 0.35em;
  border-radius: 5px;
  background: #edf0ee;
  font-family: Consolas, "SFMono-Regular", monospace;
  font-size: 0.88em;
}

.message__body pre {
  max-width: 100%;
  overflow-x: auto;
  padding: 14px;
  border-radius: 12px;
  background: #19231f;
  color: #f3f7f5;
  white-space: pre;
}

.message__body pre code {
  padding: 0;
  background: transparent;
  color: inherit;
}

.message__body a {
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.message__actions {
  display: flex;
  min-height: 36px;
  align-items: center;
  gap: 4px;
  margin-top: 7px;
}

.message-action {
  display: inline-flex;
  min-height: 36px;
  align-items: center;
  gap: 5px;
  padding: 6px 9px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
}

.message-action:hover {
  background: var(--surface-soft);
  color: var(--ink);
}

.typing-indicator {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 28px;
}

.typing-indicator i {
  display: block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #789189;
  animation: typing 1.15s infinite ease-in-out;
}

.typing-indicator i:nth-child(2) { animation-delay: 140ms; }
.typing-indicator i:nth-child(3) { animation-delay: 280ms; }

@keyframes typing {
  0%, 60%, 100% { opacity: 0.35; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-4px); }
}

.streaming-cursor::after {
  content: "";
  display: inline-block;
  width: 2px;
  height: 1em;
  margin-left: 3px;
  vertical-align: -0.12em;
  background: var(--brand);
  animation: blink 850ms steps(1) infinite;
}

@keyframes blink {
  50% { opacity: 0; }
}

.image-result {
  width: min(100%, 620px);
  margin-top: 4px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 17px;
  background: var(--surface-soft);
}

.image-result img {
  display: block;
  width: 100%;
  height: auto;
  max-height: 650px;
  object-fit: contain;
}

.image-result__loading {
  display: grid;
  min-height: 290px;
  place-items: center;
  background:
    linear-gradient(100deg, #edf1ef 20%, #f8faf9 40%, #edf1ef 60%);
  background-size: 220% 100%;
  animation: shimmer 1.5s infinite linear;
}

.image-result__loading span {
  padding: 8px 12px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.88);
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 750;
}

@keyframes shimmer {
  to { background-position-x: -220%; }
}

.error-message {
  padding: 12px 14px;
  border: 1px solid #f1c8c2;
  border-radius: 12px;
  background: var(--danger-soft);
  color: #85251b;
}

.composer-wrap {
  position: sticky;
  z-index: 18;
  bottom: 0;
  padding: 10px 18px calc(9px + env(safe-area-inset-bottom));
  background: linear-gradient(to bottom, rgba(255, 255, 255, 0), #fff 18%, #fff);
}

.composer {
  width: min(100%, var(--content-width));
  margin: 0 auto;
  padding: 7px;
  border: 1px solid #cfd7d3;
  border-radius: 22px;
  background: var(--surface);
  box-shadow: 0 5px 22px rgba(20, 40, 33, 0.1);
}

.mode-switch {
  display: flex;
  gap: 5px;
  margin: 0;
  padding: 0 4px 5px;
  border: 0;
}

.mode-switch label {
  cursor: pointer;
}

.mode-switch input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.mode-switch label > span {
  display: inline-flex;
  min-height: 37px;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border-radius: 10px;
  color: var(--muted);
  font-size: 0.79rem;
  font-weight: 750;
}

.mode-switch input:checked + span {
  background: var(--brand-soft);
  color: var(--brand-dark);
}

.mode-switch input:focus-visible + span {
  outline: 3px solid #58bfa4;
  outline-offset: 2px;
}

.composer__input-row {
  display: flex;
  align-items: flex-end;
  gap: 7px;
}

.attach-button {
  display: grid;
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-soft);
  color: var(--ink);
  cursor: pointer;
  font-size: 1.35rem;
  font-weight: 500;
}

.attach-button:hover {
  background: var(--brand-soft);
}

.attach-button.is-disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.attachment-preview {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  margin: 0 4px 6px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--surface-soft);
}

.attachment-preview img {
  width: 54px;
  height: 54px;
  border-radius: 9px;
  background: #fff;
  object-fit: cover;
}

.attachment-preview strong,
.attachment-preview span {
  display: block;
}

.attachment-preview strong {
  font-size: 0.84rem;
}

.attachment-preview span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.7rem;
}

.attachment-preview button {
  min-height: 38px;
  padding: 6px 9px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--danger);
  font-size: 0.76rem;
  font-weight: 750;
}

.message-attachment-note {
  display: inline-block;
  margin-bottom: 6px;
  padding: 3px 7px;
  border-radius: 7px;
  background: #dfe8e3;
  color: #35433e;
  font-size: 0.72rem;
  font-weight: 750;
}

.composer textarea {
  max-height: 190px;
  resize: none;
  padding: 10px 10px 8px;
  border: 0;
  outline: 0;
  line-height: 1.5;
}

.composer textarea:focus {
  border: 0;
  outline: 0;
}

.send-button {
  display: grid;
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  place-items: center;
  border: 0;
  border-radius: 14px;
  background: var(--brand);
  color: #fff;
  font-weight: 900;
}

.send-button:hover:not(:disabled) {
  background: var(--brand-dark);
}

.send-arrow {
  font-size: 1.45rem;
  line-height: 1;
}

.send-button.is-busy .send-arrow {
  display: none;
}

.send-button.is-busy .spinner {
  display: block;
}

.composer-hint {
  margin: 6px auto 0;
  color: var(--muted);
  font-size: 0.68rem;
  text-align: center;
}

.sidebar-backdrop {
  position: fixed;
  z-index: 45;
  inset: 0;
  background: rgba(15, 25, 21, 0.44);
  backdrop-filter: blur(2px);
}

.confirm-dialog {
  width: min(calc(100% - 28px), 430px);
  padding: 0;
  border: 0;
  border-radius: 20px;
  box-shadow: var(--shadow);
}

.confirm-dialog::backdrop {
  background: rgba(15, 25, 21, 0.48);
}

.confirm-dialog form {
  padding: 25px;
}

.confirm-dialog h2 {
  margin: 0 0 6px;
  font-size: 1.25rem;
  letter-spacing: -0.03em;
}

.confirm-dialog p {
  margin: 0 0 22px;
  color: var(--muted);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.toast {
  position: fixed;
  z-index: 180;
  bottom: calc(24px + env(safe-area-inset-bottom));
  left: 50%;
  width: max-content;
  max-width: calc(100% - 30px);
  padding: 11px 17px;
  border-radius: 12px;
  background: #17201d;
  color: #fff;
  font-size: 0.88rem;
  font-weight: 700;
  text-align: center;
  transform: translateX(-50%);
  box-shadow: var(--shadow);
}

.noscript-message {
  position: fixed;
  z-index: 300;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 30px;
  background: var(--surface);
  font-weight: 800;
  text-align: center;
}

/* Admin */
.admin-page {
  background:
    radial-gradient(circle at 5% 0%, rgba(15, 111, 92, 0.08), transparent 29%),
    var(--page);
}

.admin-topbar {
  display: flex;
  min-height: calc(72px + env(safe-area-inset-top));
  align-items: center;
  justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) max(20px, calc((100vw - 1180px) / 2)) 10px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(14px);
}

.admin-main {
  width: min(100% - 32px, 1180px);
  margin: 0 auto;
  padding: 36px 0 70px;
}

.admin-auth-card {
  margin: min(9vh, 80px) auto 0;
}

.admin-auth-card .stack-form {
  margin: 0;
}

.admin-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 24px;
}

.admin-heading .eyebrow {
  margin: 0 0 3px;
}

.admin-heading h1 {
  margin: 0;
  font-size: clamp(1.8rem, 5vw, 2.45rem);
  line-height: 1.25;
  letter-spacing: -0.05em;
}

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

.admin-heading .muted {
  margin: 4px 0 0;
  font-size: 0.86rem;
}

.summary-grid {
  display: grid;
  grid-template-columns: 1.35fr 1fr 1fr;
  gap: 13px;
  margin-bottom: 15px;
}

.summary-card,
.admin-panel,
.privacy-note {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 2px 9px rgba(20, 40, 33, 0.035);
}

.summary-card {
  min-height: 156px;
  padding: 20px;
}

.summary-card--accent {
  border-color: #b7d6cc;
  background: linear-gradient(135deg, #ecf7f3, #fff);
}

.summary-card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

.summary-card > strong {
  display: block;
  margin: 7px 0;
  font-size: 2rem;
  line-height: 1.25;
  letter-spacing: -0.04em;
}

.summary-card strong small {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.summary-card > small {
  color: var(--muted);
  font-size: 0.75rem;
}

.budget-track {
  height: 8px;
  margin: 10px 0 7px;
  overflow: hidden;
  border-radius: 999px;
  background: #dbe7e3;
}

.budget-track span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--brand);
  transition: width 350ms ease;
}

.budget-track span.is-warning {
  background: #c16d05;
}

.budget-track span.is-danger {
  background: var(--danger);
}

.admin-panel {
  padding: 22px;
}

.invite-panel {
  margin-bottom: 15px;
}

.panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 17px;
}

.panel-heading h2 {
  margin: 0;
  font-size: 1.18rem;
  letter-spacing: -0.03em;
}

.panel-heading p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.inline-form__row,
.copy-field {
  display: flex;
  gap: 8px;
}

.inline-form__row input,
.copy-field input {
  min-width: 0;
  flex: 1;
}

.invite-result {
  margin-top: 18px;
  padding: 14px;
  border-radius: 13px;
  background: var(--brand-soft);
}

.invite-result label {
  display: block;
  margin-top: 0;
  color: var(--brand-dark);
}

.invite-result .muted {
  margin: 6px 0 0;
  font-size: 0.76rem;
}

.admin-columns {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(310px, 0.8fr);
  gap: 15px;
}

.device-list {
  display: grid;
  gap: 8px;
}

.device-row {
  display: grid;
  align-items: center;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  gap: 11px;
  padding: 11px 0;
  border-top: 1px solid #edf0ee;
}

.device-row:first-child {
  border-top: 0;
}

.device-row__icon {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 12px;
  background: var(--surface-soft);
  font-size: 1.25rem;
}

.device-row strong,
.device-row small {
  display: block;
}

.device-row small {
  color: var(--muted);
  font-size: 0.73rem;
}

.device-row .button {
  min-height: 40px;
  padding: 7px 12px;
  color: var(--danger);
  font-size: 0.78rem;
}

.device-row .button:hover {
  background: var(--danger-soft);
}

.device-row.is-revoked {
  opacity: 0.58;
}

.device-status {
  display: inline-block;
  margin-left: 5px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--brand-soft);
  color: var(--brand-dark);
  font-size: 0.65rem;
  font-weight: 800;
}

.device-status--off {
  background: #eceeed;
  color: var(--muted);
}

.empty-note {
  padding: 28px 10px;
  color: var(--muted);
  text-align: center;
}

.settings-form {
  display: flex;
  flex-direction: column;
}

.settings-form label:first-child {
  margin-top: 0;
}

.settings-form > small {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.72rem;
}

.number-field {
  display: flex;
  min-height: 50px;
  align-items: center;
  gap: 7px;
  padding: 0 12px;
  border: 1px solid #c9d1ce;
  border-radius: 12px;
  background: var(--surface);
  font-weight: 800;
}

.number-field:focus-within {
  border-color: var(--brand);
  outline: 3px solid rgba(15, 111, 92, 0.14);
}

.number-field input {
  min-height: 46px;
  padding: 0;
  border: 0;
  outline: 0;
  text-align: right;
}

.number-field input:focus {
  border: 0;
  outline: 0;
}

.settings-form .button {
  margin-top: 22px;
}

.panel-divider {
  height: 1px;
  margin: 28px 0 24px;
  background: #e6ebe8;
}

.panel-heading--sub {
  margin-bottom: 12px;
}

.password-form {
  display: flex;
  flex-direction: column;
}

.password-form label {
  margin-top: 13px;
}

.password-form label:first-child {
  margin-top: 0;
}

.password-form .button {
  margin-top: 22px;
}

.privacy-note {
  display: flex;
  align-items: flex-start;
  gap: 13px;
  margin-top: 15px;
  padding: 18px 20px;
  background: #f2f7f5;
}

.privacy-note > span {
  font-size: 1.35rem;
}

.privacy-note strong {
  display: block;
  font-size: 0.9rem;
}

.privacy-note p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 0.76rem;
}

@media (max-width: 900px) {
  .sidebar {
    transform: translateX(-105%);
    box-shadow: var(--shadow);
    transition: transform 180ms ease;
  }

  body.sidebar-open {
    overflow: hidden;
  }

  body.sidebar-open .sidebar {
    transform: translateX(0);
  }

  .sidebar__close,
  .topbar__menu {
    display: inline-grid;
  }

  .chat-area {
    margin-left: 0;
  }

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

  .summary-card:last-child {
    grid-column: 1 / -1;
    min-height: 125px;
  }

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

@media (max-width: 620px) {
  :root {
    font-size: 16px;
  }

  .topbar {
    min-height: calc(60px + env(safe-area-inset-top));
    padding: calc(6px + env(safe-area-inset-top)) 10px 6px;
  }

  .topbar .button--compact {
    width: 44px;
    padding: 0;
  }

  .topbar .button-label {
    display: none;
  }

  .empty-state {
    width: min(100% - 26px, 800px);
    min-height: calc(100dvh - 220px);
    padding-top: 26px;
  }

  .empty-state > p {
    margin-bottom: 20px;
  }

  .starter-grid {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .starter-card {
    min-height: 70px;
    padding: 10px 12px;
  }

  .starter-card__icon {
    width: 41px;
    height: 41px;
  }

  .message-list {
    padding: 18px 14px 10px;
  }

  .message {
    grid-template-columns: 33px minmax(0, 1fr);
    gap: 9px;
    margin-bottom: 23px;
  }

  .message__avatar {
    width: 32px;
    height: 32px;
    border-radius: 10px;
  }

  .message--user .message__content {
    max-width: 90%;
    padding: 10px 14px;
  }

  .composer-wrap {
    padding: 7px 8px calc(6px + env(safe-area-inset-bottom));
  }

  .composer {
    border-radius: 19px;
  }

  .composer-hint {
    display: none;
  }

  .mode-switch label > span {
    min-height: 35px;
    font-size: 0.76rem;
  }

  .admin-topbar {
    min-height: calc(64px + env(safe-area-inset-top));
    padding: calc(8px + env(safe-area-inset-top)) 14px 8px;
  }

  .admin-main {
    width: min(100% - 22px, 1180px);
    padding-top: 24px;
  }

  .admin-heading {
    align-items: center;
  }

  .admin-heading .button {
    min-height: 42px;
    padding: 7px 10px;
    font-size: 0.8rem;
  }

  .summary-grid {
    grid-template-columns: 1fr 1fr;
    gap: 9px;
  }

  .summary-card {
    min-height: 140px;
    padding: 16px;
  }

  .summary-card--accent {
    grid-column: 1 / -1;
  }

  .summary-card:last-child {
    grid-column: auto;
    min-height: 140px;
  }

  .summary-card > strong {
    font-size: 1.6rem;
  }

  .admin-panel {
    padding: 17px;
  }

  .inline-form__row,
  .copy-field {
    flex-direction: column;
  }

  .inline-form__row .button,
  .copy-field .button {
    width: 100%;
  }

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

  .device-row__icon {
    width: 38px;
    height: 38px;
  }

  .device-row .button {
    grid-column: 2;
    justify-self: start;
  }

  .gate-card,
  .admin-auth-card {
    padding: 28px 21px;
    border-radius: 21px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
