/* ============================================================
   Reset + base
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 15px;
  line-height: 1.6;
  color: #1a1a1a;
  background: #f5f5f5;
}

[x-cloak] { display: none !important; }

a { color: #1a56c4; text-decoration: none; }
a:hover { text-decoration: underline; }

code {
  background: #f0f0f0;
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 0.85em;
  font-family: 'SF Mono', Consolas, monospace;
}

h1 { font-size: 1.5rem; font-weight: 700; }
h2 { font-size: 1.1rem; font-weight: 600; color: #444; margin-bottom: 0.5rem; }

.muted { color: #888; font-size: 0.9em; }
.mono  { font-family: 'SF Mono', Consolas, monospace; font-size: 0.85em; }
.wrap  { white-space: pre-wrap; word-break: break-word; max-width: 400px; }

/* ============================================================
   Buttons
   ============================================================ */
.btn {
  display: inline-block;
  padding: 0.4rem 0.9rem;
  border-radius: 5px;
  border: 1px solid #ccc;
  background: #fff;
  color: #333;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  line-height: 1.5;
  white-space: nowrap;
}
.btn:hover { background: #f0f0f0; text-decoration: none; }

.btn-primary {
  background: #1a56c4;
  color: #fff;
  border-color: #1a56c4;
}
.btn-primary:hover { background: #1545a8; color: #fff; }

.btn-danger {
  background: #c41a1a;
  color: #fff;
  border-color: #c41a1a;
}
.btn-danger:hover { background: #a81414; color: #fff; }

.btn-link {
  background: none;
  border: none;
  color: #1a56c4;
  cursor: pointer;
  font-size: 0.875rem;
  padding: 0;
  text-decoration: none;
}
.btn-link:hover { text-decoration: underline; }

/* ============================================================
   Top nav (CEO / main pages)
   ============================================================ */
.top-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 1.5rem;
  background: #fff;
  border-bottom: 1px solid #e0e0e0;
  position: sticky;
  top: 0;
  z-index: 10;
}
.top-nav-brand {
  font-weight: 700;
  font-size: 1rem;
  color: #1a1a1a;
}
.top-nav-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}
.nav-user  { color: #555; font-size: 0.875rem; }
.nav-link  { font-size: 0.875rem; }

.page-content { padding: 2rem; }

/* ============================================================
   Auth pages
   ============================================================ */
.auth-page {
  background: #f0f0f0;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.auth-card {
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  padding: 2.5rem 2rem;
  max-width: 360px;
  width: 100%;
  text-align: center;
}
.auth-card h1 { margin-bottom: 0.25rem; }
.auth-subtitle { color: #666; margin-bottom: 1.5rem; font-size: 0.9rem; }
.auth-note     { color: #888; font-size: 0.8rem; margin-top: 1rem; }
.auth-error {
  background: #fff0f0;
  border: 1px solid #f5c0c0;
  border-radius: 5px;
  padding: 0.6rem 0.9rem;
  margin-bottom: 1rem;
  font-size: 0.875rem;
  color: #b00020;
}
.btn-google {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  width: 100%;
  padding: 0.6rem 1rem;
  border: 1px solid #ddd;
  border-radius: 5px;
  background: #fff;
  color: #333;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  margin: 0 auto;
}
.btn-google:hover { background: #f8f8f8; text-decoration: none; }
.google-icon { flex-shrink: 0; }

/* ============================================================
   Admin nav
   ============================================================ */
.admin-body { background: #f5f5f5; min-height: 100vh; }

.admin-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  height: 52px;
  background: #1a1a2e;
  color: #e0e0e0;
  position: sticky;
  top: 0;
  z-index: 10;
}
.admin-nav a { color: #c0c0d8; text-decoration: none; font-size: 0.875rem; }
.admin-nav a:hover, .admin-nav a.active { color: #fff; text-decoration: none; }

.admin-nav-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  font-size: 0.95rem;
}
.admin-nav-brand a { color: #fff; font-weight: 700; }
.admin-badge {
  background: #3a4a8a;
  color: #aac;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.admin-nav-links { display: flex; gap: 1.25rem; }
.admin-nav-user  { display: flex; align-items: center; gap: 1rem; font-size: 0.875rem; color: #aaa; }
.admin-nav-user .btn-link { color: #aac; }
.admin-nav-user .btn-link:hover { color: #fff; }

.admin-main { padding: 2rem; max-width: 1100px; }

/* ============================================================
   Page header
   ============================================================ */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}

/* ============================================================
   Flash + errors
   ============================================================ */
.flash {
  background: #e8f4e8;
  border: 1px solid #b0d8b0;
  border-radius: 5px;
  padding: 0.6rem 1rem;
  margin-bottom: 1rem;
  font-size: 0.875rem;
  color: #2a6a2a;
}
.error-list {
  background: #fff0f0;
  border: 1px solid #f5c0c0;
  border-radius: 5px;
  padding: 0.6rem 1rem;
  margin-bottom: 1rem;
  font-size: 0.875rem;
  color: #b00020;
}

/* ============================================================
   Tables
   ============================================================ */
.data-table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  overflow: hidden;
  font-size: 0.875rem;
}
.data-table th {
  background: #f7f7f7;
  text-align: left;
  padding: 0.6rem 1rem;
  font-weight: 600;
  color: #555;
  border-bottom: 1px solid #e0e0e0;
  white-space: nowrap;
}
.data-table td {
  padding: 0.6rem 1rem;
  border-bottom: 1px solid #f0f0f0;
  vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: #fafafa; }

/* ============================================================
   Forms
   ============================================================ */
.form-card {
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  padding: 1.5rem;
  max-width: 600px;
  margin-bottom: 1.5rem;
}
.form-row {
  margin-bottom: 1.1rem;
}
.form-row label {
  display: block;
  font-weight: 600;
  font-size: 0.875rem;
  margin-bottom: 0.3rem;
  color: #333;
}
.form-row input[type="text"],
.form-row input[type="email"],
.form-row input[type="number"],
.form-row select {
  display: block;
  width: 100%;
  padding: 0.45rem 0.7rem;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 0.9rem;
  background: #fff;
  color: #1a1a1a;
}
.form-row input[disabled] {
  background: #f5f5f5;
  color: #888;
  cursor: not-allowed;
}
.form-row input[type="color"] {
  height: 36px;
  width: 80px;
  padding: 2px;
  border: 1px solid #ccc;
  border-radius: 4px;
  cursor: pointer;
}
.form-row small {
  display: block;
  margin-top: 0.25rem;
  color: #888;
  font-size: 0.8rem;
}
.form-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1.25rem;
  align-items: center;
}
.required { color: #c41a1a; }

/* ============================================================
   Checkbox group (tenant access)
   ============================================================ */
.checkbox-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-top: 0.25rem;
}
.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 400;
  font-size: 0.875rem;
  cursor: pointer;
}
.checkbox-label input[type="checkbox"] { cursor: pointer; }

/* ============================================================
   Stat grid (admin dashboard)
   ============================================================ */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-bottom: 2rem;
}
.stat-card {
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  padding: 1.25rem 1.5rem;
  text-align: center;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s;
}
.stat-card:hover { border-color: #1a56c4; text-decoration: none; }
.stat-number { font-size: 2rem; font-weight: 700; color: #1a56c4; }
.stat-label  { font-size: 0.85rem; color: #666; margin-top: 0.1rem; }

/* ============================================================
   Badges
   ============================================================ */
.tenant-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 4px;
  vertical-align: middle;
}
.status-badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 10px;
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.status-active  { background: #e8f4e8; color: #2a6a2a; }
.status-success { background: #e8f4e8; color: #2a6a2a; }
.status-failure { background: #fff0f0; color: #b00020; }
.status-error   { background: #fff0f0; color: #b00020; }
.status-paused  { background: #fefae0; color: #7a6000; }

.role-badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 10px;
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
}
.role-owner    { background: #1a1a2e; color: #fff; }
.role-admin    { background: #2d4263; color: #fff; }
.role-operator { background: #e8f0fe; color: #1a45a0; }
.role-finance  { background: #fef3e0; color: #8a4a00; }
.role-viewer   { background: #f0f0f0; color: #555; }

/* ============================================================
   Danger zone
   ============================================================ */
.danger-zone {
  max-width: 600px;
  border: 1px solid #f5c0c0;
  border-radius: 6px;
  padding: 1.25rem 1.5rem;
  background: #fff;
  margin-top: 2rem;
}
.danger-zone h2 { color: #c41a1a; margin-bottom: 0.75rem; }
.delete-confirm {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid #f5c0c0;
}
.delete-confirm p { font-size: 0.875rem; margin-bottom: 0.75rem; color: #555; }

/* ============================================================
   Misc sections
   ============================================================ */
.admin-section {
  max-width: 600px;
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.25rem;
}
.link-list { list-style: none; }
.link-list li { padding: 0.2rem 0; }
.link-list a  { font-size: 0.9rem; }

.empty-state {
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  padding: 2rem;
  color: #888;
  text-align: center;
}
.empty-state p { margin-bottom: 0.5rem; }

.coming-soon {
  max-width: 540px;
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  padding: 1.5rem 2rem;
}
.coming-soon h2 { margin-bottom: 0.5rem; }
.coming-soon p  { color: #555; font-size: 0.9rem; margin-bottom: 0.5rem; }

/* ============================================================
   CEO view (Phase 0 placeholder)
   ============================================================ */
.phase0 { max-width: 640px; }
.status, .tenants {
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.25rem;
}
ul { list-style: none; }
li { padding: 0.25rem 0; }
.ok    { color: #2a7a2a; font-weight: 600; }
.error { color: #b00020; font-weight: 600; }

/* ============================================================
   Provider tags (connections)
   ============================================================ */
.provider-tag {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 10px;
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: #e8f0fe;
  color: #1a45a0;
}
.provider-gmail { background: #fce8e8; color: #a01a1a; }

/* ============================================================
   Connection detail layout
   ============================================================ */
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
  margin-bottom: 1.25rem;
}
@media (max-width: 700px) {
  .detail-grid { grid-template-columns: 1fr; }
}
.detail-card {
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  padding: 1.25rem 1.5rem;
}
.detail-card h2 {
  font-size: 0.95rem;
  font-weight: 700;
  color: #333;
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid #f0f0f0;
}
.kv-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}
.kv-table th {
  text-align: left;
  font-weight: 600;
  color: #555;
  padding: 0.3rem 0.75rem 0.3rem 0;
  white-space: nowrap;
  width: 35%;
  vertical-align: top;
}
.kv-table td {
  padding: 0.3rem 0;
  color: #1a1a1a;
  vertical-align: top;
  word-break: break-word;
}

/* ============================================================
   Email data table
   ============================================================ */
.email-table { table-layout: fixed; width: 100%; }
.email-table .email-from    { width: 20%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.85rem; }
.email-table .email-subject { width: 30%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.875rem; }
.email-table .email-date    { width: 18%; font-size: 0.8rem; white-space: nowrap; }
.email-table .email-snippet { width: 32%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.8rem; }

/* ============================================================
   Status badge additions
   ============================================================ */
.status-expired { background: #f0e8ff; color: #5a00a0; }
