:root {
  --bg: #eef2f4;
  --bg-panel: #f7f9fa;
  --surface: #ffffff;
  --ink: #1a2330;
  --muted: #5c6b7a;
  --line: #d4dde5;
  --accent: #0f6e6a;
  --accent-ink: #ffffff;
  --accent-soft: #d8efed;
  --danger: #9b2c2c;
  --warning: #8a5a00;
  --info: #1e4d7b;
  --success: #1f6b3a;
  --rail: #142033;
  --rail-ink: #d7e0ea;
  --api: #6b4f1d;
  --radius: 10px;
  --font: "IBM Plex Sans", "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}

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

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

body {
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(ellipse 80% 50% at 100% 0%, #d5e8e6 0%, transparent 55%),
    radial-gradient(ellipse 60% 40% at 0% 100%, #d9e2ec 0%, transparent 50%),
    var(--bg);
  line-height: 1.45;
}

body:has(.messenger) {
  overflow: hidden;
}

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

a:hover {
  text-decoration: underline;
}

h1,
h2 {
  margin: 0 0 0.35rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.app-shell {
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: 100vh;
}

.app-shell:has(.messenger) {
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.rail {
  background: linear-gradient(180deg, #142033 0%, #1a2a40 100%);
  color: var(--rail-ink);
  display: flex;
  flex-direction: column;
  padding: 1.25rem 1rem;
  gap: 1.5rem;
}

.brand {
  font-size: 1.35rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.03em;
  text-decoration: none;
}

.brand:hover {
  text-decoration: none;
  color: #fff;
}

.rail-nav {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  flex: 1;
}

.rail-nav a {
  color: var(--rail-ink);
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  text-decoration: none;
  font-weight: 500;
}

.rail-nav a:hover,
.rail-nav a.active {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  text-decoration: none;
}

.rail-footer {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  font-size: 0.9rem;
}

.user-chip {
  font-weight: 500;
  color: #fff;
}

.link-muted {
  color: #98a8ba;
}

.main {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.app-shell:has(.messenger) .main {
  height: 100%;
  overflow: hidden;
}

.flash-stack {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding: 0.75rem 1rem 0;
}

.flash {
  padding: 0.65rem 0.9rem;
  border-radius: 8px;
  background: #fff;
  border: 1px solid var(--line);
  font-size: 0.92rem;
}

.flash-danger { border-color: #e8b4b4; color: var(--danger); }
.flash-warning { border-color: #e8d4a0; color: var(--warning); }
.flash-success { border-color: #b7dcc4; color: var(--success); }
.flash-info { border-color: #b4cce0; color: var(--info); }

/* Login */
.login-page {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.login-panel {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 3rem clamp(1.5rem, 5vw, 4rem);
  max-width: 480px;
  margin: 0 auto;
  width: 100%;
}

.login-brand {
  font-size: 2rem;
  font-weight: 700;
  margin: 0 0 1.5rem;
  letter-spacing: -0.03em;
  color: var(--accent);
}

.login-lead {
  color: var(--muted);
  margin: 0 0 1.5rem;
}

.login-visual {
  background:
    linear-gradient(145deg, rgba(15, 110, 106, 0.85), rgba(20, 32, 51, 0.9)),
    url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.06'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
  background-size: cover, 60px 60px;
}

/* Messenger */
.messenger {
  display: grid;
  grid-template-columns: 300px 1fr;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.chat-list {
  background: var(--bg-panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.chat-list-users {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-list-users .conv-items {
  flex: 1;
  overflow-y: auto;
}

.chat-list-environments {
  flex-shrink: 0;
  max-height: 42%;
  display: flex;
  flex-direction: column;
  border-top: 1px solid var(--line);
  background: linear-gradient(180deg, #f0f4f6, var(--bg-panel));
}

.chat-list-environments .env-items {
  overflow-y: auto;
  max-height: 220px;
  padding-bottom: 0.75rem;
}

.chat-list-environments .panel-head h2 {
  color: var(--accent);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1rem 1rem 0.75rem;
}

.panel-head h2 {
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 600;
}

.conv-items {
  list-style: none;
  margin: 0;
  padding: 0.25rem 0.5rem 1rem;
  overflow-y: auto;
  flex: 1;
}

.conv-item {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0.75rem 0.85rem;
  border-radius: 8px;
  color: inherit;
  text-decoration: none;
}

.conv-item-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.conv-item-top strong,
.conv-name strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.unread-badge {
  flex-shrink: 0;
  min-width: 1.25rem;
  height: 1.25rem;
  padding: 0 0.4rem;
  border-radius: 999px;
  background: #c23b3b;
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1.25rem;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.conv-item:hover {
  background: rgba(15, 110, 106, 0.08);
  text-decoration: none;
}

.conv-item.active {
  background: var(--accent-soft);
}

.conv-item.active .unread-badge {
  display: none;
}

.conv-preview {
  font-size: 0.85rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  background: var(--surface);
  position: relative;
}

.chat-header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  padding: 0;
}

.icon-btn:hover,
.icon-btn.active {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}

.chat-body {
  flex: 1;
  min-height: 0;
  display: flex;
}

.chat-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.chat-body.search-open .chat-main {
  border-right: 1px solid var(--line);
}

.search-panel {
  width: min(320px, 42vw);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-panel);
  border-left: 1px solid var(--line);
  min-height: 0;
}

.search-panel[hidden] {
  display: none !important;
}

.search-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--line);
}

.search-panel-head h2 {
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.search-field {
  display: block;
  padding: 0.75rem 1rem 0.35rem;
}

.search-field input {
  width: 100%;
  font: inherit;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.search-field input:focus {
  outline: 2px solid rgba(15, 110, 106, 0.35);
  border-color: var(--accent);
}

.search-status {
  margin: 0;
  padding: 0.35rem 1rem 0.5rem;
  font-size: 0.82rem;
  color: var(--muted);
  min-height: 1.4rem;
}

.search-results {
  list-style: none;
  margin: 0;
  padding: 0 0.5rem 1rem;
  overflow-y: auto;
  flex: 1;
}

.search-hit {
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  border-radius: 8px;
  padding: 0.65rem 0.7rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  font: inherit;
  color: inherit;
}

.search-hit:hover {
  background: rgba(15, 110, 106, 0.1);
}

.search-hit-time {
  font-size: 0.75rem;
  color: var(--muted);
}

.search-hit-snippet {
  font-size: 0.85rem;
  color: var(--ink);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.history-loader {
  text-align: center;
  font-size: 0.85rem;
  color: var(--muted);
  padding: 0.5rem;
}

.msg-highlight {
  outline: 2px solid var(--accent);
  background: #e7f6f4 !important;
  transition: background 0.3s ease;
}

.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) {
  .chat-body.search-open {
    flex-direction: column;
  }

  .search-panel {
    width: 100%;
    max-height: 40vh;
    border-left: none;
    border-top: 1px solid var(--line);
  }
}

.chat-header {
  flex-shrink: 0;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #fff, #f9fbfc);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.conv-name {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  min-width: 0;
}

.presence-dot {
  flex-shrink: 0;
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  background: #b7c2c8;
  box-shadow: 0 0 0 2px #fff;
}

.presence-dot[data-online="1"] {
  background: #1f8a4c;
}

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

.presence-label[data-online="1"] {
  color: #1f8a4c;
}

.presence-label[data-online="0"] {
  color: var(--muted);
}

.live-badge {
  flex-shrink: 0;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: lowercase;
  color: var(--muted);
  background: #e8eef2;
  padding: 0.3rem 0.55rem;
  border-radius: 999px;
}

.live-badge[data-state="online"],
.live-badge[data-online="1"] {
  color: var(--accent);
  background: var(--accent-soft);
}

.live-badge[data-state="offline"],
.live-badge[data-online="0"] {
  color: var(--danger);
  background: #f8e8e8;
}

.chat-header h1 {
  font-size: 1.25rem;
}

.members-line {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.messages {
  flex: 1;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  background:
    radial-gradient(circle at 20% 20%, rgba(15, 110, 106, 0.04), transparent 40%),
    var(--surface);
}

.msg {
  max-width: min(640px, 92%);
  padding: 0.7rem 0.9rem;
  border-radius: 12px;
  background: var(--bg-panel);
  border: 1px solid var(--line);
  align-self: flex-start;
  flex-shrink: 0;
}

.msg.mine {
  align-self: flex-end;
  background: var(--accent-soft);
  border-color: #b7d9d6;
}

.msg.api {
  border-left: 3px solid var(--api);
}

.msg.important {
  background: #fff8e6;
  border-color: #e0c36a;
  box-shadow: inset 3px 0 0 #c9a227;
}

.msg.mine.important {
  background: #fff1cc;
  border-color: #d4b44a;
  box-shadow: inset 3px 0 0 #c9a227;
}

.msg-flag {
  display: inline-block;
  margin-left: 0.35rem;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #8a6a10;
  background: #f5e4a8;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  vertical-align: middle;
}

.msg-footer {
  margin-top: 0.45rem;
  display: flex;
  justify-content: flex-start;
}

.msg-reactions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.3rem;
}

.reaction-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.15rem;
  border: none;
  background: transparent;
  border-radius: 0;
  padding: 0 0.1rem;
  margin: 0;
  font: inherit;
  font-size: 0.95rem;
  cursor: pointer;
  line-height: 1.2;
  opacity: 0.9;
}

.reaction-chip.mine {
  opacity: 1;
}

.reaction-count {
  font-size: 0.7rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.reaction-add {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  padding: 0 0.15rem;
  margin: 0;
  font: inherit;
  font-size: 0.95rem;
  font-weight: 500;
  line-height: 1;
  color: var(--muted);
  opacity: 0.55;
  cursor: pointer;
}

.reaction-add:hover,
.reaction-chip:hover {
  opacity: 1;
  color: var(--ink);
  border: none;
  background: transparent;
}

.presence-dot.self-dot {
  background: var(--accent);
}

.emoji-picker {
  position: fixed;
  z-index: 80;
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  max-width: 220px;
  padding: 0.4rem;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(20, 40, 50, 0.12);
}

.emoji-picker[hidden] {
  display: none !important;
}

.emoji-option {
  border: none;
  background: transparent;
  font-size: 1.25rem;
  cursor: pointer;
  padding: 0.2rem;
  border-radius: 6px;
  line-height: 1;
}

.emoji-option:hover {
  background: var(--bg-panel);
}

.msg-menu {
  position: fixed;
  z-index: 90;
  min-width: 160px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(20, 40, 50, 0.14);
  padding: 0.25rem;
}

.msg-menu[hidden] {
  display: none !important;
}

.msg-menu button {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  font: inherit;
  padding: 0.55rem 0.75rem;
  border-radius: 6px;
  cursor: pointer;
  color: var(--ink);
}

.msg-menu button:hover {
  background: var(--bg-panel);
}

.app-modal {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0;
  max-width: 420px;
  width: calc(100% - 2rem);
  box-shadow: 0 16px 40px rgba(20, 40, 50, 0.18);
}

.app-modal::backdrop {
  background: rgba(20, 30, 40, 0.35);
}

.app-modal .stack-form {
  padding: 1.1rem 1.25rem 1.25rem;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.modal-head h2 {
  font-size: 1.1rem;
  margin: 0;
}

.reminder-preview {
  margin: 0 0 0.75rem;
  padding: 0.6rem 0.75rem;
  background: var(--bg-panel);
  border-radius: 8px;
  border: 1px solid var(--line);
  font-size: 0.9rem;
}

.reminder-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.85rem;
}

.reminder-card {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.1rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.reminder-desc {
  margin: 0 0 0.5rem;
  font-weight: 600;
}

.reminder-msg {
  margin: 0 0 0.5rem;
  padding: 0.55rem 0.7rem;
  border-left: 3px solid #c9a227;
  background: #fff8e6;
  display: grid;
  gap: 0.25rem;
  font-size: 0.92rem;
}

.msg header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.35rem;
  font-size: 0.85rem;
}

.msg header time {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.msg p {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg p a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
  word-break: break-all;
}

.msg p a:hover {
  color: #0c5c59;
}

.attachments {
  list-style: none;
  margin: 0.5rem 0 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.att-card {
  margin: 0;
}

.att-preview {
  display: block;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
  padding: 0;
  text-align: left;
  color: inherit;
  font: inherit;
  overflow: hidden;
  max-width: 220px;
}

.att-preview:hover {
  border-color: var(--accent);
}

.att-preview-image img {
  display: block;
  width: 180px;
  height: 120px;
  object-fit: cover;
}

.att-preview-file {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding: 0.65rem 0.75rem;
  min-width: 140px;
}

.att-icon {
  font-family: var(--mono);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 0.04em;
}

.att-name {
  font-size: 0.88rem;
  word-break: break-word;
}

.attachments .meta {
  color: var(--muted);
  font-size: 0.8rem;
}

.pending-files {
  list-style: none;
  margin: 0;
  padding: 0.65rem 1rem 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
}

.pending-item {
  position: relative;
  display: inline-flex;
}

.pending-item .pending-thumb {
  max-width: 160px;
}

.pending-item .att-preview-image img {
  width: 120px;
  height: 80px;
}

.pending-remove {
  position: absolute;
  top: -0.35rem;
  right: -0.35rem;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
  z-index: 2;
}

.pending-remove:hover {
  background: #f8e8e8;
  color: var(--danger);
}

.att-viewer {
  border: none;
  border-radius: 12px;
  padding: 0;
  width: min(920px, 94vw);
  max-height: 90vh;
  background: #fff;
  color: var(--ink);
  box-shadow: 0 20px 50px rgba(20, 32, 51, 0.28);
}

.att-viewer::backdrop {
  background: rgba(20, 32, 51, 0.55);
}

.att-viewer-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--line);
}

.att-viewer-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.att-viewer-body {
  padding: 1rem;
  max-height: calc(90vh - 60px);
  overflow: auto;
  display: flex;
  justify-content: center;
  background: #f4f7f8;
}

.att-viewer-body img {
  max-width: 100%;
  max-height: calc(90vh - 100px);
  object-fit: contain;
}

.att-viewer-body iframe {
  width: 100%;
  min-height: 70vh;
  border: none;
  background: #fff;
}

.att-text-preview {
  width: 100%;
  margin: 0;
  padding: 1rem;
  background: #fff;
  border-radius: 8px;
  font-family: var(--mono);
  font-size: 0.85rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.att-fallback {
  text-align: center;
  padding: 2rem 1rem;
}

.composer-wrap {
  position: relative;
  flex-shrink: 0;
  border-top: 1px solid var(--line);
  background: #fafcfc;
}

.composer {
  padding: 0.85rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.composer textarea {
  width: 100%;
  resize: vertical;
  min-height: 56px;
}

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

.composer-hint {
  font-size: 0.85rem;
  color: var(--muted);
}

.chat-pane.is-dragging::after {
  content: "Suelta los archivos aquí";
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(247, 249, 250, 0.88);
  border: 2px dashed var(--accent);
  color: var(--accent);
  font-weight: 600;
  font-size: 1.05rem;
  pointer-events: none;
}

.composer-locked,
.empty-hint {
  color: var(--muted);
  padding: 2rem;
  text-align: center;
}

.chat-empty {
  margin: auto;
}

.chat-empty h1 {
  font-size: 2rem;
  color: var(--accent);
}

/* Forms & pages */
.page,
.page-narrow {
  padding: 1.5rem clamp(1rem, 3vw, 2rem);
}

.page-narrow {
  max-width: 640px;
}

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.page-head p,
.muted {
  color: var(--muted);
  margin: 0;
}

.stack-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.stack-form label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-weight: 500;
  font-size: 0.92rem;
}

.stack-form input[type="text"],
.stack-form input[type="password"],
.stack-form select,
.stack-form textarea,
.stack-form .multi-select {
  width: 100%;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  background: #fff;
}

.stack-form .multi-select {
  min-height: 8rem;
}

.composer textarea {
  width: 100%;
  font: inherit;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}

.stack-form input:focus,
.stack-form select:focus,
.stack-form textarea:focus,
.composer textarea:focus {
  outline: 2px solid rgba(15, 110, 106, 0.35);
  border-color: var(--accent);
}

.check-grid {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.check-grid legend {
  padding: 0 0.35rem;
  font-weight: 600;
  font-size: 0.9rem;
}

.field-error {
  color: var(--danger);
  font-size: 0.85rem;
}

.check-row {
  display: flex !important;
  flex-direction: row !important;
  align-items: center;
  gap: 0.55rem;
  font-weight: 400 !important;
}

.form-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  margin-top: 0.5rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.55rem 1rem;
  border-radius: 8px;
  border: 1px solid transparent;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}

.btn:hover {
  text-decoration: none;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
}

.btn-primary:hover {
  background: #0c5c59;
  color: #fff;
}

.btn-ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--ink);
}

.btn-small {
  padding: 0.35rem 0.7rem;
  font-size: 0.85rem;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--ink);
}

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

.btn-danger:hover {
  background: #fdf2f2;
  color: var(--danger);
}

.row-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: nowrap;
  white-space: nowrap;
}

.row-actions .inline-form {
  display: inline;
  margin: 0;
}

.data-table .row-actions .inline-form {
  margin-bottom: 0;
}

.link-danger {
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  font: inherit;
  line-height: inherit;
  color: var(--danger);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.danger-zone {
  margin-top: 2rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--line);
}

.admin-grid {
  display: grid;
  gap: 2rem;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.data-table th,
.data-table td {
  text-align: left;
  padding: 0.75rem 0.9rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

.data-table th {
  background: var(--bg-panel);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.data-table tr:last-child td {
  border-bottom: none;
}

.tag {
  display: inline-block;
  font-size: 0.75rem;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 500;
  margin: 0.1rem;
}

.perm-tags {
  max-width: 280px;
}

.meta-list {
  display: grid;
  gap: 0.85rem;
  margin: 0 0 1.25rem;
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.meta-list dt {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.meta-list dd {
  margin: 0.2rem 0 0;
}

.api-key,
.code-block,
code {
  font-family: var(--mono);
  font-size: 0.85rem;
}

.code-block {
  background: #142033;
  color: #d7e0ea;
  padding: 1rem;
  border-radius: var(--radius);
  overflow-x: auto;
  white-space: pre-wrap;
}

.api-docs {
  margin-top: 1.5rem;
}

.api-docs h2 {
  font-size: 1.1rem;
  margin-bottom: 0.75rem;
}

.inline-form {
  margin-bottom: 1rem;
}

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

  .rail {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
  }

  .rail-nav {
    flex-direction: row;
    flex-wrap: wrap;
    flex: 1;
  }

  .rail-footer {
    flex-direction: row;
    align-items: center;
    width: 100%;
    justify-content: space-between;
  }

  .messenger {
    grid-template-columns: 1fr;
    grid-template-rows: 180px 1fr;
  }

  .chat-list {
    max-height: none;
    border-right: none;
    border-bottom: 1px solid var(--line);
  }

  .login-page {
    grid-template-columns: 1fr;
  }

  .login-visual {
    display: none;
  }
}
