/* ============================================================
   Mail App — shared modern UI stylesheet
   ============================================================ */
:root {
  --bg: #0e1116;
  --bg-soft: #12161e;
  --surface: #171c26;
  --surface-2: #1d2430;
  --surface-3: #242c3b;
  --border: #262e3d;
  --border-soft: #1f2735;
  --text: #e7ebf2;
  --text-dim: #9aa4b8;
  --text-faint: #66708a;
  --accent: #4f7cff;
  --accent-soft: rgba(79, 124, 255, 0.16);
  --accent-hover: #3f6bf0;
  --danger: #ff5c6c;
  --star: #f5b83d;
  --unread-dot: #4f7cff;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; cursor: pointer; }
input, select { font-family: inherit; }

/* ---------- App shell ---------- */
.app {
  display: grid;
  grid-template-columns: 260px 1fr;
  grid-template-rows: 64px 1fr;
  grid-template-areas:
    "header header"
    "sidebar main";
  height: 100vh;
}

.app.no-sidebar {
  grid-template-columns: 1fr;
  grid-template-areas:
    "header"
    "main";
}

/* ---------- Header ---------- */
.header {
  grid-area: header;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 20px;
  background: var(--bg-soft);
  border-bottom: 1px solid var(--border);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 16px;
  white-space: nowrap;
}
.brand .logo {
  width: 34px; height: 34px;
  border-radius: 9px;
  background: linear-gradient(135deg, #4f7cff, #7c5cff);
  display: grid; place-items: center;
  color: #fff; font-size: 16px;
}
.search-wrap {
  flex: 1;
  position: relative;
  max-width: 680px;
}
.search-wrap svg {
  position: absolute; left: 12px; top: 50%;
  transform: translateY(-50%);
  color: var(--text-faint);
}
.search-wrap input {
  width: 100%;
  padding: 10px 14px 10px 38px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text);
  outline: none;
  transition: border-color .15s;
}
.search-wrap input:focus { border-color: var(--accent); }
.header-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }

.icon-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-dim);
  border-radius: 8px;
  width: 36px; height: 36px;
  display: grid; place-items: center;
  transition: all .15s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.menu-btn { display: none; }

/* ---------- Sidebar ---------- */
.sidebar {
  grid-area: sidebar;
  background: var(--bg-soft);
  border-right: 1px solid var(--border);
  padding: 14px 10px;
  overflow-y: auto;
}
.sidebar-section {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-faint);
  padding: 12px 10px 6px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  cursor: pointer;
  transition: background .12s, color .12s;
  margin-bottom: 2px;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-item .count { margin-left: auto; font-size: 12px; color: var(--text-faint); }
.nav-item.active .count { color: var(--accent); }

.add-account {
  margin-top: 10px;
  display: flex;
  gap: 6px;
  padding: 0 6px;
}
.add-account input {
  flex: 1;
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  color: var(--text);
  outline: none;
}
.add-account input:focus { border-color: var(--accent); }
.btn {
  border: 0;
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  background: var(--accent);
  color: #fff;
  transition: background .15s;
  display: inline-flex; align-items: center; gap: 6px;
}
.btn:hover { background: var(--accent-hover); }
.btn.ghost { background: var(--surface-2); color: var(--text-dim); }
.btn.ghost:hover { background: var(--surface-3); color: var(--text); }
.btn.danger { background: rgba(255, 92, 108, 0.15); color: var(--danger); }
.btn.danger:hover { background: rgba(255, 92, 108, 0.25); }
.btn.sm { padding: 6px 10px; font-size: 12px; }

/* ---------- Main area ---------- */
.main {
  grid-area: main;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.toolbar select, .toolbar input[type="date"] {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  outline: none;
}
.toolbar label { color: var(--text-dim); font-size: 13px; display: flex; align-items: center; gap: 6px; }

.content {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 430px) minmax(0, 1fr);
  overflow: hidden;
}
.content.list-only { grid-template-columns: 1fr; }

/* ---------- Mail list ---------- */
.maillist {
  border-right: 1px solid var(--border);
  overflow-y: auto;
  background: var(--bg);
}
.maillist-header {
  padding: 14px 18px;
  font-weight: 700;
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-soft);
}
.maillist-header .sub { color: var(--text-faint); font-weight: 400; font-size: 12px; }

.mail-item {
  display: flex;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-soft);
  cursor: pointer;
  transition: background .12s;
}
.mail-item:hover { background: var(--surface); }
.mail-item.selected { background: var(--surface-2); }
.mail-item.unread { background: rgba(79, 124, 255, 0.05); }
.mail-item.unread:hover { background: rgba(79, 124, 255, 0.09); }

.avatar {
  width: 38px; height: 38px;
  border-radius: 50%;
  flex-shrink: 0;
  display: grid; place-items: center;
  font-weight: 700; font-size: 13px;
  color: #fff;
  background: #3a4457;
}
.mail-body { flex: 1; min-width: 0; }
.mail-top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 2px;
}
.mail-sender {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mail-item.unread .mail-sender { color: #fff; }
.mail-time { color: var(--text-faint); font-size: 12px; white-space: nowrap; }
.mail-subject {
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
}
.mail-item.unread .mail-subject { font-weight: 700; color: #fff; }
.mail-snippet {
  color: var(--text-dim);
  font-size: 12.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mail-meta { display: flex; gap: 8px; align-items: center; }
.chip {
  font-size: 10.5px;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--surface-3);
  color: var(--text-dim);
}
.chip.attach { background: rgba(245, 184, 61, 0.14); color: var(--star); }
.chip.recipient { background: var(--accent-soft); color: var(--accent); }

.unread-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--unread-dot);
  flex-shrink: 0;
  margin-top: 6px;
}
.star {
  color: var(--text-faint);
  cursor: pointer;
  flex-shrink: 0;
  font-size: 16px;
  line-height: 1;
}
.star.on { color: var(--star); }

.empty {
  padding: 60px 20px;
  text-align: center;
  color: var(--text-faint);
}
.empty .big { font-size: 42px; margin-bottom: 12px; }

/* ---------- Detail pane ---------- */
.detail {
  overflow-y: auto;
  background: var(--bg-soft);
  padding: 22px 28px;
}
.detail-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}
.detail h1 {
  font-size: 19px;
  margin: 0 0 10px;
  flex: 1;
}
.detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 18px;
  font-size: 13px;
}
.detail-meta .lbl { color: var(--text-faint); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; margin-bottom: 3px; }
.detail-meta a { color: var(--accent); text-decoration: none; }
.detail-meta a:hover { text-decoration: underline; }

.email-html-frame {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  min-height: 320px;
}
.email-text {
  white-space: pre-wrap;
  font-size: 14px;
  line-height: 1.65;
  color: var(--text);
}
.attachments { margin-top: 18px; }
.attachments .lbl { color: var(--text-faint); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; margin-bottom: 8px; }
.att-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
}
.att-row a { color: var(--text); text-decoration: none; font-weight: 600; }
.att-row a:hover { color: var(--accent); }
.att-row .sz { color: var(--text-faint); font-size: 12px; }

/* ---------- Backdrop / modal ---------- */
.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: grid;
  place-items: center;
  z-index: 50;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  width: 90%;
  max-width: 380px;
  box-shadow: var(--shadow);
}
.modal h2 { margin: 0 0 14px; font-size: 17px; }
.modal .field { margin-bottom: 12px; }
.modal label { display: block; color: var(--text-dim); font-size: 12px; margin-bottom: 5px; }
.modal input {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  color: var(--text);
  outline: none;
}
.modal input:focus { border-color: var(--accent); }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: radial-gradient(1200px 600px at 50% -10%, #1a2336, var(--bg));
  padding: 20px;
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 30px;
  box-shadow: var(--shadow);
}
.login-card .logo { font-size: 30px; }
.login-card h1 { font-size: 19px; margin: 14px 0 4px; }
.login-card p { color: var(--text-dim); font-size: 13px; margin: 0 0 20px; }
.login-card input {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 13px;
  color: var(--text);
  outline: none;
  margin-bottom: 14px;
}
.login-card input:focus { border-color: var(--accent); }
.login-card .btn { width: 100%; justify-content: center; }
.error-banner {
  background: rgba(255, 92, 108, 0.12);
  color: var(--danger);
  border: 1px solid rgba(255, 92, 108, 0.3);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  margin-bottom: 14px;
  font-size: 13px;
}

/* ---------- Stats dashboard ---------- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
  padding: 18px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}
.stat-card .v { font-size: 28px; font-weight: 800; }
.stat-card .k { color: var(--text-dim); font-size: 13px; margin-top: 4px; }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  .menu-btn { display: grid; }
  .app { grid-template-columns: 1fr; grid-template-areas: "header" "sidebar" "main"; grid-template-rows: 60px auto 1fr; }
  .sidebar { display: none; }
  .app.sidebar-open .sidebar { display: block; }
  .content { grid-template-columns: 1fr; }
  .content .maillist { display: none; }
  .content.show-list .maillist { display: block; }
  .content.show-detail .detail { display: block; }
  .content.show-detail .maillist { display: none; }
  .content .detail { display: none; }
  .content.show-detail .detail { display: block; }
}

/* Scrollbars */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 6px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: #2f394b; }
