:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-strong: #f9fbfd;
  --text: #18212f;
  --muted: #667085;
  --line: #d8dee8;
  --accent: #0f6cbd;
  --accent-dark: #0a4f8a;
  --green: #168a5b;
  --red: #c2413b;
  --shadow: 0 16px 40px rgba(18, 32, 53, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 380px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  border-right: 1px solid var(--line);
  background: #eef3f7;
  padding: 22px;
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 20px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  font-weight: 800;
  font-size: 24px;
}

h1,
h2,
p {
  margin: 0;
}

.brand h1 {
  font-size: 20px;
  line-height: 1.2;
}

.brand p,
.hint,
.metric-label,
.eyebrow {
  color: var(--muted);
  font-size: 12px;
}

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

.panel {
  padding: 16px;
  margin-bottom: 14px;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.section-title h2,
.toolbar h2 {
  font-size: 16px;
  line-height: 1.25;
}

.field {
  display: grid;
  gap: 7px;
  margin-bottom: 12px;
}

.field span {
  color: var(--muted);
  font-size: 12px;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-strong);
  color: var(--text);
  outline: none;
}

input {
  height: 38px;
  padding: 0 11px;
}

textarea {
  min-height: 170px;
  resize: vertical;
  padding: 11px;
  line-height: 1.45;
}

input:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 108, 189, 0.12);
}

.primary-btn,
.secondary-btn,
.icon-btn {
  border-radius: 6px;
  min-height: 36px;
}

.primary-btn {
  background: var(--accent);
  color: white;
  padding: 0 16px;
  font-weight: 700;
}

.primary-btn:hover {
  background: var(--accent-dark);
}

.secondary-btn {
  background: #e8f1fb;
  color: var(--accent-dark);
  padding: 0 12px;
  font-weight: 700;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 36px;
  background: #e7edf4;
  color: var(--text);
  font-weight: 800;
}

.icon-btn.danger {
  color: var(--red);
}

.row-actions,
.toolbar-actions {
  display: flex;
  align-items: end;
  gap: 10px;
}

.main {
  padding: 24px;
  overflow: hidden;
}

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

.compact {
  width: 92px;
  margin: 0;
}

.status-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1px;
  overflow: hidden;
  margin-bottom: 16px;
}

.status-strip > div {
  display: grid;
  gap: 5px;
  padding: 14px 16px;
  background: var(--surface);
}

.status-strip strong {
  font-size: 18px;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(330px, 40%) minmax(0, 1fr);
  gap: 16px;
  height: calc(100vh - 166px);
  min-height: 520px;
}

.mail-list-wrap,
.mail-detail {
  min-height: 0;
  overflow: auto;
}

.mail-list-wrap {
  padding: 14px;
}

.mail-detail {
  padding: 18px;
}

.sticky-title {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--surface);
  padding-bottom: 10px;
}

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

.account-card,
.mail-card {
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
}

.account-card {
  display: grid;
  gap: 6px;
  padding: 11px;
}

.account-card.active,
.mail-card.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 108, 189, 0.11);
}

.account-meta,
.mail-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.token-ok {
  color: var(--green);
  font-weight: 700;
}

.token-miss {
  color: var(--red);
  font-weight: 700;
}

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

.mail-card {
  padding: 12px;
}

.mail-card h3 {
  margin: 0 0 7px;
  font-size: 14px;
  line-height: 1.35;
}

.mail-card p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

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

.detail-empty {
  min-height: calc(100% - 48px);
}

.mail-body {
  line-height: 1.7;
  overflow-wrap: anywhere;
}

.mail-body iframe {
  width: 100%;
  min-height: 520px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

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

.detail-header h3 {
  margin: 0 0 10px;
  font-size: 20px;
  line-height: 1.3;
}

.code-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 9px;
  border-radius: 6px;
  background: #eaf7ef;
  color: #0f6b45;
  font-weight: 800;
  margin: 4px 6px 4px 0;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  max-width: min(420px, calc(100vw - 40px));
  padding: 12px 14px;
  border-radius: 8px;
  background: #18212f;
  color: white;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

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

@media (max-width: 980px) {
  .app-shell,
  .content-grid {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .main {
    overflow: visible;
  }

  .content-grid {
    height: auto;
  }
}

@media (max-width: 620px) {
  .sidebar,
  .main {
    padding: 16px;
  }

  .toolbar,
  .toolbar-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .compact {
    width: 100%;
  }

  .status-strip {
    grid-template-columns: 1fr;
  }
}
