/* ============================================
   LoverStation - Accessible CSS
   ============================================ */

/* ===== CSS Variables ===== */
:root {
  --primary-color: #2563eb;
  --secondary-color: #7c3aed;
  --success-color: #10b981;
  --error-color: #ef4444;
  --bg-color: #ffffff;
  --text-color: #1f2937;
  --border-color: #d1d5db;
  --focus-color: #3b82f6;
  --focus-width: 3px;

  /* Spacing */
  --spacing-xs: 0.25rem;
  --spacing-sm: 0.5rem;
  --spacing-md: 1rem;
  --spacing-lg: 1.5rem;
  --spacing-xl: 2rem;

  /* Typography */
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans Thai', sans-serif;
  --font-size-base: 16px;
  --line-height: 1.6;

  /* Touch targets */
  --min-touch-size: 44px;
}

/* ===== Reset & Base ===== */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: var(--font-size-base);
}

body {
  font-family: var(--font-sans);
  line-height: var(--line-height);
  color: var(--text-color);
  background-color: var(--bg-color);
}

/* ===== Accessibility Utilities ===== */
.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: var(--primary-color);
  color: white;
  padding: var(--spacing-sm) var(--spacing-md);
  text-decoration: none;
  z-index: 10000;
  font-weight: bold;
}

.skip-link:focus {
  top: 0;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ===== Focus Styles (WCAG 2.4.7) ===== */
a:focus,
button:focus,
input:focus,
select:focus,
textarea:focus {
  outline: var(--focus-width) solid var(--focus-color);
  outline-offset: 2px;
}

/* ===== Layout ===== */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 var(--spacing-md);
}

/* ===== Header ===== */
header {
  background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
  color: white;
  padding: var(--spacing-lg) 0;
  margin-bottom: var(--spacing-xl);
}

header h1 {
  font-size: 2rem;
  margin-bottom: var(--spacing-sm);
}

header .tagline {
  font-size: 1.1rem;
  margin-bottom: var(--spacing-md);
  opacity: 0.95;
}

/* ===== Navigation ===== */
nav ul {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: var(--spacing-md);
}

nav li {
  margin: 0;
}

nav a,
nav button {
  color: white;
  text-decoration: none;
  padding: var(--spacing-sm) var(--spacing-md);
  border-radius: 4px;
  display: inline-block;
  min-height: var(--min-touch-size);
  min-width: var(--min-touch-size);
  line-height: calc(var(--min-touch-size) - 1rem);
  background: rgba(255, 255, 255, 0.1);
  border: 2px solid transparent;
  cursor: pointer;
  font-size: 1rem;
  transition: background 0.2s;
}

nav a:hover,
nav button:hover {
  background: rgba(255, 255, 255, 0.2);
}

nav a:focus,
nav button:focus {
  outline: 2px solid white;
  outline-offset: 2px;
}

/* ===== Buttons ===== */
button,
.btn-primary,
.btn-secondary {
  min-height: var(--min-touch-size);
  min-width: var(--min-touch-size);
  padding: var(--spacing-sm) var(--spacing-md);
  font-size: 1rem;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.2s;
}

.btn-primary,
button[type="submit"] {
  background: var(--primary-color);
  color: white;
}

.btn-primary:hover,
button[type="submit"]:hover {
  background: #1d4ed8;
}

.btn-secondary {
  background: var(--secondary-color);
  color: white;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ===== Forms ===== */
.form-group {
  margin-bottom: var(--spacing-md);
}

label {
  display: block;
  margin-bottom: var(--spacing-xs);
  font-weight: 600;
  color: var(--text-color);
}

input[type="text"],
input[type="password"],
input[type="email"],
input[type="number"],
textarea,
select {
  width: 100%;
  min-height: var(--min-touch-size);
  padding: var(--spacing-sm) var(--spacing-md);
  font-size: 1rem;
  border: 2px solid var(--border-color);
  border-radius: 4px;
  font-family: inherit;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--focus-color);
}

.help-text,
small {
  display: block;
  margin-top: var(--spacing-xs);
  font-size: 0.9rem;
  color: #6b7280;
}

fieldset {
  border: 2px solid var(--border-color);
  padding: var(--spacing-md);
  margin-bottom: var(--spacing-md);
  border-radius: 4px;
}

legend {
  padding: 0 var(--spacing-sm);
  font-weight: bold;
}

.radio-group {
  margin-bottom: var(--spacing-md);
}

.radio-group input[type="radio"] {
  width: auto;
  min-height: 0;
  margin-right: var(--spacing-sm);
}

.radio-group label {
  display: inline;
  font-weight: normal;
  margin-left: var(--spacing-xs);
}

/* ===== Error Messages ===== */
.error-message {
  background: #fee2e2;
  border-left: 4px solid var(--error-color);
  color: #991b1b;
  padding: var(--spacing-md);
  margin-bottom: var(--spacing-md);
  border-radius: 4px;
}

/* ===== Sections ===== */
section {
  margin-bottom: var(--spacing-xl);
  padding: var(--spacing-lg);
  background: #f9fafb;
  border-radius: 8px;
}

section h2 {
  font-size: 1.5rem;
  margin-bottom: var(--spacing-md);
  color: var(--primary-color);
}

/* ===== Radio Player ===== */
.radio-player {
  background: white;
  padding: var(--spacing-md);
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.radio-player audio {
  width: 100%;
  min-height: var(--min-touch-size);
}

.radio-description {
  margin-top: var(--spacing-sm);
  text-align: center;
}

/* ===== Articles ===== */
.article-item {
  background: white;
  padding: var(--spacing-md);
  margin-bottom: var(--spacing-md);
  border-radius: 8px;
  border-left: 4px solid var(--primary-color);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.article-item h3 {
  margin-bottom: var(--spacing-sm);
}

.article-meta {
  color: #6b7280;
  font-size: 0.9rem;
  margin-bottom: var(--spacing-sm);
}

.article-category {
  color: var(--secondary-color);
  text-decoration: none;
  font-weight: 600;
}

.article-category:hover {
  text-decoration: underline;
}

/* ===== Article Overlay ===== */
.article-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  z-index: 1000;
  overflow-y: auto;
  padding: var(--spacing-xl);
}

.article-content {
  max-width: 800px;
  margin: 0 auto;
  background: white;
  padding: var(--spacing-xl);
  border-radius: 8px;
}

.article-controls {
  margin-top: var(--spacing-lg);
  display: flex;
  gap: var(--spacing-md);
  flex-wrap: wrap;
}

.article-controls button {
  flex: 1;
  min-width: 120px;
}

/* ===== Chat ===== */
#chatContainer {
  max-height: 400px;
  overflow-y: auto;
  background: white;
  border: 2px solid var(--border-color);
  border-radius: 8px;
  padding: var(--spacing-md);
  margin-bottom: var(--spacing-md);
}

.chat-message {
  margin-bottom: var(--spacing-md);
  padding-bottom: var(--spacing-sm);
  border-bottom: 1px solid #e5e7eb;
}

.chat-message:last-child {
  border-bottom: none;
}

.chat-message-header {
  font-weight: 600;
  margin-bottom: var(--spacing-xs);
  color: var(--secondary-color);
}

.chat-message-time {
  font-size: 0.8rem;
  color: #9ca3af;
  margin-left: var(--spacing-sm);
}

.chat-message-body {
  color: var(--text-color);
  word-wrap: break-word;
}

.chat-input-area {
  background: white;
  padding: var(--spacing-md);
  border-radius: 8px;
}

#chatForm {
  display: flex;
  gap: var(--spacing-sm);
  margin-bottom: var(--spacing-md);
}

#chatMessage {
  flex: 1;
}

.voice-controls {
  display: flex;
  gap: var(--spacing-sm);
  flex-wrap: wrap;
  align-items: center;
}

#recordingStatus {
  color: var(--error-color);
  font-weight: 600;
  margin-left: var(--spacing-sm);
}

.delete-btn {
  background: var(--error-color);
  color: white;
  border: none;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.8rem;
  cursor: pointer;
  margin-left: var(--spacing-md);
  min-height: 0;
  min-width: 0;
}

.delete-btn:hover {
  background: #dc2626;
}

/* ===== Tab System (Reusable) ===== */
.admin-tabs {
  display: flex;
  gap: var(--spacing-xs);
  background: #f3f4f6;
  padding: var(--spacing-sm);
  border-radius: 8px;
  margin-bottom: var(--spacing-lg);
  overflow-x: auto;
}

.tab-btn {
  flex: 1;
  min-width: 100px;
  background: white;
  border: 2px solid transparent;
  padding: var(--spacing-md);
  cursor: pointer;
  border-radius: 4px;
  transition: all 0.2s;
  font-weight: 600;
}

.tab-btn.active {
  background: var(--primary-color);
  color: white;
  border-color: var(--primary-color);
}

.tab-btn:hover:not(.active) {
  background: #e5e7eb;
}

.tab-pane {
  display: none;
}

.tab-pane.active {
  display: block;
}

/* ===== Auth Pages ===== */
.auth-container {
  max-width: 600px;
  margin: var(--spacing-xl) auto;
  background: white;
  padding: var(--spacing-xl);
  border-radius: 8px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.auth-container h2 {
  color: var(--primary-color);
  margin-bottom: var(--spacing-lg);
}

.login-method {
  margin-bottom: var(--spacing-lg);
  padding: var(--spacing-md);
  background: #f9fafb;
  border-radius: 8px;
}

.login-method h3 {
  color: var(--secondary-color);
  margin-bottom: var(--spacing-md);
}

.separator {
  text-align: center;
  margin: var(--spacing-lg) 0;
  position: relative;
}

.separator::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  height: 1px;
  background: var(--border-color);
}

.separator span {
  background: white;
  padding: 0 var(--spacing-md);
  position: relative;
  color: #6b7280;
}

.auth-link {
  text-align: center;
  margin-top: var(--spacing-lg);
}

/* ===== Footer ===== */
footer {
  background: #1f2937;
  color: white;
  padding: var(--spacing-lg) 0;
  margin-top: var(--spacing-xl);
  text-align: center;
}

/* ===== Responsive Design ===== */
@media (max-width: 768px) {
  nav ul {
    flex-direction: column;
  }

  .article-controls {
    flex-direction: column;
  }

  .article-controls button {
    width: 100%;
  }

  #chatForm {
    flex-direction: column;
  }
}

/* ===== High Contrast Mode Support ===== */
@media (prefers-contrast: high) {
  :root {
    --primary-color: #0000ff;
    --text-color: #000000;
    --bg-color: #ffffff;
    --border-color: #000000;
  }

  * {
    border-width: 2px !important;
  }
}

/* ===== Reduced Motion ===== */
@media (prefers-reduced-motion: reduce) {

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ===== Dark Mode (Optional) ===== */
@media (prefers-color-scheme: dark) {
  :root {
    --bg-color: #1f2937;
    --text-color: #f3f4f6;
    --border-color: #4b5563;
  }

  section {
    background: #374151;
  }

  .article-item,
  .radio-player,
  #chatContainer,
  .chat-input-area {
    background: #374151;
    color: var(--text-color);
  }

  .auth-container {
    background: #374151;
  }

  input,
  textarea,
  select {
    background: #1f2937;
    color: var(--text-color);
    border-color: var(--border-color);
  }
}

/* ===== Connection Status ===== */
.connection-status {
  padding: var(--spacing-sm);
  margin-bottom: var(--spacing-md);
  text-align: center;
  border-radius: 4px;
  font-weight: 600;
  font-size: 0.9rem;
}

.status-online {
  background: #dcfce7;
  color: #166534;
}

.status-offline {
  background: #fee2e2;
  color: #991b1b;
}

.status-warning {
  background: #fef9c3;
  color: #854d0e;
}

/* ===== Embedded Content (Polls/Forms) ===== */
.embedded-media {
  margin: var(--spacing-md) 0;
  background: #f3f4f6;
  padding: var(--spacing-sm);
  border-radius: 8px;
}

.poll-embed-card,
.form-embed-card {
  background: white;
  border: 1px solid var(--border-color);
  border-left: 4px solid var(--primary-color);
  border-radius: 8px;
  padding: var(--spacing-lg);
  margin: var(--spacing-lg) 0;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

/* Dark mode support for embed cards */
@media (prefers-color-scheme: dark) {

  .poll-embed-card,
  .form-embed-card {
    background: #374151;
    border-color: var(--secondary-color);
  }

  .btn-vote {
    background: #1f2937 !important;
    color: white;
    border-color: #4b5563;
  }
}

.poll-option-vote {
  margin-bottom: var(--spacing-md);
}

.btn-vote {
  width: 100%;
  text-align: left;
  background: #f9fafb;
  border: 1px solid var(--border-color);
  padding: var(--spacing-md);
  margin-bottom: var(--spacing-xs);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: all 0.2s;
  border-radius: 6px;
  font-weight: 500;
}

.btn-vote:hover {
  background: #e5e7eb;
  border-color: var(--primary-color);
}

.poll-option-vote.voted .btn-vote {
  background: #eff6ff;
  border-color: var(--primary-color);
  color: var(--primary-color);
}

.btn-vote:disabled {
  opacity: 0.8;
  cursor: default;
}

.poll-bar-bg {
  height: 6px;
  background: #f3f4f6;
  border-radius: 3px;
  overflow: hidden;
  margin-top: 4px;
}

.poll-bar-fill {
  height: 100%;
  background: var(--primary-color);
  border-radius: 3px;
  transition: width 0.5s ease;
}

.poll-percent {
  font-weight: bold;
  font-size: 0.9em;
}

.poll-total {
  font-size: 0.85rem;
  color: #6b7280;
  margin-top: var(--spacing-md);
  text-align: right;
}

.form-fields {
  margin: var(--spacing-md) 0;
}

.success-msg {
  color: var(--success-color);
  font-weight: bold;
  text-align: center;
  padding: var(--spacing-md);
  background: #ecfdf5;
  border-radius: 4px;
}

/* ===== Notifications (Toasts) ===== */
#notification-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.toast {
  min-width: 280px;
  max-width: 400px;
  background: white;
  color: #1f2937;
  padding: 1rem;
  border-radius: 8px;
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  display: flex;
  align-items: center;
  gap: 1rem;
  pointer-events: auto;
  animation: toast-in 0.3s ease forwards;
  border-left: 6px solid #2563eb;
  position: relative;
  overflow: hidden;
}

.toast.toast-out {
  animation: toast-out 0.3s ease forwards;
}

.toast-info {
  border-left-color: #2563eb;
}

.toast-success {
  border-left-color: #10b981;
}

.toast-warning {
  border-left-color: #ef4444;
}

.toast-content {
  flex: 1;
}

.toast-title {
  font-weight: 700;
  font-size: 0.95rem;
  margin-bottom: 2px;
  display: block;
}

.toast-message {
  font-size: 0.85rem;
  opacity: 0.9;
  display: block;
}

@keyframes toast-in {
  from {
    transform: translateX(120%);
    opacity: 0;
  }

  to {
    transform: translateX(0);
    opacity: 1;
  }
}

@keyframes toast-out {
  from {
    transform: translateX(0);
    opacity: 1;
  }

  to {
    transform: translateX(120%);
    opacity: 0;
  }
}

/* Dark mode support for toasts */
@media (prefers-color-scheme: dark) {
  .toast {
    background: #1f2937;
    color: white;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
  }
}

/* ===== WebRTC Call UI ===== */
.call-controls {
  margin-top: var(--spacing-md);
  display: flex;
  justify-content: center;
}

.btn-call {
  background: #dc2626;
  color: white;
  border-radius: 50px;
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
  box-shadow: 0 4px 6px rgba(220, 38, 38, 0.3);
  transition: all 0.3s ease;
  border: 2px solid transparent;
}

.btn-call:hover {
  background: #b91c1c;
  transform: translateY(-2px);
  box-shadow: 0 6px 12px rgba(220, 38, 38, 0.4);
}

.btn-call.pulse {
  animation: call-pulse 2s infinite;
}

@keyframes call-pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.7);
  }

  70% {
    box-shadow: 0 0 0 15px rgba(220, 38, 38, 0);
  }

  100% {
    box-shadow: 0 0 0 0 rgba(220, 38, 38, 0);
  }
}

/* Call Modal Overlay */
.call-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.85);
  -webkit-backdrop-filter: blur(5px);
  backdrop-filter: blur(5px);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.call-modal {
  background: #ffffff;
  width: 90%;
  max-width: 400px;
  padding: var(--spacing-xl);
  border-radius: 20px;
  text-align: center;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.2);
  border: 2px solid var(--primary-color);
}

.call-avatar {
  width: 100px;
  height: 100px;
  background: var(--primary-color);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3rem;
  margin: 0 auto var(--spacing-lg);
  position: relative;
}

.call-avatar.ringing::after {
  content: '';
  position: absolute;
  top: -10px;
  left: -10px;
  right: -10px;
  bottom: -10px;
  border: 4px solid var(--primary-color);
  border-radius: 50%;
  animation: ring-pulse 1.5s infinite;
}

@keyframes ring-pulse {
  0% {
    transform: scale(1);
    opacity: 1;
  }

  100% {
    transform: scale(1.3);
    opacity: 0;
  }
}

.call-title {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  color: #1f2937;
}

.call-status {
  color: #6b7280;
  margin-bottom: var(--spacing-xl);
}

.call-actions {
  display: flex;
  gap: var(--spacing-md);
  justify-content: center;
}

.btn-accept {
  background: var(--success-color);
  color: white;
  padding: 0.75rem 2rem;
  border-radius: 12px;
  font-weight: 700;
  border: none;
  cursor: pointer;
}

.btn-reject,
.btn-hangup {
  background: var(--error-color);
  color: white;
  padding: 0.75rem 2rem;
  border-radius: 12px;
  font-weight: 700;
  border: none;
  cursor: pointer;
}

.call-timer {
  font-family: monospace;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--primary-color);
  margin-bottom: var(--spacing-md);
}

/* Dark mode for calls */
@media (prefers-color-scheme: dark) {
  .call-modal {
    background: #374151;
    border-color: var(--secondary-color);
  }

  .call-title {
    color: white;
  }

  .call-status {
    color: #e5e7eb;
  }
}