:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --panel: #ffffff;
  --line: #d9e0ea;
  --ink: #17202a;
  --muted: #687386;
  --accent: #1769aa;
  --accent-strong: #0e4f85;
  --ok: #188a5f;
  --danger: #c0392b;
  font-family: "Segoe UI", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-card {
  width: min(420px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 22px;
  display: grid;
  gap: 12px;
}

button,
input,
select,
textarea {
  font: inherit;
}

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

.sidebar {
  background: #26313d;
  color: #fff;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
}

.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  background: #fff;
  color: #26313d;
  border-radius: 8px;
  font-weight: 800;
}

.brand span,
.muted {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.sidebar .brand span {
  color: #bdc8d5;
}

.mailbox-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.sidebar-section {
  display: grid;
  gap: 8px;
}

.sidebar-section h2 {
  margin: 0;
  color: #bdc8d5;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.folder-list {
  display: grid;
  gap: 6px;
}

.folder-button {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 10px;
  color: #e8eef6;
  background: transparent;
  cursor: pointer;
}

.folder-button.active,
.folder-button:hover,
.sidebar-settings.active {
  background: #344252;
  border-color: #45576a;
}

.mailbox-button {
  width: 100%;
  display: grid;
  grid-template-columns: 12px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  color: #e8eef6;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 10px;
  text-align: left;
  cursor: pointer;
}

.mailbox-button.active,
.mailbox-button:hover {
  background: #344252;
  border-color: #45576a;
}

.mailbox-button strong,
.mailbox-button small {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-pill {
  display: inline-flex;
  width: fit-content;
  margin-top: 6px;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  color: #d9e4ef;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 10px;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
}

.workspace {
  padding: 22px;
  min-width: 0;
}

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

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 4px;
  font-size: 24px;
}

h2 {
  font-size: 16px;
  margin-bottom: 8px;
}

.topbar-actions,
.dialog-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.primary-button,
.secondary-button,
.ghost-button,
.icon-button {
  border: 1px solid transparent;
  border-radius: 8px;
  min-height: 38px;
  padding: 0 14px;
  cursor: pointer;
}

.primary-button {
  background: var(--accent);
  color: #fff;
}

.primary-button:hover {
  background: var(--accent-strong);
}

.secondary-button,
.ghost-button {
  background: #fff;
  border-color: var(--line);
  color: var(--ink);
}

.sidebar .ghost-button {
  border-color: #45576a;
  background: transparent;
  color: #e8eef6;
}

.sidebar-settings {
  margin-top: auto;
}

.icon-button {
  width: 36px;
  padding: 0;
  background: #fff;
  border-color: var(--line);
  font-size: 16px;
}

.search-input {
  width: 220px;
}

.auto-sync-select {
  width: 170px;
}

.compact-date-filter {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.compact-date-filter input {
  width: 150px;
}

.mail-view {
  display: grid;
  grid-template-columns: minmax(280px, 400px) minmax(360px, 1fr);
  gap: 16px;
  align-items: start;
}

.scheduler-panel {
  border: 1px solid #e7c7c2;
  background: #fff4f2;
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 12px;
}

.scheduler-failed-list {
  display: grid;
  gap: 6px;
  margin-top: 8px;
}

.scheduler-failed-item {
  display: grid;
  gap: 2px;
}

.scheduler-failed-item small {
  color: var(--muted);
}

.message-panel,
.detail-panel,
.settings-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 520px;
}

.panel-head {
  height: 52px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
}

.message-list {
  display: flex;
  flex-direction: column;
}

.message-row {
  display: grid;
  grid-template-columns: 34px 34px minmax(0, 1fr);
  align-items: stretch;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.message-row:hover,
.message-row.active {
  background: #eef6fd;
}

.message-select {
  width: 18px;
  align-self: start;
  justify-self: center;
  margin-top: 18px;
}

.star-button {
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 800;
  font-size: 18px;
}

.star-button.active {
  color: #b7791f;
}

.message-item {
  border: 0;
  background: transparent;
  text-align: left;
  padding: 14px 16px;
  cursor: pointer;
}

.message-row.unread strong {
  color: var(--ink);
  font-weight: 800;
}

.message-row.unread .message-meta {
  color: var(--accent);
  font-weight: 700;
}

.message-item strong {
  display: block;
  margin-bottom: 4px;
}

.message-item span:last-child {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.message-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 6px;
}

.bulk-toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  border-bottom: 1px solid var(--line);
  padding: 10px 12px;
  background: #f8fafc;
}

.bulk-toolbar span {
  color: var(--muted);
  font-size: 13px;
  margin-right: auto;
}

.undo-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-top: 1px solid var(--line);
  padding: 10px 12px;
  background: #eef6fd;
}

.detail-panel {
  padding: 22px;
}

.empty-state {
  min-height: 470px;
  display: grid;
  place-items: center;
  color: var(--muted);
}

.email-body {
  white-space: pre-wrap;
  line-height: 1.55;
  border-top: 1px solid var(--line);
  margin-top: 18px;
  padding-top: 18px;
}

.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 16px 0 0;
}

.danger-button {
  border-color: rgba(192, 57, 43, 0.28);
  color: var(--danger);
}

.attachment-list {
  display: grid;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-top: 16px;
  padding: 12px;
  background: #f8fafc;
}

.attachment-list strong {
  font-size: 13px;
}

.attachment-list span,
.attachment-list a {
  color: var(--muted);
  font-size: 13px;
}

.attachment-list a {
  text-decoration: none;
}

.attachment-list a:hover {
  color: var(--accent);
  text-decoration: underline;
}

.settings-view {
  display: grid;
}

.settings-grid {
  display: grid;
  grid-template-columns: minmax(340px, 1fr) minmax(340px, 0.9fr);
  gap: 16px;
  align-items: start;
}

.settings-card {
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

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

.stack,
.key-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: #344252;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 11px;
  background: #fff;
  color: var(--ink);
}

textarea {
  resize: vertical;
}

.compose-html-editor {
  min-height: 180px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 11px;
  background: #fff;
}

select[multiple] {
  min-height: 96px;
}

.checkbox-row,
.checkbox-line {
  display: flex;
  flex-direction: row;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.checkbox-row input,
.checkbox-line input {
  width: auto;
}

.action-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.two-cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.two-cols.compact {
  grid-template-columns: minmax(0, 1fr) 96px;
}

.mailbox-settings {
  padding-bottom: 20px;
  border-bottom: 1px solid var(--line);
}

.key-card,
.secret-box {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #f8fafc;
  margin-top: 12px;
  word-break: break-all;
}

.secret-box {
  border-color: #9abde0;
  background: #eef6fd;
}

.hidden {
  display: none;
}

dialog {
  border: 0;
  border-radius: 10px;
  padding: 0;
  width: min(720px, calc(100vw - 32px));
}

dialog::backdrop {
  background: rgba(15, 23, 42, 0.45);
}

.dialog-card {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

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

.dialog-head h2 {
  margin: 0;
  font-size: 20px;
}

.compose-card {
  width: min(760px, calc(100vw - 32px));
}

@media (max-width: 1380px) {
  .settings-grid {
    grid-template-columns: 1fr;
  }
}

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

  .sidebar {
    min-height: auto;
  }

  .mail-view,
  .settings-grid,
  .two-cols,
  .two-cols.compact {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .search-input {
    width: 100%;
  }

  .auto-sync-select {
    width: 100%;
  }

  .compact-date-filter {
    width: 100%;
    justify-content: space-between;
  }

  .compact-date-filter input {
    width: 100%;
  }
}
