/* ============================================
   Avitia.pro — Dark Theme (Health Pal inspired)
   ============================================ */

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

:root {
  /* Backgrounds */
  --bg-base:      #0f0f1a;
  --bg-surface:   #1a1a2e;
  --bg-elevated:  #252a3f;
  --bg-input:     #2d3250;

  /* Primary */
  --primary:       #3b82f6;
  --primary-hover: #2563eb;
  --cyan:          #00d4ff;

  /* Semantic */
  --success:  #22c55e;
  --warning:  #fbbf24;
  --danger:   #ef4444;
  --info:     #8b5cf6;

  /* Text */
  --text:       #ffffff;
  --text-soft:  #e2e8f0;
  --text-muted: #9ca3af;
  --text-dim:   #6b7280;

  /* Borders */
  --border:      rgba(255, 255, 255, 0.08);
  --border-card: rgba(255, 255, 255, 0.05);

  /* Radius */
  --radius-sm:   8px;
  --radius-md:   12px;
  --radius-lg:   16px;
  --radius-pill: 9999px;

  /* Shadows */
  --shadow-card:     0 4px 6px  rgba(0, 0, 0, 0.25);
  --shadow-elevated: 0 8px 24px rgba(0, 0, 0, 0.35);
  --shadow-glow:     0 0 20px  rgba(59, 130, 246, 0.25);

  /* Spacing */
  --space-1:  4px;
  --space-2:  8px;
  --space-3:  12px;
  --space-4:  16px;
  --space-5:  20px;
  --space-6:  24px;
  --space-8:  32px;
  --space-10: 40px;
  --space-12: 48px;
  --space-16: 64px;

  /* Transitions */
  --tr-fast:   150ms ease-in-out;
  --tr-normal: 250ms ease-in-out;
  --tr-slow:   400ms ease-in-out;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg-base);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Layout ── */

.container {
  max-width: 1280px;
  margin: 0 auto;
  padding: var(--space-8) var(--space-6);
}

.grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-6);
}

.grid-full { grid-column: 1 / -1; }
.grid-2    { grid-column: span 2; }

@media (max-width: 1024px) {
  .grid { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-column: span 2; }
}

@media (max-width: 640px) {
  .grid { grid-template-columns: 1fr; }
  .grid-2, .grid-full { grid-column: span 1; }
  .container { padding: var(--space-6) var(--space-4); }
}

/* ── Cards ── */

.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  box-shadow: var(--shadow-card);
  animation: fade-up 0.5s ease-out both;
  transition: transform var(--tr-fast), box-shadow var(--tr-fast);
}

.card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-elevated);
}

.card:nth-child(1)  { animation-delay: 0.05s; }
.card:nth-child(2)  { animation-delay: 0.10s; }
.card:nth-child(3)  { animation-delay: 0.15s; }
.card:nth-child(4)  { animation-delay: 0.20s; }
.card:nth-child(5)  { animation-delay: 0.25s; }
.card:nth-child(6)  { animation-delay: 0.30s; }
.card:nth-child(7)  { animation-delay: 0.35s; }
.card:nth-child(8)  { animation-delay: 0.40s; }
.card:nth-child(9)  { animation-delay: 0.45s; }
.card:nth-child(10) { animation-delay: 0.50s; }

@keyframes fade-up {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Navbar ── */

.navbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-4) var(--space-6);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.navbar h1 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
}

.navbar-right {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

#user-info {
  font-size: 0.875rem;
  color: var(--text-muted);
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: 0.8rem;
  color: var(--text-muted);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 6px var(--success);
  animation: pulse-dot 2s infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; box-shadow: 0 0 6px var(--success); }
  50%      { opacity: 0.5; box-shadow: 0 0 12px var(--success); }
}

/* ── Hero ── */

.hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-16) 0;
  gap: var(--space-12);
}

.hero-content { max-width: 600px; }

.hero-heading {
  font-size: 3.25rem;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.02em;
  color: var(--text);
}

.hero-accent { color: var(--primary); }

.hero-subtitle {
  font-size: 1.125rem;
  color: var(--text-muted);
  line-height: 1.7;
  margin: var(--space-6) 0;
}

.hero-widget { text-align: center; }

.score-ring {
  position: relative;
  width: 160px;
  height: 160px;
  margin: 0 auto var(--space-4);
}

.score-ring svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.ring-bg {
  fill: none;
  stroke: var(--bg-elevated);
  stroke-width: 8;
}

.ring-fill {
  fill: none;
  stroke: var(--primary);
  stroke-width: 8;
  stroke-linecap: round;
  stroke-dashoffset: 339.29;
  animation: ring-fill-anim 1.5s ease-out forwards;
}

@keyframes ring-fill-anim {
  to { stroke-dashoffset: var(--ring-target, 0); }
}

.ring-value {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.5rem;
  font-weight: 700;
}

@media (max-width: 768px) {
  .hero {
    flex-direction: column;
    text-align: center;
    padding: var(--space-10) 0;
  }
  .hero-heading { font-size: 2.25rem; }
}

/* ── Section Headers ── */

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-6);
}

.section-title {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text);
}

/* ── Metric Cards ── */

.metric-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.metric-header {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.metric-icon {
  font-size: 1.25rem;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-elevated);
  border-radius: var(--radius-sm);
}

.metric-value {
  display: flex;
  align-items: baseline;
  gap: var(--space-3);
}

.metric-large {
  font-size: 3rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.metric-medium {
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.metric-footer {
  display: flex;
  gap: var(--space-4);
}

.metric-location {
  margin-top: var(--space-4);
  padding-top: var(--space-4);
  border-top: 1px solid var(--border);
}

/* ── Typography Utilities ── */

.card-title {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--text-soft);
}

.label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.caption {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-dim);
}

.body-text {
  font-size: 1rem;
  color: var(--text-soft);
  line-height: 1.6;
}

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

/* ── Trends ── */

.trend {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  font-size: 0.8rem;
  font-weight: 500;
}

.trend-up   { color: var(--success); }
.trend-down { color: var(--danger); }

/* ── Buttons ── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 0.625rem 1.25rem;
  font-size: 0.875rem;
  font-weight: 600;
  font-family: inherit;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--tr-fast),
              transform var(--tr-fast),
              box-shadow var(--tr-fast);
}

.btn:active {
  transform: translateY(1px) scale(0.98);
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover {
  background: var(--primary-hover);
  box-shadow: var(--shadow-glow);
  transform: translateY(-1px);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-danger:hover {
  background: #dc2626;
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-soft);
}
.btn-outline:hover {
  background: var(--bg-elevated);
  border-color: var(--text-dim);
}

.btn-ghost {
  background: transparent;
  color: var(--primary);
}
.btn-ghost:hover {
  background: rgba(59, 130, 246, 0.1);
}

.btn-lg {
  padding: 0.75rem 1.75rem;
  font-size: 1rem;
  border-radius: var(--radius-md);
}

.btn-sm {
  padding: 0.375rem 0.75rem;
  font-size: 0.8rem;
}

.btn-block { width: 100%; }

/* ── Badges / Pills ── */

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.65rem;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: var(--radius-pill);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.badge-success { background: rgba(34, 197, 94, 0.15);  color: var(--success); }
.badge-info    { background: rgba(139, 92, 246, 0.15); color: var(--info); }
.badge-warning { background: rgba(251, 191, 36, 0.15); color: var(--warning); }
.badge-danger  { background: rgba(239, 68, 68, 0.15);  color: var(--danger); }
.badge-neutral { background: var(--bg-elevated);        color: var(--text-muted); }

.role-badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  background: var(--primary);
  color: #fff;
  border-radius: var(--radius-pill);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ── Tabs ── */

.tab-bar {
  display: flex;
  gap: var(--space-1);
  background: var(--bg-elevated);
  border-radius: var(--radius-md);
  padding: var(--space-1);
  margin-bottom: var(--space-6);
}

.tab-bar button {
  flex: 1;
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
  font-weight: 500;
  font-family: inherit;
  color: var(--text-muted);
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--tr-fast);
}

.tab-bar button:hover {
  color: var(--text-soft);
}

.tab-bar button.active {
  background: var(--bg-surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

/* ── Forms ── */

.form-group {
  margin-bottom: var(--space-4);
}

label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: var(--space-1);
}

input[type="text"],
input[type="email"],
input[type="password"],
textarea {
  width: 100%;
  padding: 0.625rem 0.875rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-family: inherit;
  background: var(--bg-input);
  color: var(--text);
  outline: none;
  transition: border-color var(--tr-fast), box-shadow var(--tr-fast);
}

input:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

input::placeholder,
textarea::placeholder {
  color: var(--text-dim);
}

textarea {
  resize: vertical;
  min-height: 60px;
}

.form-row {
  display: flex;
  gap: var(--space-4);
  flex-wrap: wrap;
}

.form-row .form-group {
  flex: 1;
  min-width: 120px;
}

/* ── Tables ── */

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  padding: 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 0.875rem;
}

th {
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

td {
  color: var(--text-soft);
}

/* ── Fullscreen Background Animation ── */

.bg-animation {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

.bg-animation .orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.4;
  animation: orb-float 20s ease-in-out infinite alternate;
}

.bg-animation .orb:nth-child(1) {
  width: 500px; height: 500px;
  background: radial-gradient(circle, rgba(59,130,246,0.35), transparent 70%);
  top: -10%; left: -5%;
  animation-duration: 22s;
}

.bg-animation .orb:nth-child(2) {
  width: 400px; height: 400px;
  background: radial-gradient(circle, rgba(139,92,246,0.3), transparent 70%);
  bottom: -8%; right: -5%;
  animation-duration: 18s;
  animation-delay: -5s;
}

.bg-animation .orb:nth-child(3) {
  width: 300px; height: 300px;
  background: radial-gradient(circle, rgba(0,212,255,0.2), transparent 70%);
  top: 40%; left: 50%;
  transform: translate(-50%, -50%);
  animation-duration: 25s;
  animation-delay: -10s;
}

.bg-animation .orb:nth-child(4) {
  width: 250px; height: 250px;
  background: radial-gradient(circle, rgba(34,197,94,0.15), transparent 70%);
  top: 15%; right: 20%;
  animation-duration: 20s;
  animation-delay: -3s;
}

@keyframes orb-float {
  0%   { transform: translate(0, 0) scale(1); }
  25%  { transform: translate(60px, -40px) scale(1.1); }
  50%  { transform: translate(-30px, 50px) scale(0.95); }
  75%  { transform: translate(40px, 20px) scale(1.05); }
  100% { transform: translate(-50px, -30px) scale(1); }
}

.bg-animation .grid-lines {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(59,130,246,0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(59,130,246,0.03) 1px, transparent 1px);
  background-size: 60px 60px;
  animation: grid-drift 30s linear infinite;
}

@keyframes grid-drift {
  from { transform: translate(0, 0); }
  to   { transform: translate(60px, 60px); }
}

.bg-animation .particles {
  position: absolute;
  inset: 0;
}

.bg-animation .particle {
  position: absolute;
  width: 3px; height: 3px;
  background: var(--primary);
  border-radius: 50%;
  opacity: 0;
  animation: particle-rise linear infinite;
}

.bg-animation .particle:nth-child(1) { left: 10%; animation-duration: 8s; animation-delay: 0s; }
.bg-animation .particle:nth-child(2) { left: 25%; animation-duration: 10s; animation-delay: 2s; }
.bg-animation .particle:nth-child(3) { left: 40%; animation-duration: 7s; animation-delay: 4s; }
.bg-animation .particle:nth-child(4) { left: 55%; animation-duration: 9s; animation-delay: 1s; }
.bg-animation .particle:nth-child(5) { left: 70%; animation-duration: 11s; animation-delay: 3s; }
.bg-animation .particle:nth-child(6) { left: 85%; animation-duration: 8s; animation-delay: 5s; }
.bg-animation .particle:nth-child(7) { left: 15%; animation-duration: 12s; animation-delay: 6s; }
.bg-animation .particle:nth-child(8) { left: 60%; animation-duration: 9s; animation-delay: 7s; }

@keyframes particle-rise {
  0%   { bottom: -5%; opacity: 0; transform: translateX(0); }
  10%  { opacity: 0.6; }
  90%  { opacity: 0.6; }
  100% { bottom: 105%; opacity: 0; transform: translateX(30px); }
}

/* ── Auth Page ── */

.auth-wrapper {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: var(--space-6);
  background: transparent;
}

.auth-card {
  width: 100%;
  max-width: 420px;
}

.auth-card h1 {
  text-align: center;
  margin-bottom: var(--space-1);
  font-size: 1.75rem;
}

.auth-card .subtitle {
  text-align: center;
  color: var(--text-muted);
  margin-bottom: var(--space-6);
  font-size: 0.9rem;
}

/* ── Subdomain Page ── */

.subdomain-page {
  max-width: 900px;
  margin: var(--space-8) auto;
  padding: 0 var(--space-4);
}

.subdomain-page h1 {
  margin-bottom: var(--space-2);
}

.subdomain-page .role-badge {
  margin-bottom: var(--space-6);
}

.subdomain-field {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.subdomain-field input { flex: 1; }

.subdomain-suffix {
  font-size: 0.875rem;
  color: var(--text-muted);
  white-space: nowrap;
}

/* ── Entries Grid ── */

.entries-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--space-4);
}

.entry-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-md);
  padding: var(--space-5);
  transition: transform var(--tr-fast), box-shadow var(--tr-fast);
}

.entry-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-elevated);
}

.entry-card h3 {
  margin-bottom: var(--space-2);
  color: var(--text);
}

.entry-card p {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.entry-card time {
  display: block;
  margin-top: var(--space-3);
  font-size: 0.8rem;
  color: var(--text-dim);
}

.tag {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-right: var(--space-1);
}

/* ── Sleep Phase Bar ── */

.phase-bar {
  display: flex;
  height: 12px;
  border-radius: var(--radius-pill);
  overflow: hidden;
  margin-bottom: var(--space-3);
}

.phase-bar > div {
  height: 100%;
  transition: width var(--tr-slow);
}

.phase-legend {
  display: flex;
  gap: var(--space-4);
  font-size: 0.75rem;
  color: var(--text-muted);
}

.phase-legend i {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 4px;
  vertical-align: middle;
}

/* ── Bar Chart ── */

.bar-chart {
  display: flex;
  align-items: flex-end;
  gap: var(--space-6);
  height: 160px;
  padding-top: var(--space-4);
}

.bar-group {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  height: 100%;
  justify-content: flex-end;
}

.bar-group .bar {
  width: 100%;
  max-width: 48px;
  background: linear-gradient(180deg, var(--primary), var(--cyan));
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  transition: height var(--tr-slow);
}

.bar-label {
  font-size: 0.7rem;
  color: var(--text-dim);
}

/* ── Donut Chart ── */

.donut-container {
  width: 120px;
  height: 120px;
  margin: var(--space-4) auto;
}

.donut-legend {
  display: flex;
  justify-content: center;
  gap: var(--space-4);
  font-size: 0.8rem;
  color: var(--text-muted);
}

.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 4px;
  vertical-align: middle;
}

/* ── Week Calendar ── */

.week-calendar {
  display: flex;
  gap: var(--space-2);
  margin: var(--space-4) 0;
}

.day {
  flex: 1;
  text-align: center;
  padding: var(--space-2) 0;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-dim);
  background: var(--bg-elevated);
  border-radius: var(--radius-sm);
}

.day-active {
  background: var(--primary);
  color: #fff;
}

/* ── AI Suggestion Box ── */

.ai-suggestion {
  margin-top: var(--space-4);
  padding: var(--space-4);
  background: var(--bg-elevated);
  border-radius: var(--radius-md);
  border-left: 3px solid var(--primary);
}

.ai-suggestion p {
  margin-top: var(--space-2);
  font-size: 0.875rem;
  color: var(--text-muted);
}

/* ── Toast Notifications ── */

#toast-container {
  position: fixed;
  top: var(--space-4);
  right: var(--space-4);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.toast {
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius-sm);
  color: #fff;
  font-size: 0.875rem;
  font-weight: 500;
  box-shadow: var(--shadow-elevated);
  animation: toast-in 0.3s ease-out;
}

.toast-success { background: var(--success); }
.toast-error   { background: var(--danger); }

@keyframes toast-in {
  from { opacity: 0; transform: translateX(1rem); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ── Empty State ── */

.empty-state {
  text-align: center;
  color: var(--text-dim);
  padding: var(--space-8);
}

/* ── Demo Banner ── */

.demo-banner {
  background: rgba(59, 130, 246, 0.08);
  border: 1px solid rgba(59, 130, 246, 0.2);
  border-radius: var(--radius-md);
  padding: var(--space-4) var(--space-6);
  margin-bottom: var(--space-6);
  font-size: 0.9rem;
  color: var(--text-soft);
}

.demo-banner a {
  color: var(--primary);
  font-weight: 600;
}

/* ── Utility ── */

.hidden { display: none !important; }

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

.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-6 { margin-bottom: var(--space-6); }

/* ── Responsive ── */

@media (max-width: 600px) {
  .form-row { flex-direction: column; }
  .navbar { padding: var(--space-3) var(--space-4); }
  .navbar h1 { font-size: 1.1rem; }
}
