:root {
  color-scheme: light;
  --bg: #f6f7f3;
  --panel: #ffffff;
  --ink: #1d2425;
  --muted: #66706a;
  --line: #dfe4dc;
  --accent: #1f7a5c;
  --accent-dark: #155b44;
  --warning: #9c5b16;
  --danger: #a63a32;
  --shadow: 0 18px 50px rgba(30, 43, 36, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(320px, 0.95fr) minmax(340px, 1.05fr);
  gap: 24px;
  width: min(1160px, calc(100vw - 32px));
  margin: 32px auto;
}

.composer,
.preview {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 28px;
}

.title-row,
.preview-header,
.send-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.draft-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.title-row {
  border: 1px solid rgba(223, 228, 220, 0.9);
  border-radius: 8px;
  background: linear-gradient(180deg, #ffffff 0%, #fbfcfa 100%);
  box-shadow: 0 10px 28px rgba(30, 43, 36, 0.08);
  padding: 12px 14px;
}

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

.brand-home-link {
  display: inline-flex;
  align-items: center;
  color: inherit;
  text-decoration: none;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.connect-button,
.menu-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #ffffff;
  color: var(--accent-dark);
  font-size: 0.82rem;
  font-weight: 800;
  padding: 0 12px;
  text-decoration: none;
}

.connect-button:hover,
.menu-link:hover {
  background: #f1f7f4;
}

.connect-button.connected,
.menu-link.connected {
  background: #f7fbf8;
  color: var(--muted);
  cursor: default;
}

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

.user-menu {
  position: relative;
  flex: 0 0 auto;
}

.user-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  min-width: 38px;
  min-height: 38px;
  border: 1px solid rgba(31, 122, 92, 0.22);
  border-radius: 999px;
  background: var(--accent);
  color: #ffffff;
  padding: 0;
  font-size: 0.95rem;
  font-weight: 900;
  box-shadow: 0 10px 22px rgba(31, 122, 92, 0.18);
  text-decoration: none;
}

.user-avatar:hover,
.user-avatar[aria-expanded="true"] {
  background: var(--accent-dark);
}

.user-menu-panel {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  z-index: 20;
  display: grid;
  gap: 8px;
  width: min(260px, calc(100vw - 48px));
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: var(--shadow);
  padding: 10px;
}

.user-menu-heading {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 800;
  padding: 4px 4px 10px;
}

.user-menu-heading span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-menu-initial {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  background: #eef7f2;
  color: var(--accent-dark);
  font-weight: 900;
}

.menu-link {
  justify-content: flex-start;
  width: 100%;
  min-height: 38px;
  border-radius: 8px;
  color: var(--ink);
  font-size: 0.9rem;
}

.user-menu-panel button.menu-link {
  border: 1px solid var(--line);
  background: #ffffff;
  cursor: pointer;
  padding: 0 12px;
  text-align: left;
}

.user-menu-panel button.menu-link:hover {
  background: #f1f7f4;
}

.danger-link {
  color: var(--danger);
}

.brand-logo {
  width: 178px;
  height: 62px;
  border-radius: 8px;
  flex: 0 0 auto;
  object-fit: contain;
}

.brand-copy {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.brand-subtitle,
.eyebrow {
  margin: 0;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  line-height: 1.08;
  letter-spacing: 0;
}

h1 {
  font-size: 1.35rem;
  font-weight: 850;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

h2 {
  font-size: 1.6rem;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-width: 0;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f7fbf8;
  color: var(--accent-dark);
  text-align: center;
  font-size: 0.82rem;
  font-weight: 700;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.9);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: #24b47e;
  box-shadow: 0 0 0 3px rgba(36, 180, 126, 0.14);
}

.status-pill.not-ready {
  border-color: rgba(166, 58, 50, 0.22);
  background: rgba(166, 58, 50, 0.08);
  color: var(--danger);
}

.status-pill.not-ready .status-dot {
  background: var(--danger);
  box-shadow: 0 0 0 3px rgba(166, 58, 50, 0.14);
}

.form-panel,
.draft-preview {
  display: grid;
  gap: 12px;
  margin-top: 28px;
}

.slider-group {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
  padding: 14px;
}

.profile-toggle {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  gap: 10px;
  align-items: flex-start;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
  color: var(--ink);
  cursor: pointer;
  padding: 13px 14px;
}

.profile-toggle input {
  width: 18px;
  height: 18px;
  margin: 2px 0 0;
  accent-color: var(--accent);
  box-shadow: none;
}

.profile-toggle span {
  display: grid;
  gap: 3px;
}

.profile-toggle small {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 650;
  line-height: 1.45;
}

.slider-head,
.scale-labels {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

output,
.scale-labels {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

label {
  color: var(--ink);
  font-size: 0.94rem;
  font-weight: 700;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
  color: var(--ink);
  font: inherit;
  line-height: 1.5;
  padding: 12px 14px;
  outline: none;
}

textarea {
  resize: vertical;
}

input[type="range"] {
  accent-color: var(--accent);
  cursor: pointer;
  padding: 0;
}

input:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(31, 122, 92, 0.14);
}

.copy-field {
  position: relative;
}

.copy-field input,
.copy-field textarea {
  padding-right: 54px;
}

.copy-icon-button {
  position: absolute;
  top: 8px;
  right: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  min-height: 34px;
  border: 1px solid rgba(31, 122, 92, 0.18);
  border-radius: 8px;
  background: #ffffff;
  color: var(--accent-dark);
  padding: 0;
  box-shadow: 0 6px 14px rgba(30, 43, 36, 0.06);
}

.copy-icon-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
}

.copy-icon-button:hover {
  border-color: var(--accent);
  background: #eef7f2;
  color: var(--accent-dark);
}

button {
  min-height: 46px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font: inherit;
  font-weight: 800;
  padding: 0 18px;
}

button:hover {
  background: var(--accent-dark);
}

button:disabled {
  cursor: wait;
  opacity: 0.65;
}

button.secondary {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

button.secondary:hover {
  background: #f1f4ef;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 420px;
  margin-top: 28px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
  padding: 24px;
}

.hidden {
  display: none;
}

.notice {
  min-height: 24px;
  margin-top: 18px;
  color: var(--muted);
  font-weight: 700;
}

.notice.error {
  color: var(--danger);
}

.notice.success {
  color: var(--accent-dark);
}

.history-panel {
  display: grid;
  gap: 14px;
  margin-top: 24px;
  border-top: 1px solid var(--line);
  padding-top: 22px;
}

.history-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
}

.history-head h2 {
  margin-top: 4px;
  font-size: 1.2rem;
}

.history-list {
  display: grid;
  gap: 10px;
}

.history-empty {
  margin: 0;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  font-weight: 700;
  padding: 14px;
}

.history-item {
  display: grid;
  gap: 5px;
  width: 100%;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
  color: var(--ink);
  padding: 12px 14px;
  text-align: left;
}

.history-item:hover {
  border-color: rgba(31, 122, 92, 0.35);
  background: #f1f7f4;
}

.history-item strong,
.history-meta,
.history-preview {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-item strong {
  font-size: 0.95rem;
}

.history-meta,
.history-preview {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.feedback-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
  padding: 12px 14px;
}

.feedback-panel p {
  margin: 0;
  color: var(--muted);
  font-weight: 800;
}

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

.feedback-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  min-width: 44px;
  border: 1px solid rgba(31, 122, 92, 0.24);
  background: #ffffff;
  color: var(--accent-dark);
  padding: 0 10px;
  box-shadow: 0 8px 18px rgba(30, 43, 36, 0.06);
}

.feedback-button svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

.feedback-button:hover,
.feedback-button.selected {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
  transform: translateY(-1px);
  box-shadow: 0 10px 22px rgba(31, 122, 92, 0.18);
}

.feedback-button:disabled {
  cursor: default;
  transform: none;
}

.auth-body {
  display: grid;
  place-items: center;
  padding: 28px 16px;
}

.auth-card {
  width: min(440px, 100%);
  padding: 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.auth-logo {
  width: 178px;
  height: 62px;
  object-fit: contain;
  margin-bottom: 22px;
}

.auth-card h1 {
  font-size: 2rem;
  margin-bottom: 8px;
}

.auth-copy,
.auth-switch {
  color: var(--muted);
  line-height: 1.6;
}

.auth-error {
  margin: 18px 0;
  padding: 12px 14px;
  border: 1px solid rgba(166, 58, 50, 0.22);
  border-radius: 8px;
  background: rgba(166, 58, 50, 0.08);
  color: var(--danger);
  font-weight: 700;
}

.auth-message {
  margin: 18px 0;
  padding: 12px 14px;
  border: 1px solid rgba(31, 122, 92, 0.22);
  border-radius: 8px;
  background: rgba(31, 122, 92, 0.08);
  color: var(--accent-dark);
  font-weight: 700;
}

.auth-form {
  display: grid;
  gap: 12px;
  margin-top: 22px;
}

.auth-form button {
  margin-top: 6px;
}

.auth-switch {
  margin: 22px 0 0;
  text-align: center;
}

.auth-switch a {
  color: var(--accent-dark);
  font-weight: 800;
}

.admin-button {
  color: var(--accent-dark);
}

.admin-shell {
  display: grid;
  gap: 24px;
  width: min(1060px, calc(100vw - 32px));
  margin: 32px auto;
}

.admin-header,
.admin-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 28px;
}

.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  background: linear-gradient(180deg, #ffffff 0%, #fbfcfa 100%);
}

.admin-actions {
  align-items: center;
  display: flex;
  gap: 10px;
}

.admin-metrics {
  display: grid;
  grid-template-columns: minmax(160px, 0.4fr) minmax(260px, 0.6fr);
  gap: 12px;
}

.admin-summary {
  display: inline-grid;
  gap: 6px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
}

.admin-summary strong {
  font-size: 2rem;
  line-height: 1;
}

.token-summary {
  gap: 10px;
}

.token-range-form {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.token-range-form label {
  font-size: 0.82rem;
  text-transform: uppercase;
}

.token-range-form select {
  width: auto;
  min-width: 140px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  font: inherit;
  font-weight: 700;
  padding: 9px 12px;
}

.metric-detail {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

.user-table-wrap {
  overflow-x: auto;
  margin-top: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.user-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

.user-table th,
.user-table td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.user-table th {
  background: #fbfcfa;
  color: var(--muted);
  font-size: 0.82rem;
  text-transform: uppercase;
}

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

.data-section {
  display: grid;
  gap: 14px;
}

.compact-table {
  min-width: 760px;
}

.compact-table th,
.compact-table td {
  vertical-align: top;
  font-size: 0.86rem;
}

.long-cell {
  max-width: 360px;
  white-space: pre-wrap;
}

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

.profile-card {
  display: grid;
  gap: 22px;
}

.profile-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
}

.profile-saved {
  margin: 0;
  border: 1px solid rgba(31, 122, 92, 0.2);
  border-radius: 999px;
  background: #eef7f2;
  color: var(--accent-dark);
  font-size: 0.82rem;
  font-weight: 800;
  padding: 7px 12px;
}

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

.profile-field {
  display: grid;
  gap: 8px;
}

.profile-wide {
  grid-column: 1 / -1;
}

.profile-save-button {
  width: fit-content;
  grid-column: 1 / -1;
}

.settings-panel {
  display: grid;
  align-content: start;
  gap: 10px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
}

.settings-panel h2 {
  font-size: 1.35rem;
}

.settings-button {
  width: fit-content;
  padding: 0 16px;
}

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

.legal-links {
  display: flex;
  justify-content: center;
  gap: 18px;
  width: min(1160px, calc(100vw - 32px));
  margin: -10px auto 32px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.legal-links a {
  color: inherit;
  text-decoration: none;
}

.legal-links a:hover {
  color: var(--accent-dark);
  text-decoration: underline;
}

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

  .composer,
  .preview {
    padding: 20px;
  }

  .send-row {
    align-items: stretch;
    flex-direction: column;
  }

  .title-row {
    align-items: center;
    flex-direction: row;
    padding: 12px;
  }

  .header-actions {
    align-items: center;
    justify-content: space-between;
    flex-direction: row;
  }

  .draft-actions {
    width: 100%;
  }

  .brand-lockup {
    align-items: center;
  }

  .brand-logo {
    width: 150px;
    height: 52px;
  }

  .status-pill,
  .connect-button,
  .send-row button {
    width: 100%;
  }

  .title-row .status-pill {
    width: auto;
  }

  .admin-header,
  .admin-actions {
    align-items: center;
    flex-direction: row;
  }

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

  .profile-card-head {
    flex-direction: column;
  }

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

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

}
