:root {
  --canvas: #111412;
  --surface: #181c19;
  --surface-raised: #202520;
  --surface-hover: #282e28;
  --line: #343a34;
  --line-strong: #4b544b;
  --text: #f1f3ed;
  --text-soft: #b6bcb2;
  --text-muted: #7d867b;
  --accent: #53b9a1;
  --accent-deep: #057864;
  --blue: #78a7e8;
  --amber: #e5b86a;
  --danger: #e59680;
  --shadow: 0 14px 32px rgba(0, 0, 0, 0.18);
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--canvas);
  color: var(--text);
}

button,
input,
select { font: inherit; }

button { -webkit-tap-highlight-color: transparent; }

.app-shell { min-height: 100vh; }

.topbar {
  height: 58px;
  padding: 0 20px;
  border-bottom: 1px solid var(--line);
  background: #151915;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: var(--text);
  text-decoration: none;
  font-size: 15px;
  font-weight: 680;
  letter-spacing: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  color: #b9f1d6;
  background: #075f50;
  border: 1px solid #16806d;
  border-radius: 6px;
}

.brand-mark svg { width: 17px; height: 17px; }

.topbar-status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--text-soft);
  font-size: 12px;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px rgba(83, 185, 161, 0.12);
}

.topbar-status.waiting .status-dot { background: var(--amber); box-shadow: 0 0 0 3px rgba(229, 184, 106, 0.12); }

.workspace {
  display: grid;
  grid-template-columns: 284px minmax(260px, 360px) minmax(0, 1fr);
  min-height: calc(100vh - 58px);
}

.mailbox-controls,
.inbox-panel { border-right: 1px solid var(--line); }

.mailbox-controls {
  padding: 24px 18px;
  background: #151915;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.control-heading { display: grid; gap: 5px; }

.eyebrow {
  margin: 0;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

h1,
h2,
p { margin: 0; }

h1,
h2 { letter-spacing: 0; }

h1 { font-size: 20px; line-height: 1.2; font-weight: 680; }

h2 { font-size: 17px; line-height: 1.25; font-weight: 670; }

.address-field {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 38px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  overflow: visible;
  background: var(--surface);
}

#email-input {
  min-width: 0;
  height: 40px;
  padding: 0 10px;
  color: var(--text);
  background: transparent;
  border: 0;
  outline: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
}

.icon-button {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 0;
  color: var(--text-soft);
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  cursor: pointer;
  transition: color 160ms ease, border-color 160ms ease, background 160ms ease, transform 160ms ease;
}

.address-field .icon-button { border-width: 0 0 0 1px; border-radius: 0; }

.icon-button svg { width: 18px; height: 18px; }

.icon-button:hover,
.icon-button:focus-visible {
  color: var(--text);
  background: var(--surface-hover);
  border-color: var(--line-strong);
  outline: 0;
}

.icon-button:active { transform: scale(0.96); }

.icon-button[data-tooltip]::after {
  position: absolute;
  z-index: 4;
  top: calc(100% + 8px);
  left: 50%;
  padding: 6px 8px;
  color: var(--text);
  background: #060806;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  box-shadow: var(--shadow);
  content: attr(data-tooltip);
  font-size: 11px;
  line-height: 1;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -3px);
  transition: opacity 120ms ease, transform 120ms ease;
}

.icon-button[data-tooltip]:hover::after,
.icon-button[data-tooltip]:focus-visible::after { opacity: 1; transform: translate(-50%, 0); }

.toolbar { display: flex; gap: 8px; }

.is-refreshing .refresh-symbol { animation: rotate 350ms linear; }

@keyframes rotate { to { transform: rotate(360deg); } }

.address-form {
  display: grid;
  gap: 13px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}

.field-group { display: grid; gap: 7px; }

label {
  color: var(--text-soft);
  font-size: 12px;
  font-weight: 580;
}

select,
.field-group input {
  width: 100%;
  height: 38px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  outline: 0;
}

select { padding: 0 9px; cursor: pointer; }

.field-group input { padding: 0 10px; }

select:focus,
.field-group input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(83, 185, 161, 0.12); }

.primary-button {
  height: 38px;
  color: #06281f;
  background: var(--accent);
  border: 1px solid #71cdb8;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: background 160ms ease, transform 160ms ease;
}

.primary-button:hover,
.primary-button:focus-visible { background: #74cdb8; outline: 0; }
.primary-button:active { transform: translateY(1px); }

.retention-note {
  margin-top: auto;
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.45;
}

.inbox-panel {
  min-height: 0;
  padding: 23px 12px 12px;
  background: var(--canvas);
  display: flex;
  flex-direction: column;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 7px 18px;
}

.panel-header > div { display: grid; gap: 5px; }

.inbox-status {
  padding: 4px 7px;
  color: var(--text-muted);
  background: #20251f;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 11px;
  font-weight: 620;
  white-space: nowrap;
}

.inbox-status.active { color: #b5ead8; border-color: #276b5b; background: #163b32; }
.inbox-status.waiting { color: #f0d39a; border-color: #765c2f; background: #352d1c; }

.email-list {
  display: grid;
  align-content: start;
  gap: 5px;
  min-height: 0;
  overflow-y: auto;
  padding: 0 3px 8px;
  scrollbar-color: var(--line-strong) transparent;
}

.email-item {
  width: 100%;
  display: grid;
  gap: 6px;
  padding: 12px;
  color: var(--text);
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  overflow: hidden;
  transition: background 140ms ease, border-color 140ms ease;
}

.email-item:hover { background: #1b201c; border-color: #2d342d; }
.email-item.active { background: #1a342d; border-color: #347d6b; }
.email-item:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.item-meta { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-width: 0; }
.item-sender { min-width: 0; overflow: hidden; color: var(--text-soft); font-size: 12px; font-weight: 630; text-overflow: ellipsis; white-space: nowrap; }
.item-time { flex: 0 0 auto; color: var(--text-muted); font-size: 11px; }
.item-subject { overflow: hidden; font-size: 13px; font-weight: 650; text-overflow: ellipsis; white-space: nowrap; }
.item-preview { overflow: hidden; color: var(--text-muted); font-size: 12px; line-height: 1.35; text-overflow: ellipsis; white-space: nowrap; }

.empty-state {
  min-height: 180px;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 12px;
  padding: 24px;
  color: var(--text-muted);
  text-align: center;
  font-size: 13px;
  line-height: 1.5;
}

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid #35403a;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: rotate 700ms linear infinite;
}

.reader-panel {
  min-width: 0;
  min-height: 0;
  background: #171b18;
  display: flex;
  flex-direction: column;
}

.reader-placeholder {
  flex: 1;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 10px;
  padding: 24px;
  color: var(--text-muted);
  text-align: center;
}

.reader-placeholder h2 { color: var(--text-soft); font-size: 16px; }
.reader-placeholder p { max-width: 280px; font-size: 13px; line-height: 1.5; }

.empty-mail-icon {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin-bottom: 4px;
  color: var(--blue);
  background: #1a2930;
  border: 1px solid #304b55;
  border-radius: 6px;
}

.empty-mail-icon svg { width: 24px; height: 24px; }

.reader-content {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 0;
  height: 100%;
}

.message-header {
  display: grid;
  gap: 17px;
  padding: 24px 28px 20px;
  border-bottom: 1px solid var(--line);
  background: #181d19;
}

.message-header h2 { font-size: 19px; word-break: break-word; }

.message-meta {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(0, 1.5fr) minmax(110px, 0.8fr);
  gap: 14px;
  margin: 0;
}

.message-meta div { min-width: 0; }
.message-meta dt { margin-bottom: 4px; color: var(--text-muted); font-size: 10px; font-weight: 650; letter-spacing: 0.05em; text-transform: uppercase; }
.message-meta dd { margin: 0; overflow: hidden; color: var(--text-soft); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }

#html-frame { width: 100%; min-height: 0; height: 100%; border: 0; background: #fff; }
.hidden { display: none; }

.toast {
  position: fixed;
  z-index: 10;
  right: 18px;
  bottom: 18px;
  padding: 10px 12px;
  color: var(--text);
  background: #242a24;
  border: 1px solid #4e5950;
  border-radius: 6px;
  box-shadow: var(--shadow);
  font-size: 13px;
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.hidden { opacity: 0; pointer-events: none; transform: translateY(8px); }

@media (max-width: 920px) {
  .workspace { grid-template-columns: 250px minmax(230px, 320px) minmax(0, 1fr); }
  .mailbox-controls { padding: 20px 14px; }
  .message-header { padding: 20px; }
  .message-meta { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 720px) {
  body { min-height: 100vh; }
  .topbar { padding: 0 14px; }
  .topbar-status span:last-child { display: none; }
  .workspace { display: block; min-height: auto; }
  .mailbox-controls,
  .inbox-panel { border-right: 0; border-bottom: 1px solid var(--line); }
  .mailbox-controls { gap: 16px; }
  .retention-note { margin-top: 0; }
  .inbox-panel { min-height: 290px; }
  .email-list { max-height: 360px; }
  .reader-panel { min-height: 520px; }
  .message-meta { grid-template-columns: 1fr; gap: 9px; }
  .message-header { gap: 15px; }
}

@media (max-width: 390px) {
  .brand { font-size: 14px; }
  .mailbox-controls { padding: 18px 12px; }
  .message-header { padding: 18px 14px; }
}
