/* Minimalist, Tasteful Dark Theme (Obsidian & Slate) */
:root {
  --primary-color: #ffffff; /* Stark white primary buttons */
  --primary-hover: #e2e8f0;
  --bg-app: #090a0f; /* Deep obsidian background */
  --bg-card: #12131a; /* Elegant slate card panel */
  --bg-darker: #1c1e29; /* Accent panel/headers background */
  --border-stark: rgba(255, 255, 255, 0.08); /* Ultra-subtle border line */
  --text-primary: #ffffff; /* Stark white text */
  --text-muted: #888d9e; /* Muted cool gray text */

  --accent-positive: #34d399; /* Vibrant emerald green */
  --accent-positive-soft: rgba(52, 211, 153, 0.08);
  --accent-negative: #fb7185; /* Vibrant rose red */
  --accent-negative-soft: rgba(251, 113, 133, 0.08);

  --font-sans:
    system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono:
    "SFMono-Regular", Consolas, "Liberation Mono", Menlo, Courier, monospace;

  /* Smooth curves */
  --radius-pill: 9999px;
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 24px;

  /* Deep Soft Shadows */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3), 0 1px 2px rgba(0, 0, 0, 0.2);
  --shadow-md:
    0 4px 6px -1px rgba(0, 0, 0, 0.4), 0 2px 4px -1px rgba(0, 0, 0, 0.2);
  --shadow-lg:
    0 10px 25px -5px rgba(0, 0, 0, 0.5), 0 8px 10px -6px rgba(0, 0, 0, 0.3);
  --shadow-premium: 0 20px 40px -15px rgba(0, 0, 0, 0.6);

  --transition-stark: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Base resets */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-app);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Header design */
.main-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background-color: rgba(9, 10, 15, 0.85); /* Deep dark background glass */
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-stark);
}

.header-container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1.25rem 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.brand-icon {
  width: 22px;
  height: 22px;
  color: var(--primary-color);
}

.logo-text {
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.04em;
}

.logo-accent {
  color: var(--accent-positive);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.status-wrapper {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  background-color: var(--bg-darker);
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-pill);
}

.status-indicator {
  width: 6px;
  height: 6px;
  background-color: var(--accent-positive);
  border-radius: 50%;
}

/* Premium Status Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.35rem 0.8rem;
  font-size: 0.725rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-radius: var(--radius-pill);
  line-height: 1;
  transition: var(--transition-stark);
  border: 1px solid transparent;
  box-shadow: var(--shadow-sm);
}

/* Tiny indicator dot inside status badges */
.badge::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: currentColor;
}

/* State color maps for badges */
.badge-online {
  background-color: var(--accent-positive-soft);
  color: var(--accent-positive);
  border-color: rgba(52, 211, 153, 0.15);
}

.badge-offline {
  background-color: var(--accent-negative-soft);
  color: var(--accent-negative);
  border-color: rgba(251, 113, 133, 0.15);
}

.badge-syncing {
  background-color: rgba(59, 130, 246, 0.1);
  color: #3b82f6;
  border-color: rgba(59, 130, 246, 0.15);
  animation: pulse-sync 1.5s infinite;
}

/* Legacy inline styling fallback interceptors */
[style*="background-color: #10b981"],
[style*="background-color: rgb(16, 185, 129)"] {
  background-color: var(--accent-positive-soft) !important;
  color: var(--accent-positive) !important;
  border-color: rgba(16, 185, 129, 0.15) !important;
}

[style*="background-color: #f59e0b"],
[style*="background-color: rgb(245, 158, 11)"] {
  background-color: var(--accent-negative-soft) !important;
  color: var(--accent-negative) !important;
  border-color: rgba(244, 63, 94, 0.15) !important;
}

[style*="background-color: #3b82f6"],
[style*="background-color: rgb(59, 130, 246)"] {
  background-color: rgba(59, 130, 246, 0.1) !important;
  color: #3b82f6 !important;
  border-color: rgba(59, 130, 246, 0.15) !important;
}

@keyframes pulse-sync {
  0%,
  100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.6;
    transform: scale(0.98);
  }
}

/* Main layouts */
.main-content {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1.5rem 1rem; /* Compact padding for small screens */
}

@media (min-width: 640px) {
  .main-content {
    padding: 3rem 2rem;
  }
}

.dashboard-header {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 3rem;
  border-bottom: 1px solid var(--border-stark);
  padding-bottom: 1.5rem;
}

@media (min-width: 640px) {
  .dashboard-header {
    flex-direction: row;
    align-items: flex-end;
  }
}

.section-title {
  font-size: 2.25rem;
  font-weight: 800;
  letter-spacing: -0.05em;
}

.section-subtitle {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

.conversion-badge {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-primary);
  border: 1px solid var(--border-stark);
  padding: 0.5rem 1rem;
  background-color: var(--bg-card);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-sm);
}

/* Perfect Horizontal Centering on Mobile */
.kids-grid {
  display: grid;
  grid-template-columns: repeat(
    auto-fit,
    minmax(280px, 1fr)
  ); /* auto-fit dynamically centers items */
  gap: 1.75rem;
  justify-content: center;
  align-content: center;
  width: 100%;
}

/* Beautiful Rounded Cards */
.kid-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-stark);
  border-radius: var(--radius-lg);
  padding: 2rem;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-sm);
  transition: var(--transition-stark);
}

.kid-card:hover {
  border-color: rgba(255, 255, 255, 0.15);
  box-shadow: var(--shadow-premium);
  transform: translateY(-2px);
}

.kid-card-header {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  margin-bottom: 1.5rem;
}

.avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--bg-darker);
  background-color: var(--bg-darker);
  box-shadow: var(--shadow-sm);
}

.kid-card-info h3 {
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.03em;
}

.points-header-value {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Dynamic sub-header balance colors (white when exactly zero) */
.points-header-value.text-neutral {
  color: var(--text-primary) !important;
}

.points-header-value.text-positive {
  color: var(--accent-positive) !important;
}

.points-header-value.text-negative {
  color: var(--accent-negative) !important;
}

/* Hide raw browser alt text overlaps if profile photo fails to load */
.avatar,
.modal-header-avatar,
.modal-status-avatar {
  font-size: 0 !important;
}

.kid-card-body {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  border-top: 1px dashed var(--border-stark);
  padding-top: 1.5rem;
  margin-bottom: 1.75rem;
}

.points-value {
  font-family: var(--font-mono);
  font-size: 2.25rem;
  font-weight: 700;
  letter-spacing: -0.05em;
}

.currency-value {
  font-family: var(--font-mono);
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-muted);
}

/* Superscript Currency Symbol styling */
.currency-symbol {
  font-size: 0.52em;
  position: relative;
  top: -0.42em;
  font-weight: 700;
  margin-left: 0.05em;
  margin-right: 0.05em;
}

.kid-card-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: auto;
}

/* Smooth Soft Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 0.75rem;
  border-radius: var(--radius-md);
  border: none;
  cursor: pointer;
  transition: var(--transition-stark);
  font-family: var(--font-sans);
  white-space: nowrap; /* Forces text to stay on a single line */
}

/* High-contrast solid white buttons for premium dark-mode chic */
.btn-primary {
  background-color: var(--primary-color); /* #ffffff */
  color: #000000; /* deep black text */
}

.btn-primary:hover:not(:disabled) {
  background-color: var(--primary-hover);
  box-shadow: var(--shadow-md);
}

.btn-secondary {
  background-color: transparent;
  color: var(--text-primary);
  border: 1px solid var(--border-stark);
}

.btn-secondary:hover:not(:disabled) {
  border-color: var(--text-primary);
  background-color: var(--bg-darker);
}

.btn-secondary-icon {
  background-color: var(--bg-card);
  border: 1px solid var(--border-stark);
  color: var(--text-primary);
  padding: 0.6rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-sm);
}

.btn-secondary-icon:hover {
  border-color: var(--text-primary);
  background-color: var(--bg-darker);
}

.btn-small {
  padding: 0.85rem 0.75rem; /* Spacious padding */
  flex: 1;
}

/* Micro-adjustments specifically for extremely narrow mobile screens (under 380px) */
@media (max-width: 380px) {
  .btn-small {
    font-size: 0.6875rem;
    padding: 0.85rem 0.5rem;
    letter-spacing: 0.02em;
  }
}

.btn-full {
  width: 100%;
  padding: 1rem;
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.icon-sm {
  width: 16px;
  height: 16px;
}
.icon-md {
  width: 20px;
  height: 20px;
}

/* Auth Views */
.auth-wrapper {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: calc(80vh - 100px);
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background-color: var(--bg-card);
  padding: 3rem 2.5rem;
  border: 1px solid var(--border-stark);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}

.auth-header {
  text-align: left;
  margin-bottom: 2rem;
}

.auth-header h2 {
  font-size: 1.75rem;
  font-weight: 800;
  letter-spacing: -0.05em;
}

.auth-header p {
  color: var(--text-muted);
  font-size: 0.8125rem;
  margin-top: 0.25rem;
}

.font-wide {
  letter-spacing: 0.1em;
}

/* Preset Pill capsule buttons */
.preset-pill-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
  margin-bottom: 0.25rem;
}

.preset-pill {
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-stark);
  background-color: var(--bg-card);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.875rem;
  padding: 0.65rem 0.5rem;
  cursor: pointer;
  transition: var(--transition-stark);
  box-shadow: var(--shadow-sm);
}

.preset-pill:hover {
  border-color: var(--text-primary);
  transform: translateY(-1px);
}

.preset-pill.active {
  background-color: var(--primary-color);
  color: #000000;
  border-color: var(--primary-color);
  box-shadow: var(--shadow-md);
}

.preset-add {
  color: var(--accent-positive);
  background-color: var(--accent-positive-soft);
}

.preset-sub {
  color: var(--accent-negative);
  background-color: var(--accent-negative-soft);
}

.preset-pill.active.preset-add,
.preset-pill.active.preset-sub {
  color: #000000;
}

/* Reset default native browser dialog styling completely */
dialog,
dialog:modal,
.compact-modal,
.full-width-modal {
  border: none !important;
  outline: none !important;
  background: transparent !important;
  box-shadow: none !important;
  margin: auto;
}

/* Rounded, frosted-glass overlay blurs */
dialog::backdrop {
  background-color: rgba(0, 0, 0, 0.45) !important;
  backdrop-filter: blur(16px) !important;
  -webkit-backdrop-filter: blur(16px) !important;
}

.modal-viewport {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

/* Absolute Full-Screen modal drawer layout */
.full-width-modal {
  width: 100vw !important;
  height: 100vh !important;
  max-width: 100vw !important;
  max-height: 100vh !important;
  position: fixed;
  top: 0;
  left: 0;
  transform: none !important;
  margin: 0;
  overflow: hidden;
}

.full-width-modal .modal-viewport {
  padding: 0 !important;
  width: 100%;
  height: 100%;
}

.full-width-modal .modal-box {
  width: 100%;
  height: 100%;
  max-width: 100% !important;
  max-height: 100% !important;
  border-radius: 0 !important;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Floating Close Button - Styled globally as a perfect circle */
.modal-close-btn,
.absolute-close {
  background-color: var(--bg-card);
  border: 1px solid var(--border-stark) !important;
  box-shadow: var(--shadow-sm);
  width: 36px;
  height: 36px;
  border-radius: var(--radius-pill) !important;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-primary);
  transition: var(--transition-stark);
  padding: 0 !important;
  flex-shrink: 0;
}

.modal-close-btn:hover,
.absolute-close:hover {
  background-color: var(--bg-darker);
  border-color: var(--text-primary) !important;
  transform: rotate(90deg);
}

.absolute-close {
  position: absolute;
  top: 1.5rem;
  right: 1.5rem;
  z-index: 50;
  width: 40px;
  height: 40px;
}

/* Compact Modal (Edit Profile Settings) */
.compact-modal {
  width: calc(100% - 32px);
  max-width: 400px;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) !important;
}

.compact-modal .modal-viewport {
  padding: 0;
}

.modal-box {
  background-color: var(--bg-card);
  border: 1px solid var(--border-stark) !important;
  border-radius: var(--radius-lg) !important;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-premium);
}

.modal-box-narrow {
  width: 100%;
}

/* Compact Modal Header */
.modal-header {
  padding: 1.5rem 2rem;
  border-bottom: 1px solid var(--border-stark);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  background-color: var(--bg-card);
}

.title-sm {
  font-size: 1.25rem !important;
  font-weight: 800;
  letter-spacing: -0.03em;
}

/* Custom upload wrappers */
.file-upload-wrapper {
  position: relative;
  width: 100%;
}

.form-input-file {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  z-index: 2;
}

.file-upload-trigger {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.85rem 1.15rem;
  border: 1px dashed var(--border-stark);
  border-radius: var(--radius-md);
  background-color: var(--bg-app);
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--text-muted);
  transition: var(--transition-stark);
  pointer-events: none;
}

.file-upload-wrapper:hover .file-upload-trigger {
  border-color: var(--text-primary);
  color: var(--text-primary);
  background-color: var(--bg-darker);
}

/* Form Layout Stack with strictly protected inner padding bounds */
.form-stack {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  border: none !important;
  box-shadow: none !important;
  background: transparent !important;
}

.form-label {
  font-size: 0.725rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.form-input {
  width: 100%;
  padding: 0.85rem 1.15rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-stark);
  font-family: var(--font-sans);
  font-size: 0.9375rem;
  background-color: var(--bg-card);
  color: var(--text-primary);
  transition: var(--transition-stark);
  box-shadow: var(--shadow-sm);
}

.form-input:focus {
  outline: none;
  border-color: var(--text-primary);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.08);
}

/* Split Columns inside Full-Screen container */
.modal-split-body {
  display: flex;
  flex-direction: column;
  flex: 1; /* Automatically occupies all remaining vertical space below the header */
  min-height: 0; /* Permits nested scroll zones to calculate heights correctly */
  overflow-y: auto; /* Enables natural scrollbar container on mobile stack */
}

@media (min-width: 900px) {
  .modal-split-body {
    display: grid;
    grid-template-columns: 320px 1fr;
    grid-template-rows: 1fr;
    overflow: hidden; /* Lock the main grid containers on desktop viewports */
  }
}

/* Left Pane: Form stacked below kid's profile details */
.modal-pane-left {
  padding: 2.25rem 2rem;
  display: flex;
  flex-direction: column;
  gap: 2rem;
  height: auto;
  flex-shrink: 0; /* CRUCIAL: Prevents the browser from squeezing the input form height to 0 */
  background-color: var(--bg-card);
  border-bottom: 1px solid var(--border-stark);
}

@media (min-width: 900px) {
  .modal-pane-left {
    height: 100%;
    border-bottom: none;
    border-right: 1px solid var(--border-stark);
  }
}

/* Profile modal body padding safeguard (prevents inputs from touching screen edges) */
.modal-body,
.compact-modal .modal-body {
  padding: 2.25rem 2rem !important;
  border: none !important;
  box-shadow: none !important;
}

/* Minimalist Profile status card - Ordered first */
.minimal-profile-status {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding-bottom: 0;
  border-top: none;
  background-color: var(--bg-card);
}

.modal-status-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--bg-darker);
}

.modal-status-info h3 {
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.1;
}

.modal-balance-value {
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
  margin-top: 0.15rem;
}

.modal-points-digits {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 700;
}

.modal-points-sub {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-muted);
}

/* Right Pane: Maximized to use left/right space fully */
.modal-pane-right {
  padding: 2.25rem 1rem;
  display: flex;
  flex-direction: column;
  background-color: #0e1017; /* Slate black split pane background */
  overflow: hidden;
  height: auto;
  flex-shrink: 0;
}

@media (min-width: 640px) {
  .modal-pane-right {
    padding: 2.25rem 1.5rem;
  }
}

@media (min-width: 900px) {
  .modal-pane-right {
    flex-shrink: 1; /* Permit it to shrink to fit the split grid column strictly on desktop */
    height: 100%;
    overflow: hidden; /* Lock the table container scroll boundaries on desktop */
  }
}

/* Scrollable transaction container */
.ledger-container {
  overflow-y: visible; /* Dynamic heights allowed on mobile */
  border: 1px solid var(--border-stark);
  border-radius: var(--radius-md);
  background-color: var(--bg-card);
  box-shadow: var(--shadow-sm);
}

@media (min-width: 900px) {
  .ledger-container {
    flex: 1;
    overflow-y: auto; /* Independent list scrolling strictly on desktop */
  }
}

.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
}

.history-table th {
  position: sticky;
  top: 0;
  background-color: var(--bg-darker);
  color: var(--text-primary);
  font-weight: 800;
  text-align: left;
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid var(--border-stark);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  z-index: 10;
}

.history-table td {
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid var(--border-stark);
  color: var(--text-primary);
}

/* Smaller description to reduce line wraps */
.td-description {
  font-size: 0.775rem !important;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.3;
  vertical-align: middle;
}

.activity-text {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.25;
}

.activity-date {
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--text-muted); /* Muted slate date */
  margin-top: 0.2rem;
  line-height: 1.1;
}

.history-table tr:last-child td {
  border-bottom: none;
}

.history-table tr:hover td {
  background-color: var(--bg-app);
}

.text-right {
  text-align: right;
}

/* Color codes */
.text-positive {
  color: var(--accent-positive) !important;
}
.text-negative {
  color: var(--accent-negative) !important;
}

/* Empty state styling */
.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 5rem 2rem;
  background-color: var(--bg-card);
  border: 1px dashed var(--border-stark);
  border-radius: var(--radius-lg);
}

.empty-state p {
  font-weight: 800;
  font-size: 1.25rem;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.empty-state span {
  color: var(--text-muted);
  font-size: 0.875rem;
  display: block;
  margin-top: 0.25rem;
}

#sync-btn.syncing svg {
  animation: spin-animation 1s linear infinite;
}

#sync-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

@keyframes spin-animation {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}
