:root {
  --bg: #f7f8fa;
  --panel: #ffffff;
  --panel-muted: #f2f4f7;
  --text: #171717;
  --muted: #626976;
  --line: #d8dde5;
  --accent: #d4af37;
  --accent-dark: #8c6a16;
  --danger: #b42318;
  --success: #067647;
  --shadow: 0 14px 36px rgba(17, 24, 39, 0.08);
}

* {
  box-sizing: border-box;
}

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

body {
  color: var(--text);
  background: var(--bg);
  font-family: "Fira Sans", system-ui, sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 40px;
}

.topbar,
.query-panel,
.mail-list-panel,
.mail-detail-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 22px 24px;
}

.kicker {
  margin: 0 0 6px;
  color: var(--accent-dark);
  font-family: "Fira Code", monospace;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 1.72rem;
  line-height: 1.2;
}

h2 {
  font-size: 1.08rem;
  line-height: 1.25;
}

h3 {
  font-size: 1.18rem;
  line-height: 1.35;
}

.health-badge,
.limit-note,
.result-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-muted);
  color: var(--muted);
  font-family: "Fira Code", monospace;
  font-size: 0.8rem;
  white-space: nowrap;
}

.health-badge[data-state="loading"] {
  color: var(--accent-dark);
  border-color: rgba(212, 175, 55, 0.48);
  background: rgba(212, 175, 55, 0.12);
}

.query-panel {
  margin-top: 18px;
  padding: 22px;
}

.section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.section-heading.compact {
  margin-bottom: 14px;
}

.query-form {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 120px auto;
  gap: 12px;
  align-items: end;
}

.field {
  display: grid;
  gap: 8px;
  min-width: 0;
  color: var(--text);
  font-weight: 600;
}

.field span {
  font-size: 0.92rem;
}

input,
select {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 0 12px;
  outline: none;
}

input:focus-visible,
select:focus-visible,
button:focus-visible {
  outline: 2px solid rgba(212, 175, 55, 0.9);
  outline-offset: 2px;
}

.primary-button,
.secondary-button {
  min-height: 46px;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 0 16px;
  font-weight: 700;
  transition:
    background-color 180ms ease,
    border-color 180ms ease,
    color 180ms ease,
    transform 180ms ease;
}

.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--text);
  color: #fff;
}

.primary-button:hover {
  background: #2c2c2c;
}

.secondary-button {
  background: var(--panel-muted);
  border-color: var(--line);
  color: var(--text);
}

.secondary-button:hover {
  background: #e9edf3;
}

.button-icon {
  font-family: "Fira Code", monospace;
  line-height: 1;
}

.actions-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
  min-height: 34px;
}

.status-text {
  color: var(--muted);
  font-size: 0.94rem;
}

.status-text[data-type="success"] {
  color: var(--success);
}

.status-text[data-type="error"] {
  color: var(--danger);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(280px, 390px) minmax(0, 1fr);
  gap: 18px;
  margin-top: 18px;
}

.mail-list-panel,
.mail-detail-panel {
  min-width: 0;
  padding: 18px;
}

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

.mail-item {
  display: grid;
  gap: 5px;
  width: 100%;
  min-height: 88px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: inherit;
  text-align: left;
}

.mail-item:hover,
.mail-item.is-active {
  border-color: rgba(212, 175, 55, 0.72);
  background: rgba(212, 175, 55, 0.08);
}

.mail-subject {
  overflow: hidden;
  color: var(--text);
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mail-meta,
.mail-time {
  overflow: hidden;
  color: var(--muted);
  font-size: 0.9rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mail-detail {
  min-height: 420px;
}

.detail-header {
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.detail-meta {
  display: grid;
  gap: 8px;
  margin: 14px 0 0;
}

.detail-meta div {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr);
  gap: 10px;
}

.detail-meta dt {
  color: var(--muted);
  font-weight: 600;
}

.detail-meta dd {
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
}

.detail-body {
  margin: 16px 0 0;
  color: #252a31;
  font-family: "Fira Sans", system-ui, sans-serif;
  font-size: 0.96rem;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
}

.detail-html-frame {
  width: 100%;
  min-height: 520px;
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

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

@media (prefers-reduced-motion: reduce) {
  .primary-button,
  .secondary-button {
    transition: none;
  }
}

@media (max-width: 760px) {
  .app-shell {
    width: min(100% - 20px, 1180px);
    padding-top: 10px;
  }

  .topbar,
  .section-heading,
  .actions-row {
    align-items: stretch;
    flex-direction: column;
  }

  .query-form,
  .workspace {
    grid-template-columns: 1fr;
  }

  .primary-button,
  .secondary-button {
    width: 100%;
  }

  .mail-detail {
    min-height: 300px;
  }
}
