:root {
  color-scheme: light;
  --ink: #172033;
  --muted: #697386;
  --line: #dce1e9;
  --surface: #ffffff;
  --background: #f4f6f9;
  --navy: #111827;
  --indigo: #4f46e5;
  --indigo-dark: #4038c7;
  --danger: #b42318;
  --danger-soft: #fff1f0;
  --success: #137333;
  --success-soft: #ecfdf3;
  --warning: #9a6700;
  --warning-soft: #fff8c5;
  font-family: Inter, "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background: var(--background);
  color: var(--ink);
}

button, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
.hidden { display: none !important; }

.skip-link {
  position: fixed;
  z-index: 100;
  top: 0.5rem;
  left: 0.5rem;
  padding: 0.7rem 1rem;
  border-radius: 0.45rem;
  background: #fff;
  color: var(--navy);
  transform: translateY(-150%);
}

.skip-link:focus { transform: translateY(0); }

.topbar {
  min-height: 4.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  background: var(--navy);
  color: #fff;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.7rem;
  color: #fff;
  font-size: 1.15rem;
  font-weight: 800;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 2rem;
  height: 2rem;
  border-radius: 0.5rem;
  background: var(--indigo);
  place-items: center;
}

.top-actions { display: flex; align-items: center; gap: 1rem; }
.admin-label { color: #aab4c5; font-size: 0.85rem; }

.notice {
  max-width: 74rem;
  margin: 1rem auto;
  padding: 0.8rem 1rem;
  border: 1px solid #f0aaa4;
  border-radius: 0.55rem;
  background: var(--danger-soft);
  color: var(--danger);
}

.notice-success { border-color: #91d5a4; background: var(--success-soft); color: var(--success); }

.login-shell {
  display: grid;
  min-height: calc(100vh - 4.25rem);
  padding: 2rem 1rem 5rem;
  background:
    radial-gradient(circle at 20% 20%, #e5e4ff, transparent 30%),
    radial-gradient(circle at 80% 80%, #e2edf9, transparent 32%);
  place-items: center;
}

.login-card {
  width: min(100%, 26rem);
  padding: 2.25rem;
  border: 1px solid var(--line);
  border-radius: 0.9rem;
  background: var(--surface);
  box-shadow: 0 22px 60px rgba(17, 24, 39, 0.12);
}

h1, h2, h3, p { margin-top: 0; }
.login-card h1 { margin-bottom: 0.55rem; font-size: 1.9rem; letter-spacing: -0.03em; }
.eyebrow { margin-bottom: 0.45rem; color: var(--indigo); font-size: 0.72rem; font-weight: 800; letter-spacing: 0.12em; text-transform: uppercase; }
.subtle { color: var(--muted); font-size: 0.9rem; }

label:not(.confirmation), .field-label {
  display: block;
  margin: 1.1rem 0 0.4rem;
  font-size: 0.85rem;
  font-weight: 700;
}

input[type="password"] {
  width: 100%;
  min-height: 2.8rem;
  padding: 0.65rem 0.75rem;
  border: 1px solid #b9c2d0;
  border-radius: 0.5rem;
  color: var(--ink);
}

input:focus, button:focus-visible, a:focus-visible {
  outline: 3px solid rgba(79, 70, 229, 0.28);
  outline-offset: 2px;
}

.button {
  min-height: 2.55rem;
  padding: 0.55rem 0.95rem;
  border: 1px solid transparent;
  border-radius: 0.5rem;
  cursor: pointer;
  font-weight: 750;
}

.button:disabled { cursor: not-allowed; opacity: 0.55; }
.button-primary { background: var(--indigo); color: #fff; }
.button-primary:hover:not(:disabled) { background: var(--indigo-dark); }
.button-secondary { border-color: var(--line); background: #fff; color: var(--ink); }
.button-secondary:hover:not(:disabled) { background: #f1f3f7; }
.button-danger { border-color: #f2b8b3; background: var(--danger-soft); color: var(--danger); }
.button-quiet { background: transparent; color: #d7dcea; }
.button-block { width: 100%; margin-top: 1.35rem; }

.dashboard {
  max-width: 76rem;
  margin: 0 auto;
  padding: clamp(1.25rem, 4vw, 3rem) 1rem 5rem;
}

.dashboard-head, .section-head, .connection-summary {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 1rem;
}

.dashboard-head { margin-bottom: 2rem; }
.dashboard-head h1 { margin-bottom: 0.4rem; font-size: clamp(1.8rem, 4vw, 2.35rem); letter-spacing: -0.035em; }
.dashboard-head h1:focus { outline: none; }
.section-head { align-items: center; margin: 2rem 0 0.8rem; }
.section-head h2 { margin-bottom: 0.2rem; font-size: 1.15rem; }

.credentials-panel {
  margin-bottom: 2rem;
  padding: clamp(1.25rem, 3vw, 2rem);
  border: 2px solid #e0a100;
  border-radius: 0.75rem;
  background: #fffdf0;
}

.credential-warning { display: flex; flex-wrap: wrap; gap: 0.4rem; color: #6d4b00; }
.credentials-panel h2 { margin: 1.25rem 0 0.75rem; font-size: 1.2rem; }
.credential-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.credential-grid > div { min-width: 0; padding: 0.9rem; border: 1px solid #eadb9f; border-radius: 0.55rem; background: #fff; }
.credential-grid .field-label { margin-top: 0; color: var(--muted); }
.credential-grid code { display: block; overflow: auto; padding: 0.65rem; border-radius: 0.35rem; background: #f5f3e6; font-size: 0.9rem; white-space: nowrap; }
.copy-button { margin-top: 0.5rem; padding: 0; border: 0; background: transparent; color: var(--indigo); cursor: pointer; font-weight: 700; }
.confirmation { display: flex; align-items: flex-start; gap: 0.6rem; margin: 1rem 0; cursor: pointer; }
.confirmation input { width: 1.1rem; height: 1.1rem; margin-top: 0.1rem; }

.loading { padding: 1.5rem; color: var(--muted); text-align: center; }
.empty-card { padding: 3rem 1rem; border: 1px dashed #b9c2d0; border-radius: 0.7rem; background: #fff; text-align: center; }
.empty-card h3 { margin-bottom: 0.35rem; }
.empty-card p { margin-bottom: 0; color: var(--muted); }
.connections-list { display: grid; gap: 0.8rem; }

.connection-card {
  padding: 1.25rem;
  border: 1px solid var(--line);
  border-radius: 0.7rem;
  background: var(--surface);
  box-shadow: 0 2px 8px rgba(17, 24, 39, 0.035);
}

.connection-gmail { margin-bottom: 0.25rem; font-size: 1.05rem; overflow-wrap: anywhere; }
.connection-mailbox { margin-bottom: 0; color: var(--muted); font-size: 0.87rem; overflow-wrap: anywhere; }
.status-badge { flex: 0 0 auto; padding: 0.3rem 0.55rem; border-radius: 999px; background: #eef0f4; color: #4b5565; font-size: 0.73rem; font-weight: 800; }
.status-badge[data-status="active"] { background: var(--success-soft); color: var(--success); }
.status-badge[data-status="reauth_required"] { background: var(--warning-soft); color: var(--warning); }
.status-badge[data-status="error"] { background: var(--danger-soft); color: var(--danger); }

.connection-details { display: flex; flex-wrap: wrap; gap: 1.5rem; margin: 1rem 0; }
.connection-details div { min-width: 10rem; }
.connection-details dt { margin-bottom: 0.15rem; color: var(--muted); font-size: 0.75rem; }
.connection-details dd { margin: 0; font-size: 0.87rem; }
.connection-error { padding: 0.7rem; border-radius: 0.4rem; background: var(--danger-soft); color: var(--danger); font-size: 0.85rem; overflow-wrap: anywhere; }
.connection-actions { display: flex; flex-wrap: wrap; gap: 0.55rem; padding-top: 0.25rem; }

.audit-section { margin-top: 2.75rem; }
.audit-table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 0.7rem; background: #fff; }
table { width: 100%; border-collapse: collapse; font-size: 0.83rem; }
th, td { padding: 0.75rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { background: #f8f9fb; color: var(--muted); font-size: 0.72rem; letter-spacing: 0.04em; text-transform: uppercase; }
td { max-width: 22rem; overflow-wrap: anywhere; }
tbody tr:last-child td { border-bottom: 0; }
.table-empty { margin: 0; padding: 2.5rem 1rem; color: var(--muted); text-align: center; }

@media (max-width: 640px) {
  .topbar { padding-inline: 1rem; }
  .admin-label { display: none; }
  .dashboard-head { align-items: stretch; flex-direction: column; }
  .dashboard-head .button { width: 100%; }
  .credential-grid { grid-template-columns: 1fr; }
  .connection-details { display: grid; grid-template-columns: 1fr 1fr; gap: 0.8rem; }
  .connection-actions .button { flex: 1 1 auto; }
  th:nth-child(2), td:nth-child(2), th:nth-child(5), td:nth-child(5) { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; }
}
