/* ==========================================================================
   UNIVERSAL DESIGN SYSTEM - Darom News Platform
   ==========================================================================
   
   This file contains all universal styles, components, and utilities
   used across the entire Darom platform. It follows a Reddit-inspired
   design language with modern CSS practices.
   
   Architecture:
   - CSS Custom Properties (variables)
   - Component-based design
   - Utility classes
   - Responsive design
   - Accessibility-first approach
   ========================================================================== */

/* Mobile Optimization: Prevent iOS text selection/callout on buttons */
button,
.btn,
.vote-btn,
.post-action,
.action-btn,
.mobile-nav-item,
[role="button"] {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  /* Prevent iOS context menu */
  touch-action: manipulation;
  /* Improve touch response */
}

/* ==========================================================================
   CSS CUSTOM PROPERTIES (Design Tokens)
   ========================================================================== */

/* :root Variables moved to variables.css */

/* Dark Theme Variables */
/* Dark Theme Variables moved to variables.css */

/* ==========================================================================
   BASE STYLES
   ========================================================================== */

* {
  box-sizing: border-box;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: var(--font-size-base);
  line-height: 1.5;
  color: var(--text-primary);
  background-color: var(--bg-primary);
  margin: 0;
  padding: 0;
}

/* ==========================================================================
   TYPOGRAPHY SYSTEM
   ========================================================================== */

.text-xs {
  font-size: var(--font-size-xs);
}

.text-sm {
  font-size: var(--font-size-sm);
}

.text-base {
  font-size: var(--font-size-base);
}

.text-lg {
  font-size: var(--font-size-lg);
}

.text-xl {
  font-size: var(--font-size-xl);
}

.text-2xl {
  font-size: var(--font-size-2xl);
}

.text-3xl {
  font-size: var(--font-size-3xl);
}

.text-4xl {
  font-size: var(--font-size-4xl);
}

.font-normal {
  font-weight: 400;
}

.font-medium {
  font-weight: 500;
}

.font-semibold {
  font-weight: 600;
}

.font-bold {
  font-weight: 700;
}

.text-primary {
  color: var(--text-primary);
}

.text-secondary {
  color: var(--text-secondary);
}

.text-muted {
  color: var(--text-muted);
}

.text-inverse {
  color: var(--text-inverse);
}

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

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

.text-error {
  color: var(--color-error);
}

.text-info {
  color: var(--color-info);
}

.leading-tight {
  line-height: 1.25;
}

.leading-normal {
  line-height: 1.5;
}

.leading-relaxed {
  line-height: 1.75;
}

/* ==========================================================================
   SPACING SYSTEM
   ========================================================================== */

.m-0 {
  margin: 0;
}

.m-xs {
  margin: var(--space-xs);
}

.m-sm {
  margin: var(--space-sm);
}

.m-md {
  margin: var(--space-md);
}

.m-lg {
  margin: var(--space-lg);
}

.m-xl {
  margin: var(--space-xl);
}

.m-2xl {
  margin: var(--space-2xl);
}

.mt-0 {
  margin-top: 0;
}

.mt-xs {
  margin-top: var(--space-xs);
}

.mt-sm {
  margin-top: var(--space-sm);
}

.mt-md {
  margin-top: var(--space-md);
}

.mt-lg {
  margin-top: var(--space-lg);
}

.mt-xl {
  margin-top: var(--space-xl);
}

.mt-2xl {
  margin-top: var(--space-2xl);
}

.mb-0 {
  margin-bottom: 0;
}

.mb-xs {
  margin-bottom: var(--space-xs);
}

.mb-sm {
  margin-bottom: var(--space-sm);
}

.mb-md {
  margin-bottom: var(--space-md);
}

.mb-lg {
  margin-bottom: var(--space-lg);
}

.mb-xl {
  margin-bottom: var(--space-xl);
}

.mb-2xl {
  margin-bottom: var(--space-2xl);
}

.p-0 {
  padding: 0;
}

.p-xs {
  padding: var(--space-xs);
}

.p-sm {
  padding: var(--space-sm);
}

.p-md {
  padding: var(--space-md);
}

.p-lg {
  padding: var(--space-lg);
}

.p-xl {
  padding: var(--space-xl);
}

.p-2xl {
  padding: var(--space-2xl);
}

.pt-0 {
  padding-top: 0;
}

.pt-xs {
  padding-top: var(--space-xs);
}

.pt-sm {
  padding-top: var(--space-sm);
}

.pt-md {
  padding-top: var(--space-md);
}

.pt-lg {
  padding-top: var(--space-lg);
}

.pt-xl {
  padding-top: var(--space-xl);
}

.pt-2xl {
  padding-top: var(--space-2xl);
}

.pb-0 {
  padding-bottom: 0;
}

.pb-xs {
  padding-bottom: var(--space-xs);
}

.pb-sm {
  padding-bottom: var(--space-sm);
}

.pb-md {
  padding-bottom: var(--space-md);
}

.pb-lg {
  padding-bottom: var(--space-lg);
}

.pb-xl {
  padding-bottom: var(--space-xl);
}

.pb-2xl {
  padding-bottom: var(--space-2xl);
}

/* ==========================================================================
   LAYOUT SYSTEM
   ========================================================================== */

.container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 var(--space-md);
}

.container-sm {
  max-width: 640px;
}

.container-md {
  max-width: 767px;
}

.container-lg {
  max-width: 1024px;
}

.container-xl {
  max-width: 1280px;
}

.flex {
  display: flex;
}

.inline-flex {
  display: inline-flex;
}

.grid {
  display: grid;
}

.block {
  display: block;
}

.inline-block {
  display: inline-block;
}

.hidden {
  display: none !important;
}

.no-scroll {
  overflow: hidden !important;
}

.flex-col {
  flex-direction: column;
}

.flex-row {
  flex-direction: row;
}

.flex-wrap {
  flex-wrap: wrap;
}

.flex-nowrap {
  flex-wrap: nowrap;
}

.items-start {
  align-items: flex-start;
}

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

.items-end {
  align-items: flex-end;
}

.items-stretch {
  align-items: stretch;
}

.justify-start {
  justify-content: flex-start;
}

.justify-center {
  justify-content: center;
}

.justify-end {
  justify-content: flex-end;
}

.justify-between {
  justify-content: space-between;
}

.justify-around {
  justify-content: space-around;
}

.gap-xs {
  gap: var(--space-xs);
}

.gap-sm {
  gap: var(--space-sm);
}

.gap-md {
  gap: var(--space-md);
}

.gap-lg {
  gap: var(--space-lg);
}

.gap-xl {
  gap: var(--space-xl);
}

.w-full {
  width: 100%;
}

.h-full {
  height: 100%;
}

.min-h-screen {
  min-height: 100vh;
}

/* ==========================================================================
   COMPONENT SYSTEM
   ========================================================================== */

/* Card Component */
.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: box-shadow var(--transition-base);
}

.card:hover {
  box-shadow: var(--shadow-md);
}

.card-header {
  padding: var(--space-lg) var(--space-xl);
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-secondary);
}

.card-body {
  padding: var(--space-xl);
}

.card-footer {
  padding: var(--space-lg) var(--space-xl);
  border-top: 1px solid var(--border-color);
  background: var(--bg-secondary);
}

/* Button Component */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-lg);
  font-size: var(--font-size-sm);
  font-weight: 600;
  text-decoration: none;
  border: 1px solid transparent;
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: all var(--transition-base);
  font-family: inherit;
  line-height: 1;
  white-space: nowrap;
  user-select: none;
}

.btn:focus {
  outline: none;
  box-shadow: 0 0 0 2px var(--color-primary);
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  pointer-events: none;
}

/* Button Variants */
.btn--primary {
  background: var(--color-primary);
  color: var(--text-inverse);
  border-color: var(--color-primary);
}

.btn--primary:hover:not(:disabled) {
  background: var(--color-primary-hover);
  border-color: var(--color-primary-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

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

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

.btn--danger {
  background: var(--color-error);
  color: var(--text-inverse);
  border-color: var(--color-error);
}

.btn--danger:hover:not(:disabled) {
  background: #e53e3e;
  border-color: #e53e3e;
}

.btn--success {
  background: var(--color-success);
  color: var(--text-inverse);
  border-color: var(--color-success);
}

.btn--success:hover:not(:disabled) {
  background: #38a169;
  border-color: #38a169;
}

/* Button Sizes */
.btn--sm {
  padding: var(--space-xs) var(--space-md);
  font-size: var(--font-size-xs);
}

.btn--lg {
  padding: var(--space-md) var(--space-xl);
  font-size: var(--font-size-base);
}

.btn--xl {
  padding: var(--space-lg) var(--space-2xl);
  font-size: var(--font-size-lg);
}

/* Form Component */
.form-group {
  margin-bottom: var(--space-lg);
}

.form-label {
  display: block;
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: var(--space-sm);
  line-height: 1.4;
}

.form-label--required::after {
  content: ' *';
  color: var(--color-error);
}

.form-input,
.form-textarea,
.form-select {
  width: 100%;
  padding: var(--space-md);
  font-size: var(--font-size-sm);
  line-height: 1.4;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  color: var(--text-primary);
  transition: all var(--transition-base);
  font-family: inherit;
  box-sizing: border-box;
}

.form-input:focus,
.form-textarea:focus,
.form-select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px rgba(0, 121, 211, 0.2);
  background: var(--bg-secondary);
}

.form-input:hover,
.form-textarea:hover,
.form-select:hover {
  border-color: var(--border-hover);
}

.form-input::placeholder,
.form-textarea::placeholder {
  color: var(--text-muted);
}

.form-textarea {
  min-height: 120px;
  resize: vertical;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

.form-textarea--large {
  min-height: 300px;
}

.form-textarea--extra-large {
  min-height: 500px;
}

/* Form Validation States */
.form-input--error,
.form-textarea--error,
.form-select--error {
  border-color: var(--color-error);
  box-shadow: 0 0 0 2px rgba(255, 68, 68, 0.2);
}

.form-input--success,
.form-textarea--success,
.form-select--success {
  border-color: var(--color-success);
  box-shadow: 0 0 0 2px rgba(70, 209, 96, 0.2);
}

.form-error {
  font-size: var(--font-size-xs);
  color: var(--color-error);
  margin-top: var(--space-xs);
  display: flex;
  align-items: center;
  gap: var(--space-xs);
}

.form-error::before {
  content: '⚠';
  font-size: var(--font-size-sm);
}

.form-help {
  font-size: var(--font-size-xs);
  color: var(--text-secondary);
  margin-top: var(--space-xs);
  line-height: 1.3;
}

/* Form Actions */
.form-actions {
  display: flex;
  gap: var(--space-md);
  justify-content: flex-end;
  align-items: center;
  margin-top: var(--space-xl);
  padding-top: var(--space-lg);
  border-top: 1px solid var(--border-color);
}

.form-actions--center {
  justify-content: center;
}

.form-actions--space-between {
  justify-content: space-between;
}

/* ==========================================================================
   UTILITY CLASSES
   ========================================================================== */

/* Text Utilities */
.text-center {
  text-align: center;
}

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

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

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Border Utilities */
.border {
  border: 1px solid var(--border-color);
}

.border-t {
  border-top: 1px solid var(--border-color);
}

.border-b {
  border-bottom: 1px solid var(--border-color);
}

.border-l {
  border-left: 1px solid var(--border-color);
}

.border-r {
  border-right: 1px solid var(--border-color);
}

.rounded-sm {
  border-radius: var(--radius-sm);
}

.rounded-md {
  border-radius: var(--radius-md);
}

.rounded-lg {
  border-radius: var(--radius-lg);
}

.rounded-xl {
  border-radius: var(--radius-xl);
}

.rounded-2xl {
  border-radius: var(--radius-2xl);
}

/* Shadow Utilities */
.shadow-sm {
  box-shadow: var(--shadow-sm);
}

.shadow-md {
  box-shadow: var(--shadow-md);
}

.shadow-lg {
  box-shadow: var(--shadow-lg);
}

.shadow-xl {
  box-shadow: var(--shadow-xl);
}

/* Position Utilities */
.relative {
  position: relative;
}

.absolute {
  position: absolute;
}

.fixed {
  position: fixed;
}

.sticky {
  position: sticky;
}

.top-0 {
  top: 0;
}

.right-0 {
  right: 0;
}

.bottom-0 {
  bottom: 0;
}

.left-0 {
  left: 0;
}

/* Overflow Utilities */
.overflow-hidden {
  overflow: hidden;
}

.overflow-auto {
  overflow: auto;
}

.overflow-scroll {
  overflow: scroll;
}

/* Cursor Utilities */
.cursor-pointer {
  cursor: pointer;
}

.cursor-not-allowed {
  cursor: not-allowed;
}

/* Opacity Utilities */
.opacity-0 {
  opacity: 0;
}

.opacity-50 {
  opacity: 0.5;
}

.opacity-75 {
  opacity: 0.75;
}

.opacity-100 {
  opacity: 1;
}

/* Visibility Utilities */
.visible {
  visibility: visible;
}

.invisible {
  visibility: hidden;
}

/* ==========================================================================
   RESPONSIVE DESIGN
   ========================================================================== */

/* Mobile First Approach */
@media (min-width: 640px) {
  .sm\:hidden {
    display: none;
  }

  .sm\:block {
    display: block;
  }

  .sm\:flex {
    display: flex;
  }

  .sm\:grid {
    display: grid;
  }

  .sm\:text-sm {
    font-size: var(--font-size-sm);
  }

  .sm\:text-base {
    font-size: var(--font-size-base);
  }

  .sm\:text-lg {
    font-size: var(--font-size-lg);
  }

  .sm\:p-md {
    padding: var(--space-md);
  }

  .sm\:p-lg {
    padding: var(--space-lg);
  }

  .sm\:p-xl {
    padding: var(--space-xl);
  }
}

@media (min-width: 768px) {
  .md\:hidden {
    display: none;
  }

  .md\:block {
    display: block;
  }

  .md\:flex {
    display: flex;
  }

  .md\:grid {
    display: grid;
  }

  .md\:text-base {
    font-size: var(--font-size-base);
  }

  .md\:text-lg {
    font-size: var(--font-size-lg);
  }

  .md\:text-xl {
    font-size: var(--font-size-xl);
  }

  .md\:p-lg {
    padding: var(--space-lg);
  }

  .md\:p-xl {
    padding: var(--space-xl);
  }

  .md\:p-2xl {
    padding: var(--space-2xl);
  }
}

@media (min-width: 1024px) {
  .lg\:hidden {
    display: none;
  }

  .lg\:block {
    display: block;
  }

  .lg\:flex {
    display: flex;
  }

  .lg\:grid {
    display: grid;
  }

  .lg\:text-lg {
    font-size: var(--font-size-lg);
  }

  .lg\:text-xl {
    font-size: var(--font-size-xl);
  }

  .lg\:text-2xl {
    font-size: var(--font-size-2xl);
  }

  .lg\:p-xl {
    padding: var(--space-xl);
  }

  .lg\:p-2xl {
    padding: var(--space-2xl);
  }

  .lg\:p-3xl {
    padding: var(--space-3xl);
  }
}

@media (min-width: 1280px) {
  .xl\:hidden {
    display: none;
  }

  .xl\:block {
    display: block;
  }

  .xl\:flex {
    display: flex;
  }

  .xl\:grid {
    display: grid;
  }

  .xl\:text-xl {
    font-size: var(--font-size-xl);
  }

  .xl\:text-2xl {
    font-size: var(--font-size-2xl);
  }

  .xl\:text-3xl {
    font-size: var(--font-size-3xl);
  }
}

/* ==========================================================================
   ACCESSIBILITY
   ========================================================================== */

/* Focus Management */
.focus\:outline-none:focus {
  outline: none;
}

.focus\:ring:focus {
  box-shadow: 0 0 0 2px var(--color-primary);
}

/* Screen Reader Only */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* High Contrast Mode */
@media (prefers-contrast: high) {
  .btn {
    border-width: 2px;
  }

  .form-input,
  .form-textarea,
  .form-select {
    border-width: 2px;
  }
}

/* ==========================================================================
   ANIMATIONS
   ========================================================================== */

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

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slideIn {
  from {
    transform: translateX(-100%);
  }

  to {
    transform: translateX(0);
  }
}

@keyframes spin {
  from {
    transform: rotate(0deg);
  }

  to {
    transform: rotate(360deg);
  }
}

.animate-fade-in {
  animation: fadeIn 0.3s ease-out;
}

.animate-slide-in {
  animation: slideIn 0.3s ease-out;
}

.animate-spin {
  animation: spin 1s linear infinite;
}

/* ==========================================================================
   LOADING STATES
   ========================================================================== */

.loading {
  position: relative;
  pointer-events: none;
}

.loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 1rem;
  height: 1rem;
  margin: -0.5rem 0 0 -0.5rem;
  border: 2px solid transparent;
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

.btn--loading {
  position: relative;
  color: transparent;
}

.btn--loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 1rem;
  height: 1rem;
  margin: -0.5rem 0 0 -0.5rem;
  border: 2px solid transparent;
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

/* --- Toast Notifications --- */
#toast-container {
  position: fixed;
  top: 24px;
  right: 24px;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 12px;
  pointer-events: none;
}

.toast {
  position: relative;
  padding: 12px 16px;
  border-radius: 12px;
  background: var(--bg-elevated);
  color: var(--text-primary);
  box-shadow: var(--shadow-lg);
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  gap: 12px;
  opacity: 0;
  transform: translateX(40px) scale(0.9);
  transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  border: 1px solid var(--border-color);
  min-width: 320px;
  max-width: 450px;
  pointer-events: auto;
  overflow: hidden;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.toast::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 6px;
  background: var(--color-primary);
}

.toast--show {
  opacity: 1;
  transform: translateX(0) scale(1);
}

.toast--hide {
  opacity: 0;
  transform: translateX(40px) scale(0.8);
}

.toast__icon {
  font-size: 1.25rem;
  flex-shrink: 0;
}

.toast__content {
  flex-grow: 1;
}

.toast__message {
  font-weight: 500;
  line-height: 1.4;
}

.toast__close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  font-size: 0.8rem;
  opacity: 0.6;
  transition: opacity 0.2s;
}

.toast__close:hover {
  opacity: 1;
}

.toast--success::before {
  background: var(--color-success);
}

.toast--success .toast__icon {
  color: var(--color-success);
}

.toast--error::before {
  background: var(--color-error);
}

.toast--error .toast__icon {
  color: var(--color-error);
}

.toast--warning::before {
  background: var(--color-warning);
}

.toast--warning .toast__icon {
  color: var(--color-warning);
}

.toast--info::before {
  background: var(--color-primary);
}

.toast--info .toast__icon {
  color: var(--color-primary);
}

@media (max-width: 640px) {
  #toast-container {
    top: auto;
    bottom: 24px;
    right: 12px;
    left: 12px;
    align-items: center;
  }

  .toast {
    min-width: 0;
    width: 100%;
  }
}