/* LowFat Mail — Global Stylesheet (~5KB target) */

/* ===== Reset ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
img { max-width: 100%; display: block; }
a { color: inherit; text-decoration: none; }
button { cursor: pointer; font: inherit; }
ul { list-style: none; }

/* ===== Variables / Color scheme ===== */
:root {
  --bg: #fff;
  --bg-alt: #f6f8fa;
  --bg-chrome: #f0f2f5;
  --bg-hover: #eef1f5;
  --border: #d0d7de;
  --text: #1f2328;
  --text-muted: #656d76;
  --accent: #0969da;
  --accent-hover: #0550ae;
  --unread-bg: #f0f7ff;
  --badge-unread: #0969da;
  --error: #cf222e;
  --radius: 6px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.08);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --bg-alt: #161b22;
    --bg-chrome: #10151c;
    --bg-hover: #1c2128;
    --border: #30363d;
    --text: #e6edf3;
    --text-muted: #8b949e;
    --accent: #58a6ff;
    --accent-hover: #79c0ff;
    --unread-bg: #121d2f;
    --badge-unread: #58a6ff;
    --error: #f85149;
  }
}

/* ===== Base ===== */
html, body { height: 100%; }
body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
}

/* ===== Site header ===== */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-chrome);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.site-header__inner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
}
.site-header__logo {
  font-weight: 700;
  font-size: 16px;
  color: var(--accent);
  margin-right: auto;
}
.site-header__account {
  color: var(--text-muted);
  font-size: 12px;
}
.site-header__logout {
  font-size: 12px;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 3px 8px;
  transition: background .15s;
}
.site-header__logout:hover { background: var(--bg-hover); }

/* ===== Main ===== */
.site-main { padding: 16px; min-width: 0; }

/* ===== Layout grid ===== */
.layout {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 0;
  min-height: calc(100vh - 49px);
}

/* ===== Sidebar ===== */
.sidebar {
  border-right: 1px solid var(--border);
  padding: 12px 0;
  background: var(--bg-chrome);
  overflow-y: auto;
}
.sidebar__compose {
  display: block;
  margin: 0 12px 12px;
  text-align: center;
}
.sidebar__list { margin: 0; padding: 0; }
.sidebar__item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 16px;
  font-size: 13px;
  color: var(--text);
  border-radius: 0 20px 20px 0;
  margin-right: 8px;
  transition: background .12s;
}
.sidebar__icon { display: flex; flex-shrink: 0; color: var(--text-muted); }
.sidebar__item--active .sidebar__icon { color: #fff; }
.sidebar__item:hover { background: var(--bg-hover); }
.sidebar__item--active { background: var(--accent); color: #fff; font-weight: 600; }
.sidebar__item--active:hover { background: var(--accent-hover); }
.sidebar__label { flex: 1; min-width: 0; }
.sidebar__count { font-size: 11px; color: var(--text-muted); font-weight: 600; }
.sidebar__item--active .sidebar__count { color: rgba(255,255,255,.8); }
.sidebar__divider {
  height: 1px;
  background: var(--border);
  margin: 8px 12px;
}
.sidebar__heading {
  padding: 6px 16px;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}

@media (max-width: 640px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { display: none; }
}

/* ===== Inbox layout ===== */
.inbox-layout { max-width: 1200px; margin: 0 auto; }
.inbox-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: -16px -16px 12px;
  padding: 10px 16px;
  background: var(--bg-chrome);
  border-bottom: 1px solid var(--border);
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  transition: background .15s, border-color .15s;
  white-space: nowrap;
}
.btn:hover { background: var(--bg-hover); }
.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn--primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn--ghost { background: transparent; border-color: transparent; }
.btn--ghost:hover { background: var(--bg-hover); border-color: var(--border); }
.btn--small { padding: 3px 8px; font-size: 12px; }
.btn--active { background: var(--bg-alt); font-weight: 600; }
.btn--disabled { opacity: .45; pointer-events: none; }

/* ===== Search bar ===== */
.search-bar {
  display: flex;
  flex: 1;
  gap: 6px;
}
.search-bar__input {
  flex: 1;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-alt);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color .15s;
}
.search-bar__input:focus { border-color: var(--accent); background: var(--bg); }
#reload-btn { font-size: 18px; line-height: 1; padding: 4px 8px; }

/* ===== Mail list / table ===== */
.mail-list { width: 100%; }
.mail-list__controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 0;
  margin-bottom: 4px;
}
.mail-list__count { color: var(--text-muted); font-size: 12px; }
.mail-list__size-selector { display: flex; align-items: center; gap: 4px; font-size: 12px; }

.mail-table {
  width: 100%;
  border-collapse: collapse;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  table-layout: fixed;
}
.mail-table__row {
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background .12s;
  background: var(--bg-alt);
}
.mail-table__row:last-child { border-bottom: none; }
.mail-table__row:hover { background: var(--bg-hover); }
.mail-table__row--unread { background: var(--bg); font-weight: 600; }
.mail-table__row--unread:hover { background: var(--bg-hover); }

.mail-table td { padding: 10px 8px; vertical-align: top; }
.mail-table__star { width: 28px; text-align: center; padding-left: 4px; padding-right: 0; }
.star { color: var(--border); font-size: 15px; }
.star--active { color: #f4b400; }
.mail-table__from { width: 160px; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-table__subject { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-table__subject-text { font-weight: inherit; }
.mail-table__snippet { color: var(--text-muted); font-weight: 400; font-size: 13px; }
.mail-table__badges { width: 60px; white-space: nowrap; }
.mail-table__date { width: 70px; text-align: right; color: var(--text-muted); font-size: 12px; white-space: nowrap; }
.mail-table__empty { text-align: center; padding: 32px; color: var(--text-muted); }

/* ===== Badges ===== */
.badge { display: inline-flex; align-items: center; justify-content: center; font-size: 11px; }
.badge--unread {
  width: 8px; height: 8px;
  background: var(--badge-unread);
  border-radius: 50%;
  margin-right: 4px;
}
.badge--count {
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0 5px;
  margin-left: 4px;
}

/* ===== Skeleton loading ===== */
@keyframes skeleton-pulse {
  0%, 100% { opacity: .15; }
  50% { opacity: .3; }
}
.mail-table__row--skeleton td { pointer-events: none; }
.skeleton-text {
  display: inline-block;
  height: .9em;
  border-radius: 4px;
  background: currentColor;
  animation: skeleton-pulse 1.2s ease-in-out infinite;
}
.mail-list__error {
  text-align: center;
  padding: 32px;
  color: var(--text-muted);
}
.mail-list__error .btn { margin-left: 8px; }

/* ===== Pagination ===== */
.mail-list__pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 16px;
}
.mail-list__page { color: var(--text-muted); font-size: 13px; }

/* ===== Thread layout ===== */
.thread-layout { max-width: 860px; margin: 0 auto; }
.thread-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  flex-wrap: wrap;
  gap: 8px;
}
.thread-actions { display: flex; gap: 4px; }

/* ===== Mail viewer ===== */
.mail-viewer {}
.mail-viewer__subject { font-size: 20px; font-weight: 700; margin-bottom: 16px; }
.mail-viewer--empty { color: var(--text-muted); padding: 32px; text-align: center; }
.message-list { display: flex; flex-direction: column; gap: 8px; }

.message-item {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.message-item--expanded {}

.message-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  cursor: pointer;
  user-select: none;
  background: var(--bg-alt);
  transition: background .12s;
}
.message-header:hover { background: var(--bg-hover); }
.message-header__from { font-weight: 600; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.message-header__meta { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.message-header__date { color: var(--text-muted); font-size: 12px; }
.message-header__toggle { color: var(--text-muted); font-size: 11px; }

.message-body { padding: 14px; }
.message-details {
  display: grid;
  grid-template-columns: 40px 1fr;
  gap: 2px 8px;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 10px;
}
.message-details dt { font-weight: 600; }

.message-body__image-notice { margin-bottom: 8px; }

/* ===== iFrame wrapper ===== */
.iframe-wrapper {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: #fff; /* always white inside iframe area */
}

/* ===== Attachments ===== */
.message-attachments { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
.message-attachments__title { font-size: 13px; font-weight: 600; margin-bottom: 8px; }
.attachment-list { display: flex; flex-wrap: wrap; gap: 10px; }
.attachment-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: 160px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px;
  background: var(--bg-alt);
}
.attachment-item__preview { border-radius: 4px; width: 144px; height: 100px; object-fit: cover; }
.attachment-item__info { display: flex; flex-direction: column; gap: 4px; }
.attachment-item__name { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachment-item__size { font-size: 11px; color: var(--text-muted); }

/* ===== Inline reply / Compose bar ===== */
.compose-bar {
  margin-top: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.compose-bar__trigger {
  width: 100%;
  text-align: left;
  padding: 12px 16px;
  color: var(--text-muted);
  border: none;
  background: var(--bg-alt);
  border-radius: var(--radius);
}
.compose-bar__trigger:hover { background: var(--bg-hover); }

.compose-bar--expanded .compose-bar__form { display: flex; flex-direction: column; }
.compose-bar__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--bg-alt);
  border-bottom: 1px solid var(--border);
}
.compose-bar__to { font-size: 13px; color: var(--text-muted); }
.compose-bar__actions { display: flex; gap: 6px; }

.compose-bar__body {
  width: 100%;
  padding: 12px;
  border: none;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  resize: vertical;
  outline: none;
}
.compose-bar__footer {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--bg-alt);
  border-top: 1px solid var(--border);
}
.compose-bar__attach-label { position: relative; }
.compose-bar__file-input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
}
.compose-bar__error { color: var(--error); font-size: 12px; flex: 1; }
.compose-bar .btn--primary { margin-left: auto; }

/* ===== Compose page ===== */
.compose-page {
  height: calc(100vh - 49px);
  display: flex;
  flex-direction: column;
}
