:root {
  --navy: #1e3a5f;
  --navy-dark: #152a45;
  --green: #2d8f4e;
  --green-hover: #257a42;
  --green-light: #e8f5ec;
  --text: #1a2e4a;
  --text-muted: #5a6b7d;
  --white: #ffffff;
  --border: #e2e8f0;
  --bg: #f4f7f9;
  --danger: #c62828;
  --warn: #f57c00;
  --ok: #2d8f4e;
  --radius: 14px;
  --shadow: 0 8px 32px rgba(30, 58, 95, 0.08);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
  min-height: 100vh;
}

a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
img { max-width: 100%; display: block; }
ul { list-style: none; }

.portal-container {
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 1.25rem;
}

/* ===== Login ===== */
.login-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.login-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  background: var(--white);
  border-bottom: 1px solid var(--border);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: var(--navy);
}

.login-brand span { color: var(--green); }

.login-brand svg { width: 32px; height: 32px; }

.login-back {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-muted);
}

.login-main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1.25rem;
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 1.75rem 1.5rem;
}

.login-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  background: var(--green-light);
  color: var(--green);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  margin-bottom: 1rem;
}

.login-card h1 {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--navy);
  line-height: 1.25;
  margin-bottom: 0.5rem;
}

.login-card .login-desc {
  font-size: 0.9375rem;
  color: var(--text-muted);
  margin-bottom: 1.5rem;
}

.login-error {
  background: #fdecea;
  color: var(--danger);
  border-radius: 10px;
  padding: 0.75rem 0.875rem;
  font-size: 0.875rem;
  margin-bottom: 1rem;
}

.field { margin-bottom: 1rem; }

.field label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--navy);
  margin-bottom: 0.375rem;
}

.field input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.8rem 0.9rem;
  background: #fafbfc;
  color: var(--text);
}

.field input:focus {
  outline: 2px solid rgba(45, 143, 78, 0.25);
  border-color: var(--green);
  background: var(--white);
}

.field-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.4rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  border: 2px solid transparent;
  border-radius: 10px;
  padding: 0.8rem 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: 0.2s ease;
}

.btn--primary {
  background: var(--green);
  border-color: var(--green);
  color: var(--white);
}

.btn--primary:hover { background: var(--green-hover); }

.btn--ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--navy);
}

.btn--google {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  width: 100%;
  background: var(--white);
  border-color: var(--border);
  color: var(--navy);
}

.btn--google:hover { background: #f8fafc; }

.btn--google:disabled {
  opacity: 0.65;
  cursor: wait;
}

.btn--sm {
  width: auto;
  padding: 0.5rem 0.875rem;
  font-size: 0.8125rem;
}

.login-card--wide {
  max-width: 520px;
}

.login-desc--compact {
  margin-bottom: 1.25rem;
}

.persona-radios {
  border: none;
  margin: 0 0 1.25rem;
  padding: 0;
}

.persona-radios__legend {
  font-size: 0.8125rem;
  font-weight: 700;
  color: var(--navy);
  margin-bottom: 0.75rem;
}

.persona-radios__grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.625rem;
}

.persona-radio {
  cursor: pointer;
}

.persona-radio input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.persona-radio__card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.2rem;
  padding: 0.85rem 0.9rem;
  border: 2px solid var(--border);
  border-radius: 12px;
  background: #fafbfc;
  transition: border-color 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
}

.persona-radio__icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--green-light);
  color: var(--green);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 0.35rem;
}

.persona-radio__icon svg {
  width: 18px;
  height: 18px;
}

.persona-radio__icon--admin {
  background: #e8f0fe;
  color: #2563eb;
}

.persona-radio__label {
  font-size: 0.875rem;
  font-weight: 800;
  color: var(--navy);
}

.persona-radio__hint {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.persona-radio input:checked + .persona-radio__card {
  border-color: var(--green);
  background: #f3faf5;
  box-shadow: 0 0 0 3px rgba(45, 143, 78, 0.12);
}

.persona-radio input:focus-visible + .persona-radio__card {
  outline: 2px solid var(--green);
  outline-offset: 2px;
}

@media (min-width: 640px) {
  .persona-radios__grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .persona-radio__card {
    min-height: 132px;
  }
}

.login-method {
  margin-bottom: 0.25rem;
}

.login-method__title {
  font-size: 0.9375rem;
  font-weight: 800;
  color: var(--navy);
  margin-bottom: 0.25rem;
}

.login-method__hint {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-bottom: 0.875rem;
}

.portal-picker {
  width: 100%;
  max-width: 820px;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 1.75rem 1.5rem;
}

.portal-picker h1 {
  font-size: clamp(1.375rem, 4vw, 1.75rem);
  font-weight: 800;
  color: var(--navy);
  line-height: 1.25;
  margin-bottom: 0.5rem;
}

.persona-grid {
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
  margin-top: 1.5rem;
}

.persona-card {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 1.15rem 1.125rem;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #fafbfc;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.15s ease;
}

.persona-card:hover {
  border-color: var(--green);
  box-shadow: var(--shadow);
  transform: translateY(-1px);
}

.persona-card__icon {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: var(--green-light);
  color: var(--green);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 0.35rem;
}

.persona-card__icon svg {
  width: 20px;
  height: 20px;
}

.persona-card__title {
  font-size: 1rem;
  font-weight: 800;
  color: var(--navy);
}

.persona-card__desc {
  font-size: 0.875rem;
  color: var(--text-muted);
  line-height: 1.45;
}

.persona-card--admin .persona-card__icon {
  background: #e8f0fe;
  color: #2563eb;
}

@media (min-width: 768px) {
  .persona-grid {
    flex-direction: row;
    align-items: stretch;
  }

  .persona-card {
    flex: 1;
  }
}

.login-divider {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 1.25rem 0;
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.login-divider::before,
.login-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.login-alt {
  margin-top: 1.25rem;
  text-align: center;
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.login-alt a {
  color: var(--green);
  font-weight: 700;
}

.login-links {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.otp-actions {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  margin-top: 0.75rem;
}

.otp-actions button {
  background: none;
  border: none;
  color: var(--green);
  font-weight: 700;
  font-size: 0.8125rem;
  cursor: pointer;
}

/* ===== Dashboard shell ===== */
.dash-page { min-height: 100vh; }

.dash-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--white);
  border-bottom: 1px solid var(--border);
}

.dash-header__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 64px;
  padding: 0.75rem 0;
}

.dash-user {
  min-width: 0;
}

.dash-user__name {
  font-size: 0.9375rem;
  font-weight: 700;
  color: var(--navy);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dash-user__meta {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.dash-header__actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.society-select {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.4rem 0.6rem;
  background: var(--white);
  color: var(--navy);
  font-size: 0.8125rem;
  max-width: 160px;
}

.dash-main {
  padding: 1.25rem 0 2.5rem;
}

.dash-hero {
  margin-bottom: 1.25rem;
}

.dash-hero h1 {
  font-size: clamp(1.25rem, 4vw, 1.75rem);
  font-weight: 800;
  color: var(--navy);
  margin-bottom: 0.35rem;
}

.dash-hero p {
  font-size: 0.875rem;
  color: var(--text-muted);
}

.role-pill {
  display: inline-flex;
  margin-top: 0.65rem;
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  background: var(--green-light);
  color: var(--green);
  font-size: 0.75rem;
  font-weight: 700;
}

.metrics-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.metric-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: 0 2px 12px rgba(30, 58, 95, 0.04);
}

.metric-card__label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}

.metric-card__value {
  font-size: 1.125rem;
  font-weight: 800;
  color: var(--navy);
  line-height: 1.2;
}

.metric-card__note {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.35rem;
}

.metric-card--wide {
  grid-column: 1 / -1;
}

.panel {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.125rem;
  margin-bottom: 1rem;
  box-shadow: 0 2px 12px rgba(30, 58, 95, 0.04);
}

.panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.875rem;
}

.panel__title {
  font-size: 1rem;
  font-weight: 800;
  color: var(--navy);
}

.health-bar {
  height: 10px;
  background: #e8eef4;
  border-radius: 999px;
  overflow: hidden;
  margin: 0.5rem 0 0.35rem;
}

.health-bar__fill {
  height: 100%;
  background: linear-gradient(90deg, #2d8f4e, #57b872);
  border-radius: inherit;
}

.attendance-row {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.attendance-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem;
  background: #f8fafc;
  border-radius: 10px;
}

.attendance-item strong {
  display: block;
  font-size: 0.875rem;
  color: var(--navy);
}

.attendance-item span {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.badge--pending { background: #fff3e0; color: var(--warn); }
.badge--closed { background: var(--green-light); color: var(--ok); }
.badge--open { background: #e8f0fe; color: #2563eb; }
.badge--progress { background: #f3e8ff; color: #7c3aed; }

.issue-list,
.request-list {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.issue-item,
.request-item {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 10px;
}

.issue-item__top,
.request-item__top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
}

.issue-item__title,
.request-item__title {
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--navy);
}

.issue-item__meta,
.request-item__meta {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.actions-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
}

.action-card {
  display: flex;
  align-items: flex-start;
  gap: 0.875rem;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--white);
  text-align: left;
  cursor: pointer;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.action-card:hover {
  border-color: var(--green);
  box-shadow: var(--shadow);
}

.action-card__icon {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: var(--green-light);
  color: var(--green);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.action-card__icon svg { width: 20px; height: 20px; }

.action-card__title {
  font-size: 0.9375rem;
  font-weight: 700;
  color: var(--navy);
  margin-bottom: 0.2rem;
}

.action-card__desc {
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: none;
  align-items: flex-end;
  justify-content: center;
  background: rgba(21, 42, 69, 0.45);
  padding: 1rem;
}

.modal.is-open { display: flex; }

.modal__panel {
  width: 100%;
  max-width: 480px;
  background: var(--white);
  border-radius: 18px 18px 14px 14px;
  padding: 1.25rem;
  max-height: 85vh;
  overflow: auto;
}

.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.modal__header h2 {
  font-size: 1.125rem;
  font-weight: 800;
  color: var(--navy);
}

.modal__close {
  border: none;
  background: #f1f5f9;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1.25rem;
  color: var(--navy);
}

.chat-box {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-height: 220px;
  max-height: 320px;
  overflow: auto;
  margin-bottom: 0.875rem;
  padding: 0.75rem;
  background: #f8fafc;
  border-radius: 12px;
}

.chat-msg {
  max-width: 85%;
  padding: 0.65rem 0.85rem;
  border-radius: 12px;
  font-size: 0.875rem;
}

.chat-msg--admin {
  align-self: flex-start;
  background: var(--white);
  border: 1px solid var(--border);
}

.chat-msg--user {
  align-self: flex-end;
  background: var(--green);
  color: var(--white);
}

.chat-compose {
  display: flex;
  gap: 0.5rem;
}

.chat-compose input {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.7rem 0.85rem;
}

.modal__panel--chat {
  max-width: 440px;
  width: 100%;
}

.modal__panel--chat .modal__header {
  align-items: flex-start;
}

.modal__panel--chat .modal__header > div {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.chat-ai-link {
  border: none;
  background: none;
  padding: 0;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--green);
  cursor: pointer;
  text-align: left;
  width: fit-content;
}

.chat-ai-link:hover {
  text-decoration: underline;
}

.chat-ai-settings {
  margin-bottom: 0.75rem;
  padding: 0.75rem;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.chat-ai-field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
}

.chat-ai-field select,
.chat-ai-field input {
  font-weight: 500;
  color: var(--navy);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.55rem 0.65rem;
  font-size: 0.875rem;
}

.chat-ai-settings__actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.4rem;
}

.chat-msg--typing {
  padding: 0.75rem 1rem;
}

.chat-typing {
  display: inline-flex;
  gap: 4px;
  align-items: center;
}

.chat-typing i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #94a3b8;
  display: inline-block;
  animation: chat-bounce 1.2s infinite ease-in-out;
}

.chat-typing i:nth-child(2) { animation-delay: 0.15s; }
.chat-typing i:nth-child(3) { animation-delay: 0.3s; }

@keyframes chat-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40% { transform: translateY(-4px); opacity: 1; }
}

.chat-msg em {
  font-style: normal;
  font-weight: 600;
  color: var(--green);
}

.chat-msg--admin em {
  color: var(--green);
}

.chat-msg code {
  font-size: 0.75rem;
  background: #f1f5f9;
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
}

.chat-hint {
  display: block;
  margin-top: 0.4rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.chat-bill-preview {
  margin-top: 0.65rem;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
  max-width: 220px;
}

.chat-bill-preview img {
  display: block;
  width: 100%;
  height: auto;
  max-height: 180px;
  object-fit: cover;
}

/* Demo Razorpay sheet when Key ID is not configured */
.rzp-demo {
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 1rem;
}

.rzp-demo__sheet {
  background: var(--white);
  border-radius: 16px 16px 12px 12px;
  padding: 1.25rem 1.35rem 1.35rem;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.25);
}

.rzp-demo__brand {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #3395ff;
  margin-bottom: 0.75rem;
}

.rzp-demo__sheet h3 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--navy);
  margin: 0 0 0.35rem;
}

.rzp-demo__amount {
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--navy);
  margin: 0.25rem 0 0.5rem;
}

.rzp-demo__meta {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin: 0 0 0.75rem;
  line-height: 1.45;
}

.rzp-demo__note {
  font-size: 0.75rem;
  color: var(--text-muted);
  background: #f8fafc;
  border-radius: 8px;
  padding: 0.55rem 0.65rem;
  margin: 0 0 1rem;
}

.rzp-demo__note code {
  font-size: 0.7rem;
}

.rzp-demo__actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
}

@media (min-width: 768px) {
  .rzp-demo {
    align-items: center;
  }

  .rzp-demo__sheet {
    border-radius: 16px;
  }
}

.restricted-note {
  font-size: 0.8125rem;
  color: var(--text-muted);
  background: #f8fafc;
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 0.75rem;
}

@media (min-width: 768px) {
  .metrics-grid {
    grid-template-columns: repeat(4, 1fr);
  }

  .metric-card--wide {
    grid-column: auto;
  }

  .attendance-row {
    flex-direction: row;
  }

  .attendance-item { flex: 1; }

  .actions-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .dash-panels {
    display: grid;
    grid-template-columns: 1.2fr 1fr;
    gap: 1rem;
  }

  .dash-panels .panel { margin-bottom: 0; }

  .modal {
    align-items: center;
  }
}
