:root {
  --bg: #101214;
  --card: #171a1f;
  --card2: #20242b;
  --pre-bg: #0d0f12;
  --border: rgba(255, 255, 255, 0.13);
  --text: #f7f8f6;
  --muted: #a9b0ad;
  --accent: #2fd4c7;
  --accent2: #a7e85b;
  --warm: #f5b85c;
  --danger: #ff6b35;
  --button-primary-text: #09100f;
  --button-assist-bg: rgba(47, 212, 199, 0.12);
  --button-assist-border: rgba(47, 212, 199, 0.28);
  --button-assist-text: #f5f7fb;
  --shadow: rgba(0, 0, 0, 0.18);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  max-width: 100vw;
  margin: 0;
  overflow-x: hidden;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
  transition:
    background 160ms ease,
    color 160ms ease;
}

.smc-shell {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  padding: 6px;
  overflow-x: hidden;
}

.smc-shell > * {
  max-width: 100%;
  min-width: 0;
}

.smc-header {
  order: 1;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  margin-bottom: 6px;
  flex-wrap: wrap;
}

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

.smc-logo {
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
  object-fit: contain;
}

.smc-brand-copy {
  min-width: 0;
  overflow-wrap: anywhere;
}

.smc-kicker {
  margin: 0 0 2px 0;
  color: var(--accent2);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.14em;
}

h1 {
  margin: 0;
  font-size: 16px;
  line-height: 1.1;
}

h2 {
  margin: 0;
  font-size: 14px;
}

.smc-subtitle {
  margin: 2px 0 0 0;
  color: var(--muted);
  font-size: 11px;
}

.status-pill {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 7px;
  font-size: 11px;
  color: var(--accent2);
  background: rgba(0, 232, 162, 0.08);
  white-space: nowrap;
  flex: 1 1 100%;
  width: fit-content;
  max-width: fit-content;
}

.config-card,
.mail-card,
.compose-card,
.reply-card,
.control-strip,
.tools-card,
.output-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px;
  margin-bottom: 6px;
  box-shadow: 0 1px 0 var(--shadow);
}

.control-strip {
  order: 2;
}

.config-card {
  order: 3;
}

.mail-card {
  order: 4;
}

.reply-card {
  order: 5;
}

.quick-actions {
  order: 6;
}

.tools-card {
  order: 7;
}

.output-card {
  order: 8;
}

.compose-card {
  order: 9;
}

body.compose-mode .mail-card,
body.compose-mode .reply-card,
body.compose-mode .quick-actions,
body.compose-mode .tools-card {
  display: none;
}

body.compose-mode .compose-card {
  order: 4;
  border-color: rgba(47, 212, 199, 0.42);
}

body.compose-mode .output-card {
  order: 5;
}

.control-strip {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-items: center;
  gap: 5px;
}

.compact-strip {
  padding: 6px 7px;
}

.control-field {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 6px;
}

.control-field label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

.control-strip select {
  margin-bottom: 0;
  min-height: 30px;
  padding: 5px 8px;
}

summary {
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.2;
  list-style-position: inside;
}

.details-body {
  margin-top: 7px;
}

.config-card label,
.reply-card label,
.compose-card label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
}

.config-row {
  display: flex;
  gap: 6px;
}

input,
select,
textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 8px;
  background: var(--card2);
  color: var(--text);
}

textarea {
  min-height: 78px;
  resize: vertical;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 12px;
  line-height: 1.45;
}

select {
  margin-bottom: 8px;
}

.hint {
  color: var(--muted);
  font-size: 10px;
  margin: 5px 0 0 0;
}

.ref-line {
  margin-top: 6px;
  color: var(--accent2);
  font-family: Consolas, Monaco, monospace;
  font-size: 11px;
  overflow-wrap: anywhere;
}

.tone-field {
  margin: 8px 0 0 0;
  padding: 0;
  border: 0;
}

.tone-field legend {
  margin: 0 0 6px 0;
  padding: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.segmented-control {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
}

.compose-card .segment-option {
  position: relative;
  display: block;
  min-width: 0;
  margin: 0;
}

.compose-card .segment-option input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.compose-card .segment-option span {
  display: flex;
  min-height: 30px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 5px 6px;
  color: var(--text);
  background: var(--card2);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.15;
  text-align: center;
}

.compose-card .segment-option input:checked + span {
  border-color: transparent;
  color: var(--button-primary-text);
  background: linear-gradient(135deg, var(--accent), var(--accent2));
}

.compose-card .segment-option input:focus-visible + span {
  outline: 2px solid var(--accent2);
  outline-offset: 2px;
}

dl {
  margin: 0;
}

dt {
  color: var(--muted);
  font-size: 11px;
  margin-top: 5px;
}

dd {
  margin: 3px 0 0 0;
  font-size: 12px;
  overflow-wrap: anywhere;
  max-height: 30px;
  overflow: hidden;
}

.action-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px;
  margin-bottom: 6px;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow: hidden;
}

.compose-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px;
  margin-top: 6px;
  width: 100%;
}

.quick-actions {
  margin-bottom: 6px;
}

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

.tools-card .action-grid {
  margin-bottom: 0;
}

button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  border: 1px solid transparent;
  border-radius: 7px;
  padding: 6px 8px;
  min-height: 32px;
  color: var(--button-primary-text);
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  box-shadow: 0 1px 0 var(--shadow);
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  line-height: 1.2;
  overflow-wrap: anywhere;
  white-space: normal;
  transition:
    background 160ms ease,
    border-color 160ms ease,
    color 160ms ease,
    transform 100ms ease;
}

button:hover {
  transform: translateY(-1px);
  filter: brightness(1.05);
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--accent2);
  outline-offset: 2px;
}

button:active {
  transform: translateY(0);
}

button.assist {
  color: var(--button-assist-text);
  background: var(--button-assist-bg);
  border: 1px solid var(--button-assist-border);
}

button.secondary {
  color: var(--text);
  background: var(--card2);
  border: 1px solid var(--border);
}

.compact-button {
  width: auto;
  min-width: 72px;
  min-height: 28px;
  padding: 5px 8px;
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.output-card {
  overflow: hidden;
}

.output-card,
.output-card * {
  min-width: 0;
}

.output-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 5px;
  margin-bottom: 6px;
}

#operationStatus {
  color: var(--muted);
  font-size: 11px;
}

.output-tools {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: center;
  gap: 4px;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow: hidden;
}

.output-tool {
  width: 100%;
  max-width: 100%;
  min-height: 30px;
  padding: 5px 6px;
  white-space: normal;
}

#compactViewBtn {
  display: none;
}

#operationStatus {
  grid-column: 1 / -1;
}

pre {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-family: Consolas, Monaco, monospace;
  font-size: 12px;
  line-height: 1.45;
  color: var(--text);
  background: var(--pre-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px;
  min-height: 240px;
  max-height: none;
  overflow: auto;
}

body.wide-output-mode {
  overflow: hidden;
}

body.wide-output-mode .smc-shell {
  height: 100vh;
  padding: 0;
  overflow: hidden;
}

body.wide-output-mode .smc-shell > :not(.output-card) {
  display: none;
}

body.wide-output-mode .output-card {
  display: flex;
  flex-direction: column;
  height: 100vh;
  margin: 0;
  border: 0;
  border-radius: 0;
  padding: 10px;
}

body.wide-output-mode .output-header {
  flex: 0 0 auto;
}

body.wide-output-mode #compactViewBtn {
  display: block;
}

body.wide-output-mode pre {
  flex: 1 1 auto;
  min-height: 0;
  height: auto;
  max-height: none;
  font-size: 13px;
}

.help-tooltip {
  position: fixed;
  z-index: 9999;
  max-width: min(320px, calc(100vw - 18px));
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  background: var(--card2);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.28);
  font-size: 11px;
  line-height: 1.35;
  pointer-events: none;
}

@media (max-width: 420px) {
  .smc-shell {
    padding: 6px;
  }

  .smc-logo {
    width: 34px;
    height: 34px;
    flex-basis: 34px;
  }

  h1 {
    font-size: 16px;
  }

  .smc-subtitle,
  .smc-kicker {
    display: none;
  }

  .status-pill {
    padding: 5px 7px;
  }

  button {
    min-height: 31px;
  }

  pre {
    font-size: 11px;
    max-height: none;
  }
}

@media (max-width: 380px) {
  .action-grid,
  .compose-actions,
  .segmented-control {
    grid-template-columns: minmax(0, 1fr);
  }

}
