*, *::before, *::after { box-sizing: border-box; }

:root {
  --bg: #ffffff;
  --bg-soft: #fafafa;
  --bg-softer: #f5f5f5;
  --border: #e7e7e9;
  --border-strong: #d4d4d6;
  --text: #111114;
  --text-muted: #6b6b73;
  --text-faint: #9a9aa3;
  --accent: #111114;
  --accent-bg: #f1f1f3;
  --unread: #1d4ed8;
  --danger: #b91c1c;
}

html, body {
  margin: 0;
  height: 100%;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button { font-family: inherit; }
input { font-family: inherit; }

.hidden { display: none !important; }

/* Login */
.login {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: var(--bg-soft);
}
.login-card {
  width: 320px;
  padding: 28px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.login-card h1 {
  font-size: 18px;
  margin: 0;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.login-card .muted {
  margin: 0 0 8px 0;
  color: var(--text-muted);
  font-size: 13px;
}
.login-card label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}
.login-card input {
  padding: 9px 11px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  font-size: 14px;
  color: var(--text);
  background: #fff;
  outline: none;
  transition: border-color 0.1s;
}
.login-card input:focus { border-color: var(--text); }
.login-card button {
  margin-top: 6px;
  padding: 9px 12px;
  border: none;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font-weight: 500;
  font-size: 14px;
  cursor: pointer;
}
.login-card button:hover { opacity: 0.9; }
.error { color: var(--danger); font-size: 12px; min-height: 16px; }

/* App layout */
.app {
  display: grid;
  grid-template-columns: 240px 340px 1fr;
  height: 100vh;
  overflow: hidden;
}

.sidebar {
  background: var(--bg-soft);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 10px 16px;
}
.brand {
  font-weight: 600;
  letter-spacing: -0.01em;
  font-size: 15px;
}
.ghost {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 12px;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 4px;
}
.ghost:hover { background: var(--accent-bg); color: var(--text); }
.sidebar-sub {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 16px 10px 16px;
}
.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  display: inline-block;
}
.dot.online { background: #16a34a; }
.dot.offline { background: #d4d4d6; }

.muted { color: var(--text-muted); }
.small { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; font-weight: 500; }

.inbox-list, .message-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}
.inbox-list li {
  padding: 9px 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-left: 2px solid transparent;
  font-size: 13.5px;
}
.inbox-list li:hover { background: var(--accent-bg); }
.inbox-list li.active {
  background: var(--accent-bg);
  border-left-color: var(--text);
  font-weight: 500;
}
.inbox-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge {
  background: var(--unread);
  color: #fff;
  font-size: 10px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 8px;
  min-width: 18px;
  text-align: center;
}

.messages {
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg);
}
.col-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 500;
  font-size: 13px;
  color: var(--text-muted);
  letter-spacing: 0.01em;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 47px;
}
.col-header > span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ghost.danger { color: var(--danger); }
.ghost.danger:hover { background: #fee2e2; color: var(--danger); }
#messages-title, #viewer-title { color: var(--text); }

.message-list li {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 3px;
  position: relative;
}
.message-list li:hover { background: var(--bg-soft); }
.message-list li.active { background: var(--accent-bg); }
.message-list li.unread .msg-from,
.message-list li.unread .msg-subject { font-weight: 600; }
.message-list li.unread::before {
  content: '';
  position: absolute;
  left: 6px;
  top: 18px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--unread);
}
.msg-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}
.msg-from {
  font-size: 13px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.msg-time {
  font-size: 11px;
  color: var(--text-faint);
  flex-shrink: 0;
}
.msg-subject {
  font-size: 13px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.msg-preview {
  font-size: 12px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.viewer {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg);
}
.viewer-meta {
  padding: 16px 24px 12px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
}
.viewer-meta .label {
  display: inline-block;
  width: 60px;
  color: var(--text-muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 500;
}
.viewer-meta > div span:last-child {
  color: var(--text);
}
.viewer-body {
  flex: 1;
  padding: 20px 24px;
  overflow-y: auto;
  font-size: 14px;
  line-height: 1.55;
  color: var(--text);
  min-height: 0;
}
.viewer-body iframe {
  width: 100%;
  height: 100%;
  border: none;
}
.viewer-body pre {
  font-family: 'Inter', sans-serif;
  white-space: pre-wrap;
  word-wrap: break-word;
  margin: 0;
  font-size: 14px;
}

.empty {
  padding: 30px 16px;
  text-align: center;
  color: var(--text-faint);
  font-size: 13px;
}
