/* ========================================================
   EOLM Design System
   ======================================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

/* --- Custom Properties: Light Theme --- */
:root {
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --color-bg: #f1f5f9;
  --color-surface: #ffffff;
  --color-surface-hover: #f8fafc;
  --color-text: #0f172a;
  --color-text-secondary: #475569;
  --color-text-muted: #94a3b8;
  --color-border: #e2e8f0;
  --color-input-bg: #ffffff;
  --color-input-border: #cbd5e1;
  --color-topbar-bg: #0f172a;
  --color-topbar-text: #ffffff;
  --color-shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --color-shadow-lg: 0 4px 12px rgba(0,0,0,0.08);
  --color-primary: #2563eb;
  --color-primary-hover: #1d4ed8;
  --color-success: #16a34a;
  --color-success-bg: #f0fdf4;
  --color-success-text: #166534;
  --color-danger: #dc2626;
  --color-danger-bg: #fef2f2;
  --color-danger-text: #991b1b;
  --color-warning: #d97706;
  --color-warning-bg: #fffbeb;
  --color-warning-text: #92400e;
  --color-neutral-bg: #f1f5f9;
  --color-neutral-text: #475569;
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 10px;
  --radius-pill: 999px;
}

/* --- Custom Properties: Dark Theme --- */
[data-theme="dark"] {
  --color-bg: #0f172a;
  --color-surface: #1e293b;
  --color-surface-hover: #334155;
  --color-text: #f1f5f9;
  --color-text-secondary: #94a3b8;
  --color-text-muted: #64748b;
  --color-border: #334155;
  --color-input-bg: #1e293b;
  --color-input-border: #475569;
  --color-topbar-bg: #020617;
  --color-shadow: 0 1px 3px rgba(0,0,0,0.3), 0 1px 2px rgba(0,0,0,0.2);
  --color-shadow-lg: 0 4px 12px rgba(0,0,0,0.3);
  --color-success-bg: #052e16;
  --color-success-text: #4ade80;
  --color-danger-bg: #450a0a;
  --color-danger-text: #fca5a5;
  --color-warning-bg: #451a03;
  --color-warning-text: #fcd34d;
  --color-neutral-bg: #334155;
  --color-neutral-text: #94a3b8;
}

/* --- Base Reset --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }

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

img { display: block; max-width: 100%; }
a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* --- Typography --- */
h1 { font-size: 1.5rem; font-weight: 700; line-height: 1.3; margin-bottom: 8px; }
h2 { font-size: 1.125rem; font-weight: 600; line-height: 1.4; margin-bottom: 16px; color: var(--color-text); }
h3 { font-size: 1rem; font-weight: 600; line-height: 1.4; margin-bottom: 12px; }
p { margin-bottom: 6px; }

/* ========== TOPBAR ========== */
.topbar {
  background: var(--color-topbar-bg);
  height: 56px;
  position: relative;
  z-index: 100;
}

.topbar-inner {
  max-width: 1160px;
  margin: 0 auto;
  height: 100%;
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 16px;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  flex-shrink: 0;
}

.topbar-logo {
  width: 28px;
  height: 28px;
  object-fit: contain;
}

[data-theme="dark"] .topbar-logo,
[data-theme="dark"] .main-logo {
  /* Keeps the exact original colors but adds a subtle soft white glow so the dark blue shape doesn't vanish into the dark background */
  filter: drop-shadow(0 0 8px rgba(255, 255, 255, 0.45));
}
.topbar-brand-text {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--color-topbar-text);
  letter-spacing: -0.02em;
}

.topbar-menu {
  display: flex;
  align-items: center;
  flex: 1;
  gap: 8px;
}

.topbar-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: 16px;
}

.topbar-link {
  color: var(--color-topbar-text);
  text-decoration: none;
  font-weight: 500;
  font-size: 0.875rem;
  opacity: 0.7;
  padding: 6px 12px;
  border-radius: var(--radius-md);
  transition: opacity 0.15s ease, background-color 0.15s ease;
  white-space: nowrap;
}

.topbar-link:hover {
  opacity: 1;
  background: rgba(255,255,255,0.08);
  text-decoration: none;
}

.topbar-link.active {
  opacity: 1;
  background: rgba(255,255,255,0.12);
}

.topbar-user {
  font-size: 0.8125rem;
  color: var(--color-topbar-text);
  opacity: 0.55;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}

.topbar-logout {
  opacity: 0.6;
}

/* Logout form styled as inline element — button pretends to be a link */
.topbar-logout-form {
  display: inline;
  margin: 0;
  padding: 0;
}

button.topbar-logout {
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
}

/* --- Theme Toggle --- */
.theme-toggle {
  background: none;
  border: none;
  color: var(--color-topbar-text);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.6;
  transition: opacity 0.15s ease, background-color 0.15s ease;
}

.theme-toggle:hover {
  opacity: 1;
  background: rgba(255,255,255,0.08);
}

/* Light mode: show moon. Dark mode: show sun. */
.theme-icon-sun { display: none; }
.theme-icon-moon { display: block; }
[data-theme="dark"] .theme-icon-sun { display: block; }
[data-theme="dark"] .theme-icon-moon { display: none; }

/* --- Hamburger (mobile only) --- */
.topbar-hamburger {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  margin-left: auto;
}

.topbar-hamburger span {
  display: block;
  width: 20px;
  height: 2px;
  background: var(--color-topbar-text);
  border-radius: 2px;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.topbar-hamburger.active span:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}
.topbar-hamburger.active span:nth-child(2) {
  opacity: 0;
}
.topbar-hamburger.active span:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

/* ========== LAYOUT ========== */
.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 32px 20px;
}

/* ========== CARDS ========== */
.card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--color-shadow);
  margin-bottom: 24px;
}

.card-highlight {
  border-left: 4px solid var(--color-success);
}

.page-header h1 { margin-bottom: 12px; }

.meta p {
  color: var(--color-text-secondary);
  font-size: 0.9375rem;
  margin-bottom: 4px;
}

.meta strong { color: var(--color-text); }

/* ========== FORMS ========== */
.form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

label {
  font-weight: 500;
  font-size: 0.875rem;
  color: var(--color-text-secondary);
}

input, select, textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--color-input-border);
  border-radius: var(--radius-md);
  font-size: 0.9375rem;
  font-family: var(--font-sans);
  background: var(--color-input-bg);
  color: var(--color-text);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

input[readonly] {
  background: var(--color-bg);
  cursor: default;
}

textarea {
  resize: vertical;
  font-family: 'Courier New', Courier, monospace;
}

.form-text {
  font-size: 0.875rem;
  color: var(--color-text-muted);
  line-height: 1.5;
}

/* ========== BUTTONS ========== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 18px;
  border: none;
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: background-color 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
  line-height: 1.4;
}

.btn:hover { text-decoration: none; }
.btn:active { transform: scale(0.98); }

.btn-primary {
  background: var(--color-topbar-bg);
  color: #ffffff;
}
.btn-primary:hover {
  background: #1e293b;
}
[data-theme="dark"] .btn-primary {
  background: #334155;
}
[data-theme="dark"] .btn-primary:hover {
  background: #475569;
}

.btn-danger {
  background: var(--color-danger);
  color: #ffffff;
}
.btn-danger:hover {
  background: #b91c1c;
}

.btn-success {
  background: var(--color-success);
  color: #ffffff;
}
.btn-success:hover {
  background: #15803d;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.8125rem;
}

.btn-block {
  width: 100%;
}

/* Legacy button fallback (unstyled buttons in forms default to primary) */
button:not(.btn):not(.theme-toggle):not(.topbar-hamburger) {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 18px;
  border: none;
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  background: var(--color-topbar-bg);
  color: #ffffff;
  transition: background-color 0.15s ease;
}

/* ========== TABLES ========== */
.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-top: 4px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.data-table thead th {
  text-align: left;
  padding: 10px 16px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-muted);
  background: var(--color-bg);
  border-bottom: 2px solid var(--color-border);
  white-space: nowrap;
}

.data-table tbody td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
  color: var(--color-text);
}

.data-table tbody tr:hover {
  background: var(--color-surface-hover);
}

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

.data-table form { margin: 0; display: inline; }

/* ========== BADGES ========== */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: var(--radius-pill);
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
  line-height: 1.6;
}

.badge-success {
  background: var(--color-success-bg);
  color: var(--color-success-text);
}

.badge-danger {
  background: var(--color-danger-bg);
  color: var(--color-danger-text);
}

.badge-warning {
  background: var(--color-warning-bg);
  color: var(--color-warning-text);
}

.badge-neutral {
  background: var(--color-neutral-bg);
  color: var(--color-neutral-text);
}

/* ========== FLASH MESSAGES ========== */
.flash-container {
  margin-bottom: 20px;
}

.flash {
  padding: 12px 16px;
  border-radius: var(--radius-md);
  border-left: 4px solid var(--color-danger);
  background: var(--color-danger-bg);
  color: var(--color-danger-text);
  font-size: 0.9375rem;
  margin-bottom: 10px;
}

.flash-success {
  border-left-color: var(--color-success);
  background: var(--color-success-bg);
  color: var(--color-success-text);
}

/* ========== ALERTS (inline) ========== */
.alert {
  padding: 16px 20px;
  border-radius: var(--radius-md);
  border-left: 4px solid;
  margin-bottom: 20px;
  font-size: 0.9375rem;
  line-height: 1.5;
}

.alert-danger {
  border-color: var(--color-danger);
  background: var(--color-danger-bg);
  color: var(--color-danger-text);
  font-weight: 600;
}

/* ========== HERO (Index Page) ========== */
.hero {
  position: relative;
  min-height: calc(100vh - 56px);
}

/* Logo anchor: always centered, never moves */
.hero-logo-anchor {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* Flash area: positioned at a fixed pixel offset BELOW the logo center.
   Completely outside .hero-logo-anchor so it never shifts the logo. */
.hero-flash {
  position: absolute;
  top: calc(50% + 148px); /* ~logo half-height(100) + tagline(30) + gap(18) */
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 360px;
  text-align: center;
  pointer-events: none;
}

/* Auto-dismiss: stays visible for 2.5s then fades out over 1.5s */
.flash-autodismiss {
  animation: flash-fade 4s ease forwards;
  pointer-events: none;
}

@keyframes flash-fade {
  0%   { opacity: 1; }
  62%  { opacity: 1; }
  100% { opacity: 0; }
}

.hero-tagline {
  font-size: 1rem;
  color: var(--color-text-muted);
  font-weight: 400;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-top: 12px;
}


/* ========== AUTH PAGE (Login, Invite) ========== */
.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 56px);
  padding: 40px 20px;
}

.auth-card {
  width: 100%;
  max-width: 440px;
  text-align: center;
}

.auth-card .form {
  text-align: left;
}

.auth-subtitle {
  font-size: 0.875rem;
  color: var(--color-text-muted);
  margin-bottom: 24px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.auth-card .meta {
  text-align: left;
  margin-bottom: 16px;
}

/* ========== LOGO ========== */
.logo-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: min(42vw, 200px);
  height: min(42vw, 200px);
  margin: 0 auto;
}

.logo-wrapper.small {
  width: 100px;
  height: 100px;
  margin-bottom: 20px;
}

.main-logo {
  display: block;
  width: 100%;
  height: auto;
  user-select: none;
  -webkit-user-drag: none;
  position: relative;
  z-index: 5;
}

[data-theme="dark"] .main-logo {
  filter: invert(1) opacity(0.85);
}

/* Ripple pseudo-elements (only for animated) */
.logo-wrapper.animated::before,
.logo-wrapper.animated::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image: url("/logo.svg");
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  z-index: 1;
  opacity: 0;
  pointer-events: none;
}

/* Animation classes — index page only */
.logo-wrapper.animated .main-logo {
  animation: logo-breathe 8s infinite ease-in-out;
}

.logo-wrapper.animated::before {
  animation: logo-ripple 12s infinite ease-out;
}

.logo-wrapper.animated::after {
  animation: logo-ripple 12s infinite ease-out 6s;
}

[data-theme="dark"] .logo-wrapper.animated::before,
[data-theme="dark"] .logo-wrapper.animated::after {
  filter: invert(1) opacity(0.6);
}

@keyframes logo-breathe {
  0%, 100% {
    transform: translateY(0) scale(1);
    filter: drop-shadow(0 0 0 rgba(37, 99, 235, 0));
  }
  50% {
    transform: translateY(-6px) scale(1.03);
    filter: drop-shadow(0 0 24px rgba(37, 99, 235, 0.15));
  }
}

[data-theme="dark"] .logo-wrapper.animated .main-logo {
  animation: logo-breathe-dark 8s infinite ease-in-out;
}

@keyframes logo-breathe-dark {
  0%, 100% {
    transform: translateY(0) scale(1);
    filter: invert(1) opacity(0.85) drop-shadow(0 0 0 rgba(96, 165, 250, 0));
  }
  50% {
    transform: translateY(-6px) scale(1.03);
    filter: invert(1) opacity(0.85) drop-shadow(0 0 30px rgba(96, 165, 250, 0.3));
  }
}

@keyframes logo-ripple {
  0%, 5% { transform: scale(1); opacity: 0; }
  5.5% { transform: scale(1.02); opacity: 0.45; filter: blur(0); }
  40% { transform: scale(4.5); opacity: 0; filter: blur(50px); }
  100% { opacity: 0; }
}

/* ========== PEER CREATED PAGE ========== */
.qr-container {
  text-align: center;
  margin: 20px 0;
}

.qr-container img {
  max-width: 280px;
  height: auto;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 12px;
  background: #ffffff;
  margin: 0 auto;
}

.config-textarea {
  width: 100%;
  height: 200px;
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.8125rem;
  padding: 12px;
  border: 1px solid var(--color-input-border);
  border-radius: var(--radius-md);
  background: var(--color-bg);
  color: var(--color-text);
  resize: vertical;
}

/* ========== UTILITIES ========== */
.text-center { text-align: center; }
.mt-lg { margin-top: 24px; }
.mb-0 { margin-bottom: 0; }

/* ========== RESPONSIVE: Tablet ========== */
@media (max-width: 768px) {
  .topbar-menu {
    display: none;
    position: absolute;
    top: 56px;
    left: 0;
    right: 0;
    background: var(--color-topbar-bg);
    flex-direction: column;
    padding: 12px 20px 20px;
    border-top: 1px solid rgba(255,255,255,0.08);
    gap: 4px;
    box-shadow: 0 8px 16px rgba(0,0,0,0.2);
    z-index: 99;
  }

  .topbar-menu.open {
    display: flex;
  }

  .topbar-hamburger {
    display: flex;
  }

  .topbar-nav {
    flex-direction: column;
    margin-left: 0;
    width: 100%;
    gap: 2px;
  }

  .topbar-link {
    width: 100%;
    padding: 10px 12px;
  }

  .topbar-actions {
    flex-direction: column;
    align-items: flex-start;
    margin-left: 0;
    width: 100%;
    gap: 8px;
    padding-top: 8px;
    border-top: 1px solid rgba(255,255,255,0.08);
  }

  .topbar-user {
    max-width: 100%;
    padding: 4px 12px;
  }

  .container {
    padding: 20px 16px;
  }

  .card {
    padding: 20px 16px;
  }

  .data-table {
    font-size: 0.8125rem;
  }

  .data-table thead th {
    padding: 8px 12px;
  }

  .data-table tbody td {
    padding: 10px 12px;
  }

  h1 { font-size: 1.25rem; }
}

/* ========== RESPONSIVE: Small Phone ========== */
@media (max-width: 480px) {
  .logo-wrapper {
    width: min(55vw, 180px);
    height: min(55vw, 180px);
  }

  .hero-tagline {
    font-size: 0.875rem;
  }

  .btn { padding: 10px 14px; }
  .btn-sm { padding: 6px 10px; }

  .card { padding: 16px 14px; }
}

/* ========== REDUCED MOTION ========== */
@media (prefers-reduced-motion: reduce) {
  .logo-wrapper.animated .main-logo,
  .logo-wrapper.animated::before,
  .logo-wrapper.animated::after {
    animation: none !important;
  }

  *, *::before, *::after {
    transition-duration: 0.01ms !important;
  }
}
