:root {
  --bg: #f8faff;
  --paper: #ffffff;
  --ink: #1f1f1f;
  --muted: #5f6368;
  --brand: #4285f4;
  --brand-soft: #e8f0fe;
  --accent: #ea4335;
  --success: #34a853;
  --warn: #fbbc04;
  --border: #dfe5f1;
  --shadow: 0 12px 30px rgba(66, 133, 244, 0.12);
}

body[data-theme="dark"] {
  --bg: #11151d;
  --paper: #1a202b;
  --ink: #eef3ff;
  --muted: #b8c3d8;
  --brand: #8ab4f8;
  --brand-soft: #22324a;
  --accent: #f28b82;
  --success: #81c995;
  --warn: #fdd663;
  --border: #2f3b4f;
  --shadow: 0 14px 34px rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
}

/* Accessibility: High-contrast focus state for keyboard navigation */
*:focus-visible {
  outline: 3px solid var(--brand);
  outline-offset: 2px;
  border-radius: 4px;
}

body {
  margin: 0;
  font-family: "Manrope", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top right, #e8f0fe 0%, var(--bg) 42%),
    linear-gradient(120deg, #fff4ea 0%, #eef7ff 55%, #effbf4 100%);
  min-height: 100vh;
}

body[data-theme="dark"] {
  background:
    radial-gradient(circle at top right, #1f2c45 0%, var(--bg) 45%),
    linear-gradient(120deg, #151a24 0%, #172131 55%, #17251f 100%);
}

.app-shell {
  width: min(980px, 92vw);
  margin: 2rem auto 3rem;
  display: grid;
  gap: 1rem;
}

.hero {
  background: linear-gradient(140deg, #fff2f0 0%, #fff9e9 35%, #ecf5ff 70%, #eefbf3 100%);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 1.2rem 1.4rem;
  box-shadow: var(--shadow);
}

body[data-theme="dark"] .hero {
  background: linear-gradient(140deg, #392229 0%, #37311f 35%, #1f2d45 70%, #203226 100%);
}

.hero-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
}

.badge {
  display: inline-block;
  margin: 0 0 0.5rem;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.78rem;
  color: #174ea6;
  background: var(--brand-soft);
}

body[data-theme="dark"] .badge {
  color: #ffffff;
}

body[data-theme="dark"] .ai-status-on,
body[data-theme="dark"] .ai-status-off {
  color: #ffffff;
}

body[data-theme="dark"] .icon-btn {
  color: #ffffff;
}

body[data-theme="dark"] .theme-toggle {
  background: #443a1d;
  color: #ffffff;
  border-color: #6a5b2a;
}

body[data-theme="dark"] h1,
body[data-theme="dark"] .subtitle {
  color: #ffffff;
}

.theme-toggle {
  position: relative;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #fff8e1;
  color: #b06000;
  border: 1px solid #f6d86f;
  cursor: pointer;
  padding: 0;
  transition:
    background-color 0.3s ease,
    border-color 0.3s ease,
    color 0.3s ease;
}

body[data-theme="dark"] .theme-toggle {
  background: #443a1d;
  color: #ffe08a;
  border-color: #6a5b2a;
}

.theme-toggle i {
  position: absolute;
  font-size: 1.1rem;
  transition:
    transform 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55),
    opacity 0.3s ease;
}

/* Default (Light Mode) state */
.theme-toggle .sun-icon {
  transform: translateY(0) rotate(0deg);
  opacity: 1;
}

.theme-toggle .moon-icon {
  transform: translateY(30px) rotate(-90deg);
  opacity: 0;
}

/* Dark Mode state */
body[data-theme="dark"] .theme-toggle .sun-icon {
  transform: translateY(-30px) rotate(90deg);
  opacity: 0;
}

body[data-theme="dark"] .theme-toggle .moon-icon {
  transform: translateY(0) rotate(0deg);
  opacity: 1;
}

.header-logo-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 1.2rem;
}

.portal-logo {
  width: 64px;
  height: 64px;
  object-fit: contain;
}

h1 {
  margin: 0;
  font-size: clamp(1.8rem, 4vw, 2.6rem);
  letter-spacing: -0.02em;
}

.subtitle {
  margin: 0.5rem 0 0;
  color: var(--muted);
}

.card {
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 1.1rem;
  box-shadow: var(--shadow);
}

h2 {
  margin: 0 0 0.8rem;
  font-size: 1.15rem;
}

.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.8rem;
}

label {
  display: grid;
  gap: 0.4rem;
  font-weight: 600;
  font-size: 0.92rem;
}

input,
select,
textarea,
button {
  font: inherit;
}

input,
select,
textarea {
  border: 1px solid #c8d1e8;
  border-radius: 10px;
  padding: 0.65rem 0.7rem;
  background: #fff;
  color: var(--ink);
}

body[data-theme="dark"] input,
body[data-theme="dark"] select,
body[data-theme="dark"] textarea {
  background: #121827;
  border-color: #384055;
}

textarea {
  resize: vertical;
}

.actions {
  margin-top: 0.9rem;
  display: flex;
  gap: 0.7rem;
}

button {
  border: 0;
  border-radius: 10px;
  padding: 0.65rem 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s ease;
}

button:hover {
  transform: translateY(-1px);
}

#generateBtn {
  color: #fff;
  background: linear-gradient(130deg, #4285f4 0%, #34a853 100%);
}

button.ghost {
  background: #fff3cd;
  color: #9c5300;
}

body[data-theme="dark"] button.ghost {
  background: #3b3120;
  color: #ffe2a8;
}

.output {
  margin-top: 1rem;
  border: 1px dashed #d6e1f3;
  border-radius: 12px;
  padding: 0.9rem;
  background: #fffdf9;
}

body[data-theme="dark"] .output {
  background: #141b2a;
  border-color: #3a4256;
}

.output h3 {
  margin-top: 0;
}

.output h4 {
  margin-bottom: 0.25rem;
  font-size: 1rem;
  color: var(--brand);
}

.output p,
.output li {
  margin: 0.35rem 0;
  line-height: 1.5;
}

.output ul,
.output ol {
  margin: 0.2rem 0 0.65rem 1.1rem;
}

.tip {
  border-left: 4px solid var(--success);
  padding-left: 0.6rem;
}

/* AI Status Indicator */
.ai-status-off,
.ai-status-on {
  padding: 0.375rem 0.75rem;
  border-radius: 0.375rem;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: default;
}

.ai-status-off {
  background-color: #f3f3f3;
  color: var(--muted);
}

body[data-theme="dark"] .ai-status-off {
  background-color: #2a2a2a;
  color: var(--muted);
}

.ai-status-on {
  background-color: #d4edda;
  color: #155724;
}

body[data-theme="dark"] .ai-status-on {
  background-color: #1e4620;
  color: #81c995;
}

/* Settings Button */
.icon-btn {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border-radius: 0.375rem;
  transition: background-color 0.2s ease;
}

.icon-btn:hover {
  background-color: var(--brand-soft);
}

body[data-theme="dark"] .icon-btn:hover {
  background-color: var(--brand-soft);
}

.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-content {
  background-color: var(--paper);
  border-radius: 0.75rem;
  box-shadow: var(--shadow);
  max-width: 500px;
  width: 90vw;
  max-height: 80vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.5rem;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  margin: 0;
  font-size: 1.25rem;
}

body[data-theme="dark"] .modal-header h2 {
  color: #ffffff;
}

.close-btn {
  background: none;
  border: none;
  font-size: 2rem;
  cursor: pointer;
  color: var(--muted);
  padding: 0;
  width: 2rem;
  height: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s ease;
}

.close-btn:hover {
  color: var(--ink);
}

.modal-body {
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

body[data-theme="dark"] .modal-body {
  color: #ffffff;
}

.modal-body label {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.input-wrapper input {
  width: 100%;
  padding-right: 2.5rem !important;
}

.field-icon-btn {
  position: absolute;
  right: 0.5rem;
  background: none;
  border: none;
  padding: 0.4rem;
  cursor: pointer;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s ease;
}

.field-icon-btn:hover {
  color: var(--brand);
}

body[data-theme="dark"] .modal-body label {
  color: #ffffff;
}

.modal-body input[type="password"],
.modal-body input[type="text"] {
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  font-family: "Manrope", sans-serif;
  font-size: 1rem;
  color: var(--ink);
  background-color: var(--paper);
}

body[data-theme="dark"] .modal-body input[type="password"],
body[data-theme="dark"] .modal-body input[type="text"] {
  color: #ffffff;
  background-color: #121827;
  border-color: #384055;
}

.modal-body input[type="password"]:focus,
.modal-body input[type="text"]:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}

.modal-body small {
  font-size: 0.875rem;
  color: var(--muted);
}

body[data-theme="dark"] .modal-body small {
  color: #b8c3d8;
}

.modal-body small a {
  color: var(--brand);
  text-decoration: none;
}

.modal-body small a:hover {
  text-decoration: underline;
}

.modal-body input[type="checkbox"] {
  width: 1.25rem;
  height: 1.25rem;
  cursor: pointer;
  accent-color: var(--brand);
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 1rem;
  padding: 1.5rem;
  border-top: 1px solid var(--border);
}

.hero-actions {
  display: flex;
  align-items: center;
  gap: 0.8rem;
}

@media (max-width: 760px) {
  .grid {
    grid-template-columns: 1fr;
  }

  .app-shell {
    margin-top: 1rem;
  }

  /* Make hero header elements wrap and center neatly */
  .hero-tools {
    flex-wrap: wrap;
    justify-content: center;
  }

  .badge {
    width: fit-content;
    text-align: center;
    margin: 0 auto 0.8rem;
    border-radius: 8px; /* Fix pill shape distortion */
    padding: 0.4rem 0.8rem;
  }

  .header-logo-row {
    flex-direction: column;
    justify-content: center;
    text-align: center;
    margin-top: 0.5rem;
  }

  .subtitle {
    text-align: center;
  }
}

/* =========================================
   Context-Based Loader
   ========================================= */
#initial-loader {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition:
    opacity 0.6s ease,
    visibility 0.6s ease;
}

#initial-loader.hidden {
  opacity: 0;
  visibility: hidden;
}

.ballot-loader {
  width: 60px;
  height: 60px;
  border: 4px solid var(--brand);
  border-radius: 8px;
  position: relative;
  background: var(--paper);
}

/* The actual "vote" falling in with Indian flag colors */
.ballot-loader::before {
  content: "";
  position: absolute;
  top: -30px;
  left: 50%;
  transform: translateX(-50%);
  width: 25px;
  height: 35px;
  background: linear-gradient(
    to bottom,
    #ff9933 33.3%,
    #ffffff 33.3%,
    #ffffff 66.6%,
    #138808 66.6%
  );
  border: 1px solid var(--border);
  animation: dropVote 1.4s infinite ease-in;
  border-radius: 3px;
  z-index: -1;
}

/* The slot in the ballot box */
.ballot-loader::after {
  content: "";
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  width: 38px;
  height: 4px;
  background: var(--ink);
  border-radius: 2px;
}

@keyframes dropVote {
  0% {
    transform: translate(-50%, -40px);
    opacity: 0;
  }
  15% {
    opacity: 1;
  }
  60% {
    transform: translate(-50%, 5px);
    opacity: 1;
  }
  100% {
    transform: translate(-50%, 25px);
    opacity: 0;
  }
}

.loader-text {
  margin-top: 2rem;
  font-weight: 800;
  color: var(--ink);
  letter-spacing: 0.5px;
  animation: pulseText 1.4s infinite alternate;
}

@keyframes pulseText {
  from { opacity: 0.5; }
  to { opacity: 1; }
}

.footer-credit {
  margin-top: 2rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  text-align: center;
}

.google-services-cluster {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 1rem;
  margin-bottom: 1rem;
}

.google-svc-link {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  background: var(--brand-soft);
  color: var(--brand);
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 700;
  text-decoration: none;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  cursor: pointer;
  border: 1px solid transparent;
}

.google-svc-link:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(66, 133, 244, 0.15);
  border-color: var(--brand);
}

#googleSignInPlaceholder {
  background: white;
  color: #757575;
  border: 1px solid #ddd;
}

#googleSignInPlaceholder i {
  color: #4285f4;
}

.google-services-cluster {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
  margin-top: 2rem;
  width: 100%;
}

.google-svc-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 1rem;
}

#userProfileDisplay {
  background: white;
  color: var(--ink);
  border: 1px solid var(--border);
}

#userAvatar {
  display: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  object-fit: cover;
}

.map-preview {
  margin: 1.5rem 0;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--paper);
  animation: fadeIn 0.5s ease forwards;
  width: 100%;
}

.map-preview h4 {
  margin: 0.8rem 0;
  font-size: 0.9rem;
}

.hidden {
  display: none !important;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 600px) {
  .google-svc-row {
    flex-direction: column;
    align-items: stretch;
  }
}


