:root {
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --border: #e3e8ee;
  --text: #1f2937;
  --text-muted: #6b7280;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --success: #16a34a;
  --shadow: 0 1px 2px rgba(15,23,42,0.06), 0 4px 12px rgba(15,23,42,0.04);
  --radius: 10px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Layout */
.app-shell { display: flex; flex-direction: column; min-height: 100vh; }
.topbar {
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px;
  position: sticky; top: 0; z-index: 10;
}
.topbar .brand { font-weight: 600; font-size: 16px; display: flex; align-items: center; gap: 8px; }
.topbar .brand-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--primary); }
.topbar .meta { color: var(--text-muted); font-size: 13px; display: flex; gap: 16px; align-items: center; }

.container { max-width: 1200px; margin: 0 auto; padding: 24px; width: 100%; }

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.card-title { font-weight: 600; font-size: 15px; }
.card-body { padding: 20px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid transparent;
  background: var(--surface-2);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px; font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.btn:hover { background: #e6e9ee; }
.btn-primary { background: var(--primary); color: white; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-danger { background: var(--danger); color: white; border-color: var(--danger); }
.btn-danger:hover { background: var(--danger-hover); border-color: var(--danger-hover); }
.btn-ghost { background: transparent; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn[disabled] { opacity: 0.6; cursor: not-allowed; }

/* Forms */
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px; }
.field label { font-size: 12px; font-weight: 500; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.input {
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,0.15); }
.input-with-suffix { display: flex; align-items: stretch; }
.input-with-suffix .input { border-top-right-radius: 0; border-bottom-right-radius: 0; flex: 1; }
.input-suffix {
  display: flex; align-items: center;
  padding: 0 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-left: 0;
  border-top-right-radius: 8px;
  border-bottom-right-radius: 8px;
  color: var(--text-muted);
  font-size: 13px;
}

/* Tables */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.table th { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600; background: var(--surface-2); }
.table tr:last-child td { border-bottom: none; }
.row-actions { display: flex; gap: 6px; }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--surface-2); color: var(--text-muted);
  border: 1px solid var(--border);
  padding: 2px 8px; border-radius: 999px; font-size: 12px;
}

/* Login screen */
.center-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px; width: 100%; max-width: 420px;
}
.auth-card h1 { margin: 0 0 4px; font-size: 22px; }
.auth-card .subtitle { color: var(--text-muted); margin-bottom: 20px; font-size: 14px; }
.auth-card .btn-primary { width: 100%; justify-content: center; padding: 12px; }
.auth-footer { margin-top: 16px; text-align: center; font-size: 13px; color: var(--text-muted); }

/* Alerts */
.alert {
  border-radius: 8px; padding: 10px 12px; font-size: 13px;
  margin-bottom: 12px; border: 1px solid transparent;
}
.alert-error { background: #fef2f2; color: #991b1b; border-color: #fecaca; }
.alert-success { background: #f0fdf4; color: #166534; border-color: #bbf7d0; }
.alert-info { background: #eff6ff; color: #1e3a8a; border-color: #bfdbfe; }

.empty-state {
  text-align: center; padding: 48px 24px;
  color: var(--text-muted);
}
.empty-state .empty-title { font-size: 16px; color: var(--text); font-weight: 600; margin-bottom: 6px; }

/* Inbox layout */
.inbox-shell {
  display: grid; grid-template-columns: 380px 1fr; gap: 0;
  border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
  background: var(--surface); box-shadow: var(--shadow);
  min-height: calc(100vh - 160px);
}
.message-list {
  border-right: 1px solid var(--border);
  background: var(--surface);
  max-height: calc(100vh - 160px);
  overflow-y: auto;
}
.message-item {
  padding: 12px 16px; border-bottom: 1px solid var(--border);
  cursor: pointer; transition: background 0.1s;
}
.message-item:hover { background: var(--surface-2); }
.message-item.active { background: #eff6ff; }
.message-item .row1 { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.message-item .from { font-weight: 600; font-size: 14px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.message-item .time { font-size: 12px; color: var(--text-muted); flex-shrink: 0; }
.message-item .subject { font-size: 14px; margin-top: 2px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.message-item .preview { font-size: 13px; color: var(--text-muted); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.message-view { display: flex; flex-direction: column; background: var(--surface); }
.message-view .mv-header { padding: 20px 24px; border-bottom: 1px solid var(--border); }
.message-view .mv-subject { font-size: 20px; font-weight: 600; margin: 0 0 8px; line-height: 1.3; }
.message-view .mv-meta { color: var(--text-muted); font-size: 13px; }
.message-view .mv-from { color: var(--text); font-weight: 500; }
.mv-body-wrap { flex: 1; min-height: 400px; padding: 0; }
.mv-iframe { width: 100%; min-height: 600px; border: none; display: block; background: white; }
.mv-text { padding: 20px 24px; white-space: pre-wrap; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; color: var(--text); }
.mv-actions { display: flex; gap: 8px; padding: 12px 24px; border-bottom: 1px solid var(--border); background: var(--surface-2); }
.mv-attachments { padding: 16px 24px; border-top: 1px solid var(--border); background: var(--surface-2); }
.mv-attachments h4 { margin: 0 0 10px; font-size: 13px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.attachment-chip {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 12px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  margin: 0 8px 8px 0; font-size: 13px;
  color: var(--text); text-decoration: none;
}
.attachment-chip:hover { background: #f9fafb; text-decoration: none; }
.attachment-chip .att-name { font-weight: 500; }
.attachment-chip .att-size { color: var(--text-muted); font-size: 12px; }

.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar .left, .toolbar .right { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.muted { color: var(--text-muted); }

.pulse-dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: var(--success); margin-right: 6px;
  box-shadow: 0 0 0 0 rgba(22, 163, 74, 0.7);
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(22, 163, 74, 0.7); }
  70% { box-shadow: 0 0 0 8px rgba(22, 163, 74, 0); }
  100% { box-shadow: 0 0 0 0 rgba(22, 163, 74, 0); }
}

@media (max-width: 820px) {
  .inbox-shell { grid-template-columns: 1fr; }
  .message-list { max-height: 50vh; }
}
