:root {
  --paper: #f7f4ee;
  --panel: #fffdf8;
  --ink: #1d2522;
  --muted: #6b716d;
  --line: #d9d4c9;
  --green: #1d6f52;
  --green-soft: #d7eadf;
  --blue: #285f8f;
  --cyan: #207a9f;
  --cyan-soft: #dff3fb;
  --amber: #b36b12;
  --amber-soft: #f3e4cf;
  --red: #a23c2f;
  --shadow: 0 18px 60px rgba(55, 48, 37, 0.16);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

.login-body {
  display: grid;
  min-height: 100%;
  overflow: auto;
}

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

.login-panel {
  display: grid;
  width: min(420px, 100%);
  gap: 16px;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.92);
  box-shadow: var(--shadow);
}

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

.login-error {
  color: var(--red);
  font-weight: 700;
}

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

.security-grid h3 {
  margin: 0;
  font-size: 1rem;
}

.twofa-box {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.twofa-box code,
.recovery-codes {
  display: block;
  padding: 10px;
  border-radius: 6px;
  background: var(--ink);
  color: var(--panel);
  white-space: pre-wrap;
  word-break: break-word;
}

.detail-warning.ok {
  color: var(--green);
  background: var(--green-soft);
}

body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(29, 111, 82, 0.08), transparent 38%),
    linear-gradient(315deg, rgba(179, 107, 18, 0.08), transparent 34%),
    var(--paper);
  font-family: "Avenir Next", "IBM Plex Sans", "Helvetica Neue", sans-serif;
  overflow: hidden;
}

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

button {
  border: 0;
  cursor: pointer;
}

.app-shell {
  height: calc(100vh - 72px);
  overflow: hidden;
}

.app-header {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto auto 44px;
  align-items: center;
  gap: 18px;
  height: 72px;
  padding: 12px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 253, 248, 0.86);
  backdrop-filter: blur(18px);
}

.account-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.account-tools .text-button,
.account-tools .ghost-button {
  white-space: nowrap;
}

.account-tools form {
  margin: 0;
}

.account-tools select {
  max-width: 220px;
  min-width: 150px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  background: var(--panel);
  font-weight: 700;
}

.compact {
  padding: 9px 11px;
}

.account-form {
  display: grid;
  gap: 12px;
}

.account-modal {
  width: min(520px, calc(100vw - 32px));
}

.top-nav {
  display: flex;
  gap: 8px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(236, 230, 218, 0.56);
}

.nav-button {
  min-width: 112px;
  padding: 9px 12px;
  border-radius: 7px;
  color: var(--muted);
  background: transparent;
  font-weight: 800;
  text-align: center;
  text-decoration: none;
}

.nav-button.active {
  color: white;
  background: var(--green);
}

.app-view {
  display: none;
  height: 100%;
  min-height: 0;
}

.app-view.active {
  display: grid;
}

.inbox-view {
  grid-template-columns: 340px minmax(420px, 1fr);
}

.automations-view {
  grid-template-columns: 340px minmax(0, 1fr);
  overflow: hidden;
  padding: 22px;
  gap: 18px;
}

.accounts-view,
.users-view {
  overflow: auto;
  padding: 22px;
}

.side-rail,
.thread-panel,
.automation-panel {
  min-width: 0;
  border-color: var(--line);
}

.side-rail {
  display: flex;
  flex-direction: column;
  gap: 18px;
  height: 100%;
  min-height: 0;
  padding: 22px;
  border-right: 1px solid var(--line);
  background: rgba(255, 253, 248, 0.72);
  backdrop-filter: blur(18px);
  overflow: hidden;
}

.automation-sidebar,
.automation-panel {
  height: auto;
  min-height: 0;
  max-height: none;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.82);
}

.automation-sidebar {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.automation-panel {
  overflow: auto;
}

.thread-panel {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.42);
}

.management-page {
  display: grid;
  gap: 16px;
  width: min(1240px, 100%);
  margin: 0 auto;
}

.management-header {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 18px;
  min-height: 132px;
  padding: 26px 28px;
  overflow: hidden;
  border: 1px solid rgba(29, 37, 34, 0.12);
  border-radius: 8px;
  color: white;
  background:
    linear-gradient(90deg, rgba(29, 37, 34, 0.98), rgba(29, 111, 82, 0.9)),
    var(--ink);
  box-shadow: 0 20px 60px rgba(29, 37, 34, 0.18);
}

.management-header::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(135deg, rgba(255, 253, 248, 0.16) 0 1px, transparent 1px 28px),
    linear-gradient(90deg, transparent, rgba(243, 228, 207, 0.18));
  opacity: 0.72;
  pointer-events: none;
}

.management-header > * {
  position: relative;
  z-index: 1;
}

.management-header .eyebrow {
  color: rgba(255, 253, 248, 0.7);
  font-weight: 900;
  text-transform: uppercase;
}

.management-header h2 {
  margin-top: 6px;
  font-size: clamp(28px, 4vw, 46px);
  line-height: 0.96;
}

.management-header .text-button {
  min-width: 164px;
  color: var(--ink);
  background: var(--panel);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.18);
}

.management-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 10px;
}

.management-stat {
  position: relative;
  display: grid;
  gap: 3px;
  min-height: 86px;
  padding: 16px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.86);
}

.management-stat::after {
  content: "";
  position: absolute;
  right: 0;
  bottom: 0;
  width: 42px;
  height: 4px;
  background: var(--ink);
}

.management-stat.green::after {
  background: var(--green);
}

.management-stat.blue::after {
  background: var(--blue);
}

.management-stat.amber::after {
  background: var(--amber);
}

.management-stat span {
  font-size: 30px;
  font-weight: 900;
  line-height: 1;
}

.management-stat small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
  text-transform: uppercase;
}

.management-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 12px;
}

.management-card {
  position: relative;
  display: grid;
  gap: 18px;
  min-width: 0;
  min-height: 276px;
  padding: 18px 18px 16px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 253, 248, 0.96), rgba(247, 244, 238, 0.86)),
    var(--panel);
  box-shadow: 0 10px 30px rgba(55, 48, 37, 0.08);
}

.management-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 5px;
  background: linear-gradient(90deg, var(--green), var(--cyan), var(--amber));
}

.management-card:hover {
  border-color: rgba(29, 111, 82, 0.42);
  transform: translateY(-1px);
  transition: border-color 120ms ease, transform 120ms ease;
}

.management-card.current {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(29, 111, 82, 0.14), 0 18px 40px rgba(29, 111, 82, 0.12);
}

.management-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.identity-row {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 12px;
}

.account-avatar,
.user-avatar {
  display: grid;
  flex: 0 0 48px;
  width: 48px;
  height: 48px;
  place-items: center;
  border-radius: 8px;
  color: white;
  background: var(--ink);
  font-size: 14px;
  font-weight: 900;
}

.account-avatar {
  background: linear-gradient(135deg, var(--green), var(--cyan));
}

.user-avatar {
  background: linear-gradient(135deg, var(--ink), var(--amber));
}

.management-title-block {
  display: grid;
  min-width: 0;
  gap: 3px;
}

.management-title-block h3 {
  margin: 0;
  overflow: hidden;
  font-size: 18px;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.management-title-block span {
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.detail-list {
  display: grid;
  gap: 10px;
  margin: 0;
}

.account-card .detail-list,
.user-card .detail-list {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  padding: 12px;
  border: 1px solid rgba(217, 212, 201, 0.68);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.72);
}

.detail-list div {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.detail-list dt {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.detail-list dd {
  min-width: 0;
  margin: 0;
  overflow: hidden;
  font-size: 13px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.management-card-actions {
  display: flex;
  align-self: end;
  justify-content: flex-start;
}

.management-card-actions .ghost-button {
  min-width: 126px;
}

.management-card-actions button:disabled {
  cursor: default;
  opacity: 0.62;
  transform: none;
}

.status-chip,
.role-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 4px 8px;
  border-radius: 999px;
  color: var(--blue);
  background: rgba(40, 95, 143, 0.12);
  font-size: 12px;
  font-weight: 800;
}

.status-chip.active {
  color: var(--green);
  background: var(--green-soft);
}

.status-chip.paused {
  color: var(--red);
  background: rgba(162, 60, 47, 0.12);
}

.role-badge.admin {
  color: var(--green);
  background: var(--green-soft);
}

.owned-account-strip {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  min-height: 30px;
}

.owned-account-chip {
  max-width: 100%;
  padding: 5px 8px;
  overflow: hidden;
  border: 1px solid rgba(40, 95, 143, 0.18);
  border-radius: 999px;
  color: var(--blue);
  background: rgba(40, 95, 143, 0.09);
  font-size: 12px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.owned-account-chip.muted {
  color: var(--muted);
  background: #ece6da;
  border-color: transparent;
}

.management-empty {
  min-height: 180px;
  padding: 48px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.68);
}

.brand-lockup,
.section-title,
.thread-header,
.form-footer,
.button-row,
.split-row {
  display: flex;
  align-items: center;
}

.brand-lockup {
  gap: 12px;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  color: white;
  background: var(--ink);
  border-radius: 8px;
  font-weight: 800;
  letter-spacing: 0;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 18px;
  line-height: 1.1;
}

h2 {
  font-size: 20px;
  line-height: 1.2;
}

#threadTitle {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.thread-title-text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.instagram-profile-link {
  display: inline-grid;
  flex: 0 0 26px;
  width: 26px;
  height: 26px;
  place-items: center;
  border: 1px solid rgba(29, 111, 82, 0.22);
  border-radius: 8px;
  color: var(--green);
  background: var(--green-soft);
  text-decoration: none;
}

.instagram-profile-link:hover {
  color: white;
  background: var(--green);
}

.instagram-profile-link svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
}

.brand-lockup p,
.eyebrow,
.metric small,
.conversation-meta,
.message-meta {
  color: var(--muted);
}

.brand-lockup p,
.eyebrow {
  margin-top: 3px;
  font-size: 13px;
}

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

.metric {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.9);
}

.metric span {
  display: block;
  font-size: 26px;
  font-weight: 800;
}

.metric small {
  display: block;
  margin-top: 3px;
  font-size: 12px;
}

.conversation-panel {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.section-title {
  justify-content: space-between;
  margin-bottom: 12px;
}

.search-box {
  margin-bottom: 12px;
}

.search-box input {
  padding: 11px 12px;
}

.icon-button,
.text-button,
.ghost-button,
.reply-bar button,
.rule-form button {
  border-radius: 8px;
  transition: transform 120ms ease, background 120ms ease, opacity 120ms ease;
}

.icon-button:hover,
.text-button:hover,
.ghost-button:hover,
.reply-bar button:hover,
.rule-form button:hover {
  transform: translateY(-1px);
}

.icon-button {
  width: 34px;
  height: 34px;
  color: var(--ink);
  background: var(--green-soft);
}

.text-button,
.reply-bar button,
.rule-form button {
  color: white;
  background: var(--green);
  font-weight: 700;
}

.text-button {
  padding: 9px 13px;
}

.conversation-list,
.rule-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.automation-sidebar .rule-list {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding-right: 4px;
}

.conversation-list {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding-right: 4px;
}

.conversation-item,
.rule-item {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.9);
  box-shadow: 0 8px 24px rgba(55, 48, 37, 0.06);
}

.conversation-item {
  text-align: left;
}

.conversation-item.active {
  border-color: var(--green);
  outline: 2px solid rgba(29, 111, 82, 0.16);
}

.conversation-top,
.rule-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

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

.conversation-identity {
  display: grid;
  min-width: 0;
  gap: 2px;
}

.conversation-name,
.rule-name {
  overflow: hidden;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-tag {
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-preview,
.rule-trigger {
  display: -webkit-box;
  margin-top: 7px;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.conversation-meta,
.message-meta,
.rule-meta {
  font-size: 12px;
}

.badge,
.pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 4px 8px;
  border-radius: 999px;
  color: var(--green);
  background: var(--green-soft);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.badge.comment {
  color: var(--amber);
  background: #f3e4cf;
}

.badge.unread {
  color: white;
  background: var(--red);
}

.thread-header {
  justify-content: space-between;
  gap: 16px;
  padding: 22px 26px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 253, 248, 0.72);
}

.message-stream {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  overflow: auto;
  padding: 26px;
  overscroll-behavior: contain;
}

.message {
  max-width: min(640px, 86%);
}

.message.out {
  align-self: flex-end;
}

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

.message.out .message-bubble {
  color: white;
  border-color: var(--green);
  background: var(--green);
}

.message.comment-related .message-bubble {
  border-color: rgba(179, 107, 18, 0.48);
  background: #f8ead7;
}

.message.story-related .message-bubble {
  border-color: rgba(45, 142, 186, 0.46);
  background: #dff3fb;
}

.message.out.comment-related .message-bubble {
  color: var(--ink);
  border-color: rgba(179, 107, 18, 0.58);
  background: #e9a13b;
}

.message.out.story-related .message-bubble {
  color: var(--ink);
  border-color: rgba(45, 142, 186, 0.58);
  background: #8ed8f0;
}

.message.comment-related .message-meta::before {
  content: "Commento";
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  padding: 2px 7px;
  border-radius: 999px;
  color: var(--amber);
  background: #f3e4cf;
  font-size: 11px;
  font-weight: 800;
}

.message.story-related .message-meta::before {
  content: "Storia";
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  padding: 2px 7px;
  border-radius: 999px;
  color: #207a9f;
  background: #dff3fb;
  font-size: 11px;
  font-weight: 800;
}

.comment-media-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 999px;
  color: var(--amber);
  background: #f3e4cf;
  text-decoration: none;
}

.story-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 999px;
  color: #207a9f;
  background: #dff3fb;
  text-decoration: none;
}

.comment-media-link:hover {
  color: white;
  background: var(--amber);
}

.story-link:hover {
  color: white;
  background: #207a9f;
}

.story-link svg,
.comment-media-link svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.message-buttons {
  display: grid;
  gap: 6px;
  margin-top: 7px;
}

.message.out .message-buttons {
  justify-items: end;
}

.message-button {
  display: grid;
  gap: 2px;
  min-width: min(280px, 100%);
  max-width: 420px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: var(--panel);
  font-size: 12px;
  box-shadow: 0 6px 18px rgba(55, 48, 37, 0.08);
}

.message-button.clicked {
  border-color: rgba(29, 111, 82, 0.36);
  background: var(--green-soft);
}

.message-button-title,
.message-button-status {
  font-weight: 800;
}

.message-button-url {
  min-width: 0;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.message-button.clicked .message-button-status {
  color: var(--green);
}

.message-meta {
  margin-top: 5px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.message.out .message-meta {
  justify-content: flex-end;
}

.message-status {
  font-weight: 800;
}

.message-status.read {
  color: var(--green);
}

.message-status.error {
  color: var(--red);
}

.reply-bar {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 16px 26px 22px;
  border-top: 1px solid var(--line);
  background: rgba(255, 253, 248, 0.72);
}

textarea,
input,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: var(--panel);
  outline: none;
}

textarea:focus,
input:focus,
select:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(29, 111, 82, 0.14);
}

textarea {
  resize: vertical;
}

.reply-bar textarea {
  min-height: 48px;
  max-height: 160px;
  padding: 12px;
}

.reply-bar button {
  align-self: end;
  min-width: 88px;
  height: 48px;
  padding: 0 18px;
}

.rule-form {
  display: grid;
  gap: 16px;
  padding: 20px 22px 24px;
}

.automation-editor-grid {
  display: grid;
  grid-template-columns: minmax(360px, 1.04fr) minmax(320px, 0.96fr);
  gap: 18px;
  align-items: start;
}

.automation-main-fields,
.automation-surface-fields {
  display: grid;
  gap: 12px;
}

.automation-surface-fields {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(236, 230, 218, 0.38), rgba(255, 253, 248, 0.78));
}

.legacy-channel-field {
  display: none;
}

.surface-picker {
  display: grid;
  gap: 8px;
}

.surface-picker > span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.surface-buttons {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.surface-button {
  display: grid;
  justify-items: center;
  gap: 4px;
  position: relative;
  min-height: 104px;
  padding: 10px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: var(--panel);
  font-weight: 800;
  opacity: 1;
}

.surface-button::before {
  content: "";
  position: absolute;
  inset: 7px 7px auto;
  height: 4px;
  border-radius: 999px;
  background: #d8d2c6;
}

.surface-button.active {
  color: white;
  box-shadow: 0 0 0 3px rgba(29, 111, 82, 0.14);
}

.surface-button.active::before {
  background: currentColor;
  opacity: 0.58;
}

.surface-button[data-surface="messages"].active {
  border-color: var(--green);
  background: var(--green);
}

.surface-button[data-surface="stories"].active {
  border-color: var(--cyan);
  background: var(--cyan);
}

.surface-button[data-surface="comments"].active {
  border-color: var(--amber);
  background: var(--amber);
}

.surface-icon {
  font-size: 20px;
  line-height: 1;
}

.surface-button small {
  padding: 2px 7px;
  border-radius: 999px;
  color: var(--muted);
  background: #ece6da;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
}

.surface-button.active small {
  color: var(--ink);
  background: rgba(255, 253, 248, 0.82);
}

.surface-summary {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.comment-action-fields {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid rgba(179, 107, 18, 0.24);
  border-radius: 8px;
  background: rgba(243, 228, 207, 0.58);
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

label input,
label select,
label textarea {
  padding: 10px 11px;
  color: var(--ink);
  font-weight: 500;
}

.button-builder {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(215, 234, 223, 0.44);
}

.mini-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.mini-title small {
  font-weight: 700;
}

.link-button-row {
  display: grid;
  grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr);
  gap: 8px;
}

.link-button-row input {
  padding: 10px 11px;
}

.split-row {
  gap: 10px;
}

.split-row > label {
  flex: 1;
}

.form-footer {
  justify-content: space-between;
  gap: 12px;
}

.switch-line {
  display: flex;
  grid-template-columns: none;
  align-items: center;
  gap: 8px;
}

.switch-line input {
  width: 18px;
  height: 18px;
}

.priority-field {
  width: 116px;
}

.button-row {
  gap: 8px;
}

.button-row button {
  flex: 1;
  padding: 10px 12px;
}

.ghost-button {
  color: var(--ink);
  background: #ece6da;
  font-weight: 800;
}

.rule-item {
  display: grid;
  gap: 6px;
  cursor: pointer;
}

.rule-item:hover {
  border-color: var(--green);
}

.rule-item.active {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(29, 111, 82, 0.12);
}

.rule-actions {
  position: absolute;
  right: 8px;
  bottom: 8px;
}

.rule-actions button {
  padding: 0;
  font-weight: 800;
}

.rule-item {
  position: relative;
  padding: 12px 42px 12px 12px;
  box-shadow: none;
}

.rule-title-block {
  min-width: 0;
}

.rule-status {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.rule-status.enabled {
  color: var(--green);
}

.rule-status.disabled {
  color: var(--red);
}

.icon-danger {
  display: inline-grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border-radius: 8px;
  color: var(--muted);
  background: transparent;
}

.icon-danger:hover {
  color: white;
  background: var(--red);
}

.icon-danger svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

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

.configured-buttons {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.button-chip {
  max-width: 100%;
  padding: 5px 8px;
  border: 1px solid rgba(29, 111, 82, 0.22);
  border-radius: 999px;
  color: var(--green);
  background: var(--green-soft);
  font-size: 12px;
  font-weight: 800;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.empty-state {
  margin: auto;
  color: var(--muted);
  text-align: center;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: 420px;
  padding: 12px 14px;
  border-radius: 8px;
  color: white;
  background: var(--ink);
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: none;
  place-items: center;
  padding: 22px;
  background: rgba(29, 37, 34, 0.42);
}

.modal-backdrop.show {
  display: grid;
}

.confirm-modal {
  display: grid;
  gap: 12px;
  width: min(420px, 100%);
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.confirm-modal h2 {
  font-size: 20px;
}

.confirm-modal p {
  color: var(--muted);
  line-height: 1.4;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

.modal-actions button {
  min-width: 96px;
  padding: 10px 12px;
  border-radius: 8px;
  font-weight: 800;
}

.modal-actions a.ghost-button {
  display: inline-flex;
  align-items: center;
  min-width: 96px;
  padding: 10px 12px;
  border-radius: 8px;
  font-weight: 800;
  text-decoration: none;
}

.detail-actions {
  justify-content: space-between;
  padding-top: 4px;
  border-top: 1px solid var(--line);
}

.detail-warning {
  padding: 10px 12px;
  border: 1px solid rgba(181, 123, 42, 0.28);
  border-radius: 8px;
  color: var(--ink);
  background: rgba(181, 123, 42, 0.12);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.35;
}

.danger-button {
  color: white;
  background: var(--red);
}

@media (max-width: 1180px) {
  .inbox-view {
    grid-template-columns: 320px minmax(0, 1fr);
  }

  .automation-editor-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  body {
    overflow: auto;
  }

  .app-shell {
    display: block;
    height: auto;
    overflow: visible;
  }

  .app-header {
    grid-template-columns: 1fr auto;
    height: auto;
  }

  .top-nav {
    grid-column: 1 / -1;
    width: 100%;
    overflow-x: auto;
  }

  .nav-button {
    flex: 0 0 auto;
    min-width: 0;
  }

  .app-view.active,
  .inbox-view,
  .automations-view,
  .accounts-view,
  .users-view {
    display: block;
    height: auto;
    padding: 0;
  }

  .management-page {
    width: 100%;
  }

  .management-header {
    align-items: stretch;
    grid-template-columns: 1fr;
    min-height: 160px;
    border-left: 0;
    border-right: 0;
    border-radius: 0;
  }

  .management-summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    padding: 0 14px;
  }

  .management-grid {
    grid-template-columns: 1fr;
    padding: 0 14px 18px;
  }

  .management-card {
    min-height: auto;
  }

  .account-card .detail-list,
  .user-card .detail-list {
    grid-template-columns: 1fr;
  }

  .side-rail,
  .thread-panel,
  .automation-sidebar,
  .automation-panel {
    min-height: auto;
    height: auto;
    border-left: 0;
    border-right: 0;
  }

  .conversation-list {
    max-height: 360px;
  }

  .thread-panel {
    min-height: 620px;
  }

  .reply-bar {
    grid-template-columns: 1fr;
  }

  .reply-bar button {
    width: 100%;
  }

  .surface-buttons,
  .link-button-row,
  .security-grid {
    grid-template-columns: 1fr;
  }
}

/* Compact admin pages: tables + modal detail */
.accounts-view.app-view.active,
.users-view.app-view.active {
  display: block;
  height: 100%;
}

.accounts-view,
.users-view {
  padding: 16px;
}

.accounts-view .management-page,
.users-view .management-page {
  display: block;
  gap: 10px;
  width: min(1280px, 100%);
  height: auto;
  min-height: 0;
  margin: 0 auto;
}

.management-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 0;
  padding: 10px 12px;
  overflow: visible;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: rgba(255, 253, 248, 0.88);
  box-shadow: none;
}

.management-header::before {
  display: none;
}

.management-header h2 {
  margin: 0;
  font-size: 20px;
  line-height: 1.1;
}

.management-header p {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.management-header .text-button {
  min-width: 0;
  padding: 9px 12px;
  color: white;
  background: var(--green);
  box-shadow: none;
}

.management-toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  height: 28px;
  min-height: 0;
  margin: 0 0 6px;
}

.management-toolbar .text-button {
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  height: 28px;
  min-height: 28px;
  max-height: 28px;
  padding: 0 10px;
  border-radius: 6px;
  font-size: 12px;
  line-height: 1;
  text-decoration: none;
}

.management-summary,
.management-grid {
  display: none;
}

.management-table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.9);
}

.management-table {
  width: 100%;
  min-width: 880px;
  border-collapse: collapse;
}

.management-table th,
.management-table td {
  padding: 11px 12px;
  border-bottom: 1px solid rgba(217, 212, 201, 0.78);
  text-align: left;
  vertical-align: middle;
}

.management-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  color: var(--muted);
  background: #ece6da;
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.management-table tbody tr:hover {
  background: rgba(215, 234, 223, 0.24);
}

.management-table tbody tr.selected-row {
  background: rgba(215, 234, 223, 0.42);
}

.management-table tbody tr:last-child td {
  border-bottom: 0;
}

.management-table td {
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
}

.management-table td strong,
.management-table td span {
  display: block;
  min-width: 0;
}

.management-table td strong {
  font-size: 14px;
  font-weight: 900;
}

.management-table td > span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.management-table .table-state,
.management-table .table-role {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.management-table .table-state::before,
.management-table .table-role::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--muted);
}

.management-table .table-state.active,
.management-table .table-role.admin {
  color: var(--green);
}

.management-table .table-state.active::before,
.management-table .table-role.admin::before {
  background: var(--green);
}

.management-table .table-state.paused {
  color: var(--red);
}

.management-table .table-state.paused::before {
  background: var(--red);
}

.management-table .table-state.warning {
  color: var(--amber);
}

.management-table .table-state.warning::before {
  background: var(--amber);
}

.table-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.table-actions .ghost-button {
  padding: 7px 9px;
}

.table-empty {
  height: 120px;
  color: var(--muted);
  text-align: center;
}

.detail-modal {
  width: min(620px, calc(100vw - 32px));
}

.detail-modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.detail-modal-header h2 {
  margin-top: 2px;
}

.detail-modal-body {
  display: grid;
  gap: 16px;
}

.modal-detail-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 0;
}

.modal-detail-list div {
  min-width: 0;
  padding: 10px;
  border: 1px solid rgba(217, 212, 201, 0.78);
  border-radius: 8px;
  background: rgba(247, 244, 238, 0.72);
}

.modal-detail-list dt {
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.modal-detail-list dd {
  margin: 3px 0 0;
  overflow-wrap: anywhere;
  font-size: 13px;
  font-weight: 800;
}

.modal-subsection {
  display: grid;
  gap: 8px;
}

.modal-subsection h3 {
  margin: 0;
  font-size: 14px;
}

.modal-chip-list {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

@media (max-width: 760px) {
  .accounts-view,
  .users-view {
    padding: 0;
  }

  .management-header {
    display: grid;
    grid-template-columns: 1fr;
    align-items: start;
    min-height: 0;
    padding: 12px 14px;
    border-left: 0;
    border-right: 0;
    border-radius: 0;
  }

  .management-table-wrap {
    border-left: 0;
    border-right: 0;
    border-radius: 0;
  }

  .management-toolbar {
    height: 28px;
    margin: 8px 14px 6px;
    padding: 0;
  }

  .modal-detail-list {
    grid-template-columns: 1fr;
  }
}
