:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --panel: #ffffff;
  --panel-alt: #eef4f1;
  --text: #1c241f;
  --muted: #66706a;
  --line: #d9ded8;
  --accent: #1f7a66;
  --accent-strong: #155b4c;
  --focus: #2c7be5;
  --danger: #b42318;
  --danger-bg: #fff0ed;
  --shadow: 0 18px 48px rgba(31, 45, 38, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

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

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

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

.login-panel {
  width: min(420px, 100%);
  display: grid;
  gap: 18px;
  padding: 28px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 30px;
  line-height: 1.15;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 650;
}

input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px 13px;
  color: var(--text);
  background: #fff;
  outline: none;
}

input:focus,
button:focus-visible {
  outline: 3px solid rgba(44, 123, 229, 0.22);
  outline-offset: 2px;
  border-color: var(--focus);
}

.primary-action,
.text-button,
.danger-button,
.icon-button,
.folder-button {
  border: 1px solid transparent;
  border-radius: 6px;
  min-height: 38px;
  transition: background 0.16s ease, border-color 0.16s ease, color 0.16s ease;
}

.primary-action {
  background: var(--accent);
  color: #fff;
  font-weight: 750;
  padding: 12px 16px;
}

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

.text-button {
  background: #fff;
  color: var(--text);
  border-color: var(--line);
  padding: 8px 12px;
}

.text-button:hover {
  background: var(--panel-alt);
}

.danger-button {
  background: var(--danger-bg);
  color: var(--danger);
  border-color: #ffd5cf;
  padding: 8px 12px;
}

.danger-button:hover {
  background: #ffe4df;
}

.icon-button {
  width: 38px;
  height: 38px;
  display: inline-grid;
  place-items: center;
  background: #fff;
  color: var(--text);
  border-color: var(--line);
  font-size: 22px;
  line-height: 1;
}

.icon-button:hover {
  background: var(--panel-alt);
}

.form-message {
  min-height: 20px;
  color: var(--danger);
  font-size: 14px;
}

.mail-view {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  min-height: 70px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

#account-email {
  display: block;
  max-width: min(52vw, 520px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.toolbar,
.pager,
.reader-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: 220px minmax(280px, 390px) minmax(0, 1fr);
}

.sidebar,
.message-column,
.reader {
  min-height: 0;
  border-right: 1px solid var(--line);
  background: var(--panel);
}

.sidebar {
  padding: 12px;
  overflow: auto;
}

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

.folder-button {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 11px;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.folder-button:hover,
.folder-button.active {
  background: var(--panel-alt);
}

.folder-button.active {
  color: var(--accent-strong);
  font-weight: 750;
}

.message-column {
  display: grid;
  grid-template-rows: auto 1fr;
}

.column-header {
  min-height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}

.column-header h2 {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 18px;
}

#page-label {
  min-width: 26px;
  color: var(--muted);
  text-align: center;
  font-size: 14px;
}

.message-list {
  min-height: 0;
  overflow: auto;
}

.message-item {
  width: 100%;
  display: grid;
  gap: 6px;
  padding: 13px 12px;
  background: #fff;
  border: 0;
  border-bottom: 1px solid var(--line);
  color: var(--text);
  text-align: left;
}

.message-item:hover,
.message-item.active {
  background: #eef6f8;
}

.message-item.unseen .message-subject,
.message-item.unseen .message-sender {
  font-weight: 800;
}

.message-row {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.message-sender,
.message-subject {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.message-date,
.message-size {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 12px;
}

.message-subject {
  color: var(--text);
  font-size: 14px;
}

.reader {
  display: grid;
  min-width: 0;
  background: #fbfcfb;
}

.reader-empty {
  align-self: center;
  justify-self: center;
  color: var(--muted);
}

.reader-content {
  min-height: 0;
  display: grid;
  grid-template-rows: auto auto 1fr;
}

.reader-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.reader-header h2 {
  margin-bottom: 8px;
  font-size: 22px;
  line-height: 1.25;
}

#message-meta {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.attachment-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 18px;
  background: #fff;
  border-bottom: 1px solid var(--line);
}

.attachment-list:empty {
  display: none;
}

.attachment-link {
  display: inline-flex;
  align-items: center;
  max-width: 280px;
  min-height: 34px;
  padding: 7px 10px;
  color: var(--accent-strong);
  background: var(--panel-alt);
  border: 1px solid #cfe0d8;
  border-radius: 6px;
  text-decoration: none;
}

.attachment-link span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#message-frame {
  width: 100%;
  height: 100%;
  min-height: 420px;
  border: 0;
  background: #fff;
}

.empty-state,
.loading-state {
  padding: 22px;
  color: var(--muted);
}

[data-auth="checking"] .login-view,
[data-auth="signed-out"] .login-view {
  display: grid;
}

[data-auth="checking"] .mail-view,
[data-auth="signed-out"] .mail-view,
[data-auth="signed-in"] .login-view {
  display: none;
}

[data-auth="signed-in"] .mail-view {
  display: grid;
}

@media (max-width: 980px) {
  .workspace {
    grid-template-columns: 160px minmax(240px, 340px) minmax(0, 1fr);
  }

  .reader-header {
    flex-direction: column;
  }
}

@media (max-width: 760px) {
  .topbar {
    align-items: flex-start;
  }

  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: auto 320px minmax(520px, 1fr);
  }

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

  .folder-list {
    display: flex;
    overflow-x: auto;
  }

  .folder-button {
    width: auto;
    flex: 0 0 auto;
    white-space: nowrap;
  }

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

  .reader {
    border-right: 0;
  }

  .reader-actions {
    width: 100%;
    flex-wrap: wrap;
  }
}
