/* GridMail webmail — Apple Mail inspired, light/dark via color-scheme. */

:root {
  --bg: #f5f5f7;
  --bg-list: #ffffff;
  --bg-read: #ffffff;
  --bg-sidebar: rgba(246, 246, 248, 0.92);
  --bg-hover: rgba(0, 0, 0, 0.045);
  --bg-sel: #007aff;
  --border: #e3e3e8;
  --text: #1d1d1f;
  --text-2: #6e6e73;
  --text-3: #98989d;
  --accent: #007aff;
  --danger: #d70015;
  --badge: #ff3b30;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
  --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1e1e20;
    --bg-list: #262629;
    --bg-read: #262629;
    --bg-sidebar: rgba(30, 30, 32, 0.92);
    --bg-hover: rgba(255, 255, 255, 0.06);
    --bg-sel: #0a84ff;
    --border: #3a3a3e;
    --text: #f5f5f7;
    --text-2: #a1a1a6;
    --text-3: #6e6e73;
    --accent: #0a84ff;
    --danger: #ff6961;
    --badge: #ff453a;
    --shadow: 0 12px 40px rgba(0, 0, 0, 0.55);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}
.error { color: var(--danger); font-size: 12.5px; min-height: 16px; }
.note {
  margin-top: 8px; font-size: 12px; color: var(--text-2);
  background: var(--bg-hover); border-radius: 6px; padding: 4px 8px;
}

/* ---- buttons ---- */
.btn {
  font: inherit; color: var(--text); background: transparent;
  border: 1px solid var(--border); border-radius: 999px;
  padding: 5px 13px; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--bg-hover); }
.btn.primary {
  background: var(--accent); border-color: var(--accent); color: #fff;
}
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }
.btn.ghost { border-color: transparent; color: var(--text-2); }
.btn.ghost:hover { background: var(--bg-hover); color: var(--text); }
.btn.wide { width: 100%; padding: 9px 13px; font-weight: 600; }
.btn.small { padding: 2px 9px; font-size: 12px; }
.move-select {
  font: inherit; font-size: 12.5px; color: var(--text-2);
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 999px; padding: 4px 10px; cursor: pointer; max-width: 150px;
}
.move-select:hover { background: var(--bg-hover); color: var(--text); }
.icon-btn {
  font: inherit; font-size: 16px; line-height: 1; color: var(--text-2);
  background: none; border: none; cursor: pointer; padding: 4px 7px;
  border-radius: 6px;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }
.link-btn {
  font: inherit; font-size: 12.5px; color: var(--accent);
  background: none; border: none; cursor: pointer; padding: 2px 4px;
}
.link-btn:hover { text-decoration: underline; }

/* ---- login ---- */
.login {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(1000px 500px at 20% -10%, rgba(0, 122, 255, 0.16), transparent),
    radial-gradient(800px 420px at 90% 110%, rgba(88, 86, 214, 0.14), transparent),
    var(--bg);
}
.login-card {
  width: 320px; background: var(--bg-list); border: 1px solid var(--border);
  border-radius: 16px; padding: 30px 26px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 12px;
}
.login-brand {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  font-size: 20px; font-weight: 700; letter-spacing: -0.3px; margin-bottom: 6px;
}
.login-card input {
  font: inherit; padding: 9px 12px; border: 1px solid var(--border);
  border-radius: 9px; background: var(--bg); color: var(--text); outline: none;
}
.login-card input:focus { border-color: var(--accent); }

/* ---- brand ---- */
.brand-dot {
  width: 14px; height: 14px; border-radius: 4px; display: inline-block;
  background: linear-gradient(135deg, var(--accent), #5e5ce6);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 15px; }

/* ---- app layout ---- */
.app {
  display: grid;
  grid-template-columns: 224px 348px minmax(0, 1fr);
  height: 100vh; min-width: 900px;
}
.sidebar {
  display: flex; flex-direction: column; gap: 14px; padding: 14px 12px;
  background: var(--bg-sidebar); border-right: 1px solid var(--border);
  backdrop-filter: blur(18px);
}
.compose-btn {
  font: inherit; font-weight: 600; color: #fff; background: var(--accent);
  border: none; border-radius: 999px; padding: 8px 12px; cursor: pointer;
}
.compose-btn:hover { filter: brightness(1.08); }
.boxes { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.box-item {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  font: inherit; text-align: left; color: var(--text); background: none;
  border: none; border-radius: 8px; padding: 7px 10px; cursor: pointer;
}
.box-item:hover { background: var(--bg-hover); }
.box-item.active { background: var(--accent); color: #fff; }
.box-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.box-badge {
  min-width: 20px; padding: 1px 6px; border-radius: 999px; font-size: 11px;
  font-weight: 700; text-align: center; background: var(--badge); color: #fff;
}
.box-item.active .box-badge { background: rgba(255, 255, 255, 0.28); }
.box-count { font-size: 11.5px; color: var(--text-3); }
.box-item.active .box-count { color: rgba(255, 255, 255, 0.8); }
.sidebar-foot { display: flex; flex-direction: column; gap: 8px; font-size: 12px; }
.quota { color: var(--text-2); }
.quota-bar {
  height: 5px; background: var(--bg-hover); border-radius: 999px;
  margin-top: 5px; overflow: hidden;
}
.quota-fill { height: 100%; background: var(--accent); border-radius: 999px; }
.foot-row { display: flex; gap: 6px; }
.foot-btn {
  flex: 1; font: inherit; font-size: 12px; color: var(--text-2);
  background: none; border: 1px solid var(--border); border-radius: 8px;
  padding: 5px 6px; cursor: pointer;
}
.foot-btn:hover { background: var(--bg-hover); color: var(--text); }
.me-email {
  color: var(--text-3); font-size: 11.5px; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}

/* ---- message list ---- */
.list-pane {
  display: flex; flex-direction: column; min-width: 0;
  background: var(--bg-list); border-right: 1px solid var(--border);
}
.list-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 13px 14px 10px; border-bottom: 1px solid var(--border);
}
.list-head h1 { font-size: 17px; margin: 0; letter-spacing: -0.2px; }
.head-actions { display: flex; align-items: center; gap: 7px; min-width: 0; }
#search-input {
  font: inherit; font-size: 13px; width: 170px; padding: 5px 11px;
  border: 1px solid var(--border); border-radius: 999px;
  background: var(--bg); color: var(--text); outline: none;
}
#search-input:focus { border-color: var(--accent); }
.list-tools {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 12px; border-bottom: 1px solid var(--border);
  font-size: 12.5px;
}
.search-note { color: var(--text-3); font-size: 12px; }
.row-tag {
  font-size: 11px; color: var(--accent); flex-shrink: 0;
  background: color-mix(in srgb, var(--accent) 13%, transparent);
  padding: 1px 7px; border-radius: 999px;
}
.row.selected .row-tag { color: #fff; background: rgba(255, 255, 255, 0.22); }
.bulk-bar {
  display: flex; align-items: center; gap: 8px; padding: 7px 12px;
  border-bottom: 1px solid var(--border); background: var(--bg-hover);
  font-size: 12.5px;
}
.bulk-bar #bulk-count { margin-right: auto; color: var(--text-2); }
.list { flex: 1; overflow-y: auto; }
.list-empty {
  padding: 48px 20px; text-align: center; color: var(--text-3); font-size: 13px;
}
.row {
  position: relative; display: grid;
  grid-template-columns: 34px minmax(0, 1fr); gap: 10px;
  padding: 10px 12px; cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.row:hover { background: var(--bg-hover); }
.row.selected { background: var(--bg-sel); color: #fff; }
.row.selected .row-from, .row.selected .row-preview,
.row.selected .row-date, .row.selected .row-star { color: rgba(255, 255, 255, 0.85); }
.row-main { min-width: 0; }
.row-line1 {
  display: flex; align-items: baseline; gap: 8px; justify-content: space-between;
}
.row-from {
  font-weight: 600; font-size: 13.5px; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}
.row.unread .row-from, .row.unread .row-subject { font-weight: 700; }
.row-date { font-size: 11.5px; color: var(--text-3); flex-shrink: 0; }
.row-subject {
  font-size: 13px; margin-top: 1px; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap;
}
.row-preview {
  font-size: 12px; color: var(--text-2); margin-top: 2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.row-star {
  position: absolute; right: 10px; bottom: 9px; color: #f5a623;
  font-size: 12px; pointer-events: none;
}
.row-unread-dot {
  position: absolute; left: 4px; top: 50%; transform: translateY(-50%);
  width: 7px; height: 7px; border-radius: 50%; background: var(--accent);
}
.row.selected .row-unread-dot { background: #fff; }

/* ---- avatars ---- */
.avatar {
  width: 34px; height: 34px; border-radius: 50%; display: flex;
  align-items: center; justify-content: center; font-size: 13px;
  font-weight: 700; color: #fff; user-select: none; flex-shrink: 0;
}
.avatar.lg { width: 40px; height: 40px; font-size: 15px; }

/* ---- reading pane ---- */
.read-pane { background: var(--bg-read); overflow-y: auto; min-width: 0; }
.read-empty {
  height: 100%; display: flex; flex-direction: column; align-items: center;
  justify-content: center; color: var(--text-3); gap: 6px;
}
.read-empty-mark {
  font-size: 26px; font-weight: 800; letter-spacing: -0.6px;
  color: color-mix(in srgb, var(--text-3) 35%, transparent);
}
.read { max-width: 780px; margin: 0 auto; padding: 26px 32px 80px; }
.read-head { border-bottom: 1px solid var(--border); padding-bottom: 16px; }
.read-top { display: flex; align-items: center; gap: 12px; }
.read-who { min-width: 0; flex: 1; }
.read-from { font-weight: 700; font-size: 15px; }
.read-from .addr { font-weight: 400; color: var(--text-2); font-size: 13px; }
.read-to { color: var(--text-2); font-size: 12.5px; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; }
.read-date { color: var(--text-2); font-size: 12.5px; flex-shrink: 0; }
.read h1 { font-size: 21px; letter-spacing: -0.4px; margin: 14px 0 12px; }
.read-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 4px; }
.atts { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.att {
  display: inline-flex; align-items: center; gap: 8px; font: inherit;
  font-size: 12.5px; color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px;
  cursor: pointer;
}
.att:hover { background: var(--bg-hover); }
.att .att-size { color: var(--text-3); }
.read-body {
  padding-top: 20px; font-size: 15px; line-height: 1.6; overflow-wrap: break-word;
}
.read-body.pre { white-space: pre-wrap; font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 13px; }
.read-body img { max-width: 100%; height: auto; }
.read-body blockquote {
  margin: 10px 0; padding: 2px 0 2px 14px; border-left: 3px solid var(--border);
  color: var(--text-2);
}
.read-body table { max-width: 100%; border-collapse: collapse; }
.read-body pre { white-space: pre-wrap; overflow-wrap: break-word; }

/* ---- overlays / compose ---- */
.overlay {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.32);
  display: flex; z-index: 40; backdrop-filter: blur(2px);
}
.overlay .compose { margin: auto 24px 24px auto; }
.compose {
  width: 580px; max-width: calc(100vw - 48px); background: var(--bg-list);
  border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; overflow: hidden;
}
.compose-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 11px 14px; font-weight: 600; border-bottom: 1px solid var(--border);
  background: var(--bg-hover);
}
.compose-fields { padding: 6px 14px; border-bottom: 1px solid var(--border); }
.field-row { display: flex; align-items: center; gap: 10px; padding: 7px 0; }
.field-row + .field-row { border-top: 1px solid var(--border); }
.field-label { width: 54px; color: var(--text-2); font-size: 13px; }
.field-row input {
  flex: 1; font: inherit; border: none; outline: none; background: none;
  color: var(--text); padding: 3px 0;
}
#compose textarea {
  min-height: 240px; resize: vertical; border: none; outline: none;
  background: none; color: var(--text); font: inherit; font-size: 14.5px;
  line-height: 1.55; padding: 14px; }
.compose-foot {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px; border-top: 1px solid var(--border);
}
.compose-foot .error { flex: 1; }

/* ---- modal (admin) ---- */
.overlay.center { align-items: center; justify-content: center; }
.modal {
  width: 860px; max-width: calc(100vw - 48px); max-height: calc(100vh - 60px);
  background: var(--bg-list); border: 1px solid var(--border);
  border-radius: 14px; box-shadow: var(--shadow); display: flex;
  flex-direction: column; overflow: hidden;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; font-weight: 700; border-bottom: 1px solid var(--border);
}
.modal-body { padding: 16px; overflow-y: auto; }
.admin-token-row { display: flex; gap: 8px; margin-bottom: 6px; }
.admin-token-row input {
  flex: 1; font: inherit; padding: 8px 11px; border: 1px solid var(--border);
  border-radius: 8px; background: var(--bg); color: var(--text); outline: none;
}
.admin-stats { display: flex; gap: 12px; margin: 14px 0; }
.stat-card {
  flex: 1; background: var(--bg); border: 1px solid var(--border);
  border-radius: 10px; padding: 14px; text-align: center;
}
.stat-num { font-size: 26px; font-weight: 800; letter-spacing: -0.5px; }
.stat-label { font-size: 11.5px; color: var(--text-2); margin-top: 3px; }
.modal-body h2 {
  font-size: 14px; margin: 18px 0 8px; color: var(--text-2);
  text-transform: uppercase; letter-spacing: 0.4px;
}
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th {
  text-align: left; font-size: 11.5px; color: var(--text-2); font-weight: 600;
  padding: 6px 8px; border-bottom: 1px solid var(--border);
}
.tbl td { padding: 7px 8px; border-bottom: 1px solid var(--border); }
.usage-cell { display: flex; align-items: center; gap: 8px; }
.usage-bar {
  width: 110px; height: 6px; background: var(--bg-hover); border-radius: 999px;
  overflow: hidden; flex-shrink: 0;
}
.usage-fill { height: 100%; background: var(--accent); }
.usage-fill.hot { background: var(--badge); }
.inline-form { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.inline-form input {
  font: inherit; padding: 7px 10px; border: 1px solid var(--border);
  border-radius: 8px; background: var(--bg); color: var(--text); outline: none;
}
.inline-form input[type="email"] { flex: 2; min-width: 180px; }
.inline-form input[type="password"] { flex: 1; min-width: 130px; }

/* ---- toast ---- */
.toast {
  position: fixed; top: 18px; left: 50%; transform: translateX(-50%);
  background: rgba(30, 30, 32, 0.94); color: #fff; font-size: 13px;
  padding: 9px 16px; border-radius: 999px; z-index: 60;
  box-shadow: var(--shadow); max-width: 70vw;
}
.toast.err { background: var(--danger); }

/* ---- scrollbar polish ---- */
.list::-webkit-scrollbar, .read-pane::-webkit-scrollbar,
.modal-body::-webkit-scrollbar, .boxes::-webkit-scrollbar { width: 10px; }
.list::-webkit-scrollbar-thumb, .read-pane::-webkit-scrollbar-thumb,
.modal-body::-webkit-scrollbar-thumb, .boxes::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--text-3) 40%, transparent);
  border-radius: 999px; border: 3px solid transparent; background-clip: content-box;
}
