:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --border: #e2e5ec;
  --text: #1b1f2a;
  --text-muted: #6b7280;
  --primary: #4338ca;
  --primary-hover: #3730a3;
  --success-bg: #dcfce7;
  --success-text: #166534;
  --neutral-bg: #e5e7eb;
  --neutral-text: #374151;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --radius: 10px;
  --shadow: 0 4px 20px rgba(20, 20, 40, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* ---------- topbar ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 12px 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-logo { height: 32px; width: 32px; object-fit: contain; border-radius: 6px; }
.brand-name { font-weight: 700; font-size: 18px; }

.topbar-nav { display: flex; gap: 4px; flex: 1; }

.nav-tab {
  background: none;
  border: none;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
}
.nav-tab:hover { background: var(--bg); }
.nav-tab.active { background: var(--primary); color: #fff; }

.topbar-user { display: flex; align-items: center; gap: 12px; font-size: 14px; color: var(--text-muted); }

/* ---------- layout ---------- */

.content { max-width: 1100px; margin: 0 auto; padding: 32px 24px; }

.view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}
.view-header h2 { margin: 0; font-size: 20px; }

/* ---------- toolbar ---------- */

.table-toolbar {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.table-toolbar .search-input { flex: 1; min-width: 220px; }
.table-toolbar select { width: auto; min-width: 160px; }

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--bg); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); }
.btn-block { width: 100%; }
.btn-small { padding: 6px 12px; font-size: 13px; }
.btn-icon-danger:hover { color: var(--danger); background: #fef2f2; }

/* ---------- table ---------- */

.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
  box-shadow: var(--shadow);
}

.data-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.data-table th, .data-table td {
  text-align: left;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table th { color: var(--text-muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr[data-mail-row] { cursor: pointer; }
.data-table tbody tr[data-mail-row]:hover { background: var(--bg); }
.empty-row { text-align: center; color: var(--text-muted); white-space: normal; padding: 32px 16px; }
.truncate { max-width: 320px; overflow: hidden; text-overflow: ellipsis; }

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.badge-success { background: var(--success-bg); color: var(--success-text); }
.badge-neutral { background: var(--neutral-bg); color: var(--neutral-text); }

/* ---------- modal ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 17, 26, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}
.modal-overlay[hidden] { display: none; }

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  width: 100%;
  max-width: 440px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
}
.modal-wide { max-width: 720px; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { margin: 0; font-size: 16px; }
.modal-close { background: none; border: none; font-size: 22px; line-height: 1; cursor: pointer; color: var(--text-muted); }

.modal-body { padding: 22px; display: flex; flex-direction: column; gap: 10px; }
.modal-body h4 { margin: 12px 0 4px; font-size: 13px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }
.modal-actions-start { justify-content: flex-start; flex-wrap: wrap; }

/* ---------- forms ---------- */

label { font-size: 13px; font-weight: 600; color: var(--text-muted); }
input[type="text"], input[type="email"], input[type="password"], select, textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: var(--bg);
  color: var(--text);
}
textarea { font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 1px; }

.form-hint { font-size: 12px; color: var(--text-muted); margin: 2px 0 0; }
.form-hint code { background: var(--bg); padding: 1px 6px; border-radius: 4px; }
.form-error { color: var(--danger); font-size: 13px; margin: 0; }

/* ---------- auth page ---------- */

.auth-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, #eef0fb, #f5f6fa);
}

.auth-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 36px 32px;
  width: 100%;
  max-width: 360px;
  text-align: center;
}
.auth-logo { height: 48px; width: 48px; object-fit: contain; border-radius: 10px; margin-bottom: 10px; }
.auth-card h1 { margin: 0 0 4px; font-size: 22px; }
.auth-subtitle { color: var(--text-muted); font-size: 14px; margin: 0 0 22px; }
.auth-form { display: flex; flex-direction: column; gap: 6px; text-align: left; }
.auth-form label { margin-top: 8px; }
.auth-form button { margin-top: 16px; }

/* ---------- tabs ---------- */

.tab-strip {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-top: 4px;
}
.tab-btn {
  background: none;
  border: none;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-pane { padding-top: 6px; }

.preview-frame {
  width: 100%;
  height: 360px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}

/* ---------- mail detail ---------- */

.detail-grid {
  display: grid;
  grid-template-columns: 140px 1fr;
  row-gap: 8px;
  column-gap: 12px;
  font-size: 14px;
  margin: 0 0 6px;
}
.detail-grid dt { color: var(--text-muted); font-weight: 600; }
.detail-grid dd { margin: 0; }

.compose-fields {
  margin-top: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.compose-fields textarea { font-family: inherit; }

.copy-row { display: flex; gap: 8px; align-items: center; }
.copy-row input { flex: 1; }
.copy-row .btn { flex-shrink: 0; }
