/* ─────────────────────────────────────────────
   Base / shared
   ───────────────────────────────────────────── */
* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
}

/* ─────────────────────────────────────────────
   Login page
   ───────────────────────────────────────────── */
body.login-page {
  background: #1a2744;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.login-box {
  background: #fff;
  border-radius: 8px;
  padding: 40px;
  width: 380px;
  box-shadow: 0 8px 32px rgba(0,0,0,.4);
}

.login-box .brand {
  color: #1a2744;
  font-weight: 700;
  font-size: 1.3rem;
  margin-bottom: 6px;
}

.login-box .brand span { color: #0078d4; }

/* ─────────────────────────────────────────────
   App (search) page
   ───────────────────────────────────────────── */
body.app-page {
  overflow: hidden;
  height: 100vh;
  background: #f0f2f5;
}

/* ── header ── */
#topbar {
  background: #1a2744;
  color: #fff;
  height: 48px;
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
  flex-shrink: 0;
}

#topbar .brand {
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: .5px;
  color: #fff;
  text-decoration: none;
}

#topbar .brand span { color: #4ea8f8; }

.topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.role-badge {
  background: #0d3a6e;
  border: 1px solid #2a5aa0;
  color: #8ac4f8;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: .78rem;
  display: flex;
  align-items: center;
  gap: 5px;
}

/* ── layout ── */
#layout { display: flex; height: calc(100vh - 48px); }

/* ── sidebar ── */
#sidebar {
  width: 0;
  min-width: 0;
  background: #fff;
  border-right: 1px solid #dde1e7;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width .22s ease;
  flex-shrink: 0;
}
#sidebar.open {
  width: 200px;
  min-width: 160px;
  max-width: 260px;
  resize: horizontal;
}

#sidebar-toggle {
  background: none;
  border: none;
  color: #8ac4f8;
  font-size: 1.2rem;
  padding: 0 10px;
  cursor: pointer;
  line-height: 1;
  flex-shrink: 0;
}

#sidebar-header {
  padding: 12px 14px 8px;
  border-bottom: 1px solid #eee;
  font-size: .78rem;
  font-weight: 600;
  color: #888;
  text-transform: uppercase;
  letter-spacing: .5px;
}

#sidebar-body { overflow-y: auto; flex: 1; padding: 4px 0; }

.tree-user {
  padding: 6px 14px 2px;
  font-size: .78rem;
  font-weight: 700;
  color: #1a2744;
  text-transform: uppercase;
  letter-spacing: .4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
  border-radius: 4px;
  transition: background .15s;
}
.tree-user:hover    { background: #e8f4ff; }
.tree-user.scope-active {
  background: #fff3cd;
  color: #856404;
  border-left: 3px solid #ffc107;
  padding-left: 11px;
}

.tree-pst {
  padding: 4px 14px 4px 24px;
  font-size: .82rem;
  color: #0078d4;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
  border-radius: 4px;
  margin: 1px 6px;
}

.tree-pst:hover, .tree-pst.active { background: #e8f4ff; }

.tree-folder {
  padding: 3px 14px 3px 36px;
  font-size: .82rem;
  color: #333;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  border-radius: 4px;
  margin: 1px 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tree-folder:hover, .tree-folder.active { background: #f0f6ff; }
.tree-folder .count { color: #999; font-size: .75rem; margin-left: auto; white-space: nowrap; }
.tree-children { display: none; padding-left: 12px; }
.tree-toggle { color: #aaa; font-size: .7rem; width: 12px; display: inline-block; flex-shrink: 0; }

.spinner-sm {
  display: inline-block;
  width: 10px;
  height: 10px;
  border: 2px solid #ccc;
  border-top-color: #0078d4;
  border-radius: 50%;
  animation: spin .6s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── main area ── */
#main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

/* ── search bar ── */
#searchbar { background: #fff; border-bottom: 1px solid #dde1e7; padding: 10px 16px; }

.filter-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  margin-top: 8px;
}

.filter-row .form-control, .filter-row .form-select {
  font-size: .83rem;
  height: 30px;
  padding: 2px 8px;
}

.filter-row label { font-size: .78rem; color: #666; white-space: nowrap; }

/* ── results ── */
#results-area { flex: 1; overflow-y: auto; padding: 12px 16px; }
#results-status {
  font-size: .83rem;
  color: #666;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ── email table ── */
.email-table {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  background: #fff;
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
}

.email-table thead tr { background: #f7f9fc; border-bottom: 2px solid #e0e4ea; }

.email-table th {
  padding: 8px 12px;
  font-size: .78rem;
  font-weight: 600;
  color: #0078d4;
  text-transform: uppercase;
  letter-spacing: .4px;
  white-space: nowrap;
}

.email-table td {
  padding: 9px 12px;
  font-size: .83rem;
  border-bottom: 1px solid #f0f2f5;
  vertical-align: top;
  overflow: hidden;
}

.email-table tr:hover td { background: #f5f9ff; cursor: pointer; }
.email-table tr.active td { background: #e8f4ff; }

td.col-folder   { width: 110px; min-width: 100px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: #0078d4; font-size: .78rem; }
td.col-sender  { width: 200px; min-width: 180px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: #333; font-weight: 500; }
td.col-subject { width: auto; min-width: 0; }
td.col-date    { width: 130px; min-width: 130px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: #888; font-size: .78rem; }

.subject-line {
  font-weight: 600;
  color: #1a1a1a;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 500px;
}

.snippet {
  color: #777;
  font-size: .78rem;
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.snippet mark { background: #fff3cd; padding: 0 2px; border-radius: 2px; }
.attach-icon { color: #f59e0b; margin-left: 5px; font-size: .75rem; }

/* ── pagination ── */
.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 10px 0 4px;
  font-size: .83rem;
  color: #666;
}

.pagination-bar a {
  color: #0078d4;
  text-decoration: none;
  padding: 3px 8px;
  border-radius: 3px;
  border: 1px solid #dde1e7;
}

.pagination-bar a:hover { background: #f0f6ff; }
.pagination-bar strong { color: #333; }

/* ── email viewer panel ── */
#email-panel {
  display: none;
  position: fixed;
  top: 48px;
  right: 0;
  width: 600px;
  height: calc(100vh - 48px);
  background: #fff;
  box-shadow: -3px 0 16px rgba(0,0,0,.15);
  z-index: 200;
  flex-direction: column;
  overflow: hidden;
}

#email-panel.open { display: flex; }

#ep-header {
  padding: 14px 16px;
  border-bottom: 1px solid #eee;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

#ep-meta { flex: 1; }
#ep-subject { font-size: 1rem; font-weight: 700; color: #1a2744; margin-bottom: 4px; }
#ep-from    { font-size: .82rem; color: #666; }
#ep-date    { font-size: .78rem; color: #aaa; }
#ep-actions { display: flex; gap: 6px; }

#ep-body { flex: 1; overflow-y: auto; padding: 16px; }
#ep-iframe { width: 100%; height: 100%; border: none; }
#ep-text { font-size: .85rem; line-height: 1.7; color: #333; white-space: pre-wrap; font-family: inherit; }
#ep-attachments { padding: 8px 16px; border-top: 1px solid #eee; font-size: .8rem; color: #666; }

/* ── empty state ── */
.empty-state { text-align: center; padding: 60px 20px; color: #aaa; }
.empty-state i { font-size: 3rem; display: block; margin-bottom: 12px; }

/* ── view-as banner ── */
.view-as-banner {
  background: #fff3cd;
  border-bottom: 1px solid #ffc107;
  padding: 4px 16px;
  font-size: .8rem;
  color: #856404;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ─────────────────────────────────────────────
   Admin page
   ───────────────────────────────────────────── */
body.admin-page { background: #f0f2f5; }
