/**
 * App Hub UI Framework
 * Standardized styles for all App Hub applications
 */

:root {
  --bg-primary: #0d1117;
  --bg-secondary: #161b22;
  --bg-tertiary: #21262d;
  --text-primary: #c9d1d9;
  --text-secondary: #8b949e;
  --text-muted: #6e7681;
  --accent-primary: #58a6ff;
  --accent-success: #238636;
  --accent-danger: #f85149;
  --accent-warning: #d29922;
  --border-color: #30363d;
  --code-bg: #21262d;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.3);
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
  color: var(--accent-primary);
  margin-bottom: 0.5em;
  line-height: 1.2;
}

h1 { font-size: 2rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.25rem; }
h4 { font-size: 1.1rem; }

p { margin-bottom: 1em; }
a { color: var(--accent-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Header */
header {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  padding: 20px 0;
  margin-bottom: 30px;
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

nav a {
  color: var(--text-primary);
  text-decoration: none;
  margin-left: 20px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  transition: background 0.2s;
}

nav a:hover {
  background: var(--bg-tertiary);
  text-decoration: none;
}

/* Cards */
.card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 20px;
  margin-bottom: 20px;
  transition: border-color 0.2s;
}

.card:hover {
  border-color: var(--accent-primary);
}

.card-title {
  color: var(--accent-primary);
  font-size: 1.3rem;
  margin-bottom: 10px;
}

.card-description {
  color: var(--text-secondary);
  margin-bottom: 15px;
}

/* Stats Grid */
.stats {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 20px;
  margin-bottom: 30px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 20px;
}

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

.stat-value {
  font-size: 2.5rem;
  font-weight: bold;
  color: var(--accent-primary);
}

.stat-label {
  color: var(--text-secondary);
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 1px;
}

/* Buttons */
.btn {
  display: inline-block;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  font-weight: 600;
  transition: all 0.2s;
  border: none;
  cursor: pointer;
  font-size: 0.95rem;
}

.btn-primary {
  background: var(--accent-success);
  color: white;
}

.btn-primary:hover {
  background: #2ea043;
  transform: translateY(-1px);
}

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

.btn-secondary:hover {
  background: var(--border-color);
  text-decoration: none;
}

.btn-danger {
  background: var(--accent-danger);
  color: white;
}

.btn-danger:hover {
  background: #da3633;
}

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

.btn-lg {
  padding: 14px 28px;
  font-size: 1.1rem;
}

/* Forms */
.form-group {
  margin-bottom: 20px;
}

label {
  display: block;
  margin-bottom: 8px;
  color: var(--text-secondary);
  font-weight: 500;
}

input, textarea, select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 1rem;
  transition: border-color 0.2s;
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent-primary);
}

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

/* Badges */
.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
  margin-right: 5px;
  margin-bottom: 5px;
}

.badge-primary { background: var(--accent-primary); color: white; }
.badge-success { background: var(--accent-success); color: white; }
.badge-danger { background: var(--accent-danger); color: white; }
.badge-warning { background: var(--accent-warning); color: black; }
.badge-secondary { background: var(--text-muted); color: white; }

/* Tables */
.table-container {
  overflow-x: auto;
  margin: 20px 0;
}

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

thead {
  background: var(--bg-tertiary);
}

th, td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border-color);
}

th {
  font-weight: 600;
  color: var(--text-secondary);
}

tbody tr:hover {
  background: var(--bg-tertiary);
}

/* Code blocks */
code {
  background: var(--code-bg);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
  font-size: 0.9em;
}

pre {
  background: var(--code-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 15px;
  overflow-x: auto;
  margin: 15px 0;
}

pre code {
  background: none;
  padding: 0;
}

/* Alerts */
.alert {
  padding: 15px 20px;
  border-radius: var(--radius-sm);
  margin-bottom: 20px;
}

.alert-success {
  background: rgba(35, 134, 54, 0.2);
  border: 1px solid var(--accent-success);
  color: #3fb950;
}

.alert-danger {
  background: rgba(248, 81, 73, 0.2);
  border: 1px solid var(--accent-danger);
  color: #f85149;
}

.alert-warning {
  background: rgba(210, 153, 34, 0.2);
  border: 1px solid var(--accent-warning);
  color: #d29922;
}

.alert-info {
  background: rgba(88, 166, 255, 0.2);
  border: 1px solid var(--accent-primary);
  color: var(--accent-primary);
}

/* ========================================
   Loading Indicators 🐕
   ======================================== */

/* Loading spinner (original) */
.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--bg-tertiary);
  border-top: 4px solid var(--accent-primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 20px auto;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Inline spinner (for buttons and small areas) */
.spinner-inline {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top: 2px solid white;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: middle;
  margin-right: 6px;
}

/* Skeleton loading placeholders */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--bg-tertiary) 25%,
    var(--bg-secondary) 50%,
    var(--bg-tertiary) 75%
  );
  background-size: 200% 100%;
  animation: skeleton-pulse 1.5s ease-in-out infinite;
  border-radius: var(--radius-sm);
}

@keyframes skeleton-pulse {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.skeleton-text {
  height: 1em;
  margin-bottom: 8px;
  width: 100%;
}

.skeleton-text.short { width: 60%; }
.skeleton-text.medium { width: 80%; }

.skeleton-title {
  height: 1.5em;
  margin-bottom: 12px;
  width: 40%;
}

.skeleton-card {
  height: 120px;
  margin-bottom: 16px;
}

.skeleton-circle {
  width: 40px;
  height: 40px;
  border-radius: 50%;
}

.skeleton-button {
  height: 38px;
  width: 100px;
  display: inline-block;
}

/* Button loading states */
.btn[disabled],
.btn:disabled {
  opacity: 0.65;
  cursor: not-allowed;
  pointer-events: none;
}

.btn.loading {
  position: relative;
  color: transparent !important;
  pointer-events: none;
}

.btn.loading::after {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  top: 50%;
  left: 50%;
  margin: -8px 0 0 -8px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top: 2px solid white;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* Loading overlay for content areas */
.loading-overlay {
  position: relative;
}

.loading-overlay::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(13, 17, 23, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  border-radius: inherit;
}

/* Loading container (centered spinner in a div) */
.loading-container {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  flex-direction: column;
  gap: 12px;
}

.loading-container .loading-text {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

/* Dots loading animation */
.loading-dots {
  display: inline-flex;
  gap: 4px;
}

.loading-dots span {
  width: 8px;
  height: 8px;
  background: var(--accent-primary);
  border-radius: 50%;
  animation: dot-bounce 1.4s ease-in-out infinite both;
}

.loading-dots span:nth-child(1) { animation-delay: -0.32s; }
.loading-dots span:nth-child(2) { animation-delay: -0.16s; }
.loading-dots span:nth-child(3) { animation-delay: 0s; }

@keyframes dot-bounce {
  0%, 80%, 100% { transform: scale(0.4); opacity: 0.5; }
  40% { transform: scale(1); opacity: 1; }
}

/* Page-level loading */
.page-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
}

/* Fade transitions for content that loads */
.fade-in {
  animation: fadeIn 0.3s ease-in;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Prevent layout shift during loading */
.min-height-placeholder {
  min-height: 100px;
}

/* Grid system */
.grid {
  display: grid;
  gap: 20px;
}

.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

@media (max-width: 768px) {
  .grid-2, .grid-3, .grid-4 {
    grid-template-columns: 1fr;
  }

  .stats {
    grid-template-columns: 1fr;
  }
}

/* Flex utilities */
.flex {
  display: flex;
}

.flex-between {
  justify-content: space-between;
  align-items: center;
}

.flex-center {
  justify-content: center;
  align-items: center;
}

.flex-gap {
  gap: 10px;
}

/* Spacing */
.mt-1 { margin-top: 10px; }
.mt-2 { margin-top: 20px; }
.mt-3 { margin-top: 30px; }
.mb-1 { margin-bottom: 10px; }
.mb-2 { margin-bottom: 20px; }
.mb-3 { margin-bottom: 30px; }

/* Text utilities */
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.text-success { color: var(--accent-success); }
.text-danger { color: var(--accent-danger); }
.text-warning { color: var(--accent-warning); }

/* Section titles */
.section-title {
  color: var(--accent-primary);
  font-size: 1.5rem;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 10px;
}

/* Footer */
footer {
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
  padding: 20px 0;
  margin-top: 50px;
  text-align: center;
  color: var(--text-secondary);
}

/* Utilities */
.hidden { display: none !important; }
.visible { display: block !important; }


/* ========================================
   Responsive Design System 📱
   ======================================== */

/* Mobile-first responsive breakpoints */
/* sm: 480px, md: 768px, lg: 1024px, xl: 1200px */

/* Base responsive utilities */
img, video, canvas, svg {
  max-width: 100%;
  height: auto;
}

/* Prevent horizontal scroll */
html, body {
  overflow-x: hidden;
}

/* Responsive container widths */
.container-sm { max-width: 640px; margin: 0 auto; padding: 0 16px; }
.container-md { max-width: 768px; margin: 0 auto; padding: 0 16px; }
.container-lg { max-width: 1024px; margin: 0 auto; padding: 0 16px; }

/* Responsive typography */
@media (max-width: 768px) {
  h1 { font-size: 1.6rem; }
  h2 { font-size: 1.3rem; }
  h3 { font-size: 1.15rem; }
  h4 { font-size: 1rem; }

  .container {
    padding: 12px;
  }

  /* Stack nav vertically */
  .header-content {
    flex-direction: column;
    gap: 12px;
  }

  nav a {
    margin-left: 0;
    margin-right: 10px;
  }

  /* Cards full width on mobile */
  .card {
    padding: 16px;
  }

  /* Tables scroll horizontally */
  .table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Buttons full width on mobile */
  .btn-block-mobile {
    width: 100%;
    display: block;
    text-align: center;
  }

  /* Stack form elements */
  .form-row {
    flex-direction: column;
  }

  /* Touch-friendly tap targets */
  button, .btn, a, input, select, textarea {
    min-height: 44px;
    min-width: 44px;
  }

  /* Hide non-essential elements on mobile */
  .hide-mobile {
    display: none !important;
  }
}

@media (max-width: 480px) {
  h1 { font-size: 1.4rem; }
  h2 { font-size: 1.2rem; }
  .container { padding: 10px; }
  .card { padding: 12px; }

  .btn {
    padding: 12px 16px;
    font-size: 1rem;
  }
}

/* Desktop-only elements */
@media (max-width: 768px) {
  .hide-mobile { display: none !important; }
}

@media (min-width: 769px) {
  .hide-desktop { display: none !important; }
}

/* Responsive show/hide */
.show-mobile { display: none !important; }
@media (max-width: 768px) {
  .show-mobile { display: block !important; }
}
