/**
 * StoryDesk - Main Stylesheet
 * Minimal, clean design system
 */

/* ===================== */
/* CSS Variables         */
/* ===================== */
:root {
  /* Colors */
  --color-primary: #143234;
  --color-primary-hover: #1a3a3c;
  --color-accent: #ED8767;
  --color-accent-light: #FEF7F4;

  /* Grays */
  --color-gray-50: #f9fafb;
  --color-gray-100: #f3f4f6;
  --color-gray-200: #e5e7eb;
  --color-gray-300: #d1d5db;
  --color-gray-400: #9ca3af;
  --color-gray-500: #6b7280;
  --color-gray-600: #4b5563;
  --color-gray-700: #374151;
  --color-gray-800: #1f2937;
  --color-gray-900: #111827;

  /* Status colors */
  --color-success: #10b981;
  --color-success-light: #d1fae5;
  --color-error: #ef4444;
  --color-error-light: #fee2e2;
  --color-warning: #f59e0b;
  --color-warning-light: #fef3c7;
  --color-info: #3b82f6;
  --color-info-light: #dbeafe;

  /* Spacing */
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;

  /* Border radius */
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
  --radius-xl: 12px;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.07);
  --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1);

  /* Transitions */
  --transition-fast: 0.15s ease;
  --transition-normal: 0.2s ease;
}

/* ===================== */
/* Base Reset            */
/* ===================== */
* {
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 1rem;
  line-height: 1.5;
  color: var(--color-gray-700);
  background: var(--color-gray-100);
  margin: 0;
  padding: 0;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ===================== */
/* Typography            */
/* ===================== */
h1, h2, h3, h4, h5, h6 {
  color: var(--color-primary);
  font-weight: 600;
  line-height: 1.3;
  margin: 0 0 var(--space-md) 0;
}

h1 { font-size: 1.5rem; }
h2 { font-size: 1rem; }
h3 { font-size: 0.9375rem; color: var(--color-gray-600); }
h4 { font-size: 0.875rem; }

p {
  margin: 0 0 var(--space-md) 0;
}

a {
  color: var(--color-primary);
  text-decoration: none;
  transition: color var(--transition-fast);
}

a:hover {
  color: var(--color-primary-hover);
}

/* ===================== */
/* Form Elements         */
/* ===================== */
.form-group {
  margin-bottom: 1.25rem;
}

label {
  display: block;
  margin-bottom: var(--space-sm);
  font-weight: 500;
  font-size: 0.875rem;
  color: var(--color-gray-700);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="url"],
input[type="search"],
textarea,
select {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1px solid var(--color-gray-200);
  border-radius: var(--radius-lg);
  font-size: 0.9375rem;
  font-family: inherit;
  background: var(--color-gray-50);
  color: var(--color-gray-800);
  transition: border-color var(--transition-fast), background var(--transition-fast), box-shadow var(--transition-fast);
}

input[type="text"]:hover,
input[type="email"]:hover,
input[type="password"]:hover,
textarea:hover,
select:hover {
  border-color: var(--color-gray-300);
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--color-primary);
  background: white;
  box-shadow: 0 0 0 3px rgba(20, 50, 52, 0.1);
}

input::placeholder,
textarea::placeholder {
  color: var(--color-gray-400);
}

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

select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236b7280' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 1rem center;
  padding-right: 2.5rem;
}

/* Checkbox and Radio */
input[type="checkbox"],
input[type="radio"] {
  width: auto;
  margin-right: var(--space-sm);
  accent-color: var(--color-primary);
}

/* ===================== */
/* Button System         */
/* ===================== */
button,
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: 0.625rem 1.25rem;
  font-size: 0.875rem;
  font-weight: 500;
  font-family: inherit;
  line-height: 1;
  border: none;
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: all var(--transition-fast);
  text-decoration: none;
}

/* Primary Button (default) */
button,
.btn,
.btn-primary {
  background: var(--color-primary);
  color: white;
}

button:hover,
.btn:hover,
.btn-primary:hover {
  background: var(--color-primary-hover);
}

button:disabled,
.btn:disabled {
  background: var(--color-gray-200);
  color: var(--color-gray-400);
  cursor: not-allowed;
}

/* Secondary Button */
.btn-secondary {
  background: white;
  color: var(--color-gray-700);
  border: 1px solid var(--color-gray-300);
}

.btn-secondary:hover {
  background: var(--color-gray-50);
  border-color: var(--color-gray-400);
  color: var(--color-gray-800);
}

/* Ghost Button */
.btn-ghost {
  background: transparent;
  color: var(--color-gray-500);
  border: none;
}

.btn-ghost:hover {
  background: var(--color-gray-100);
  color: var(--color-gray-700);
}

/* Accent Button */
.btn-accent {
  background: var(--color-accent);
  color: white;
}

.btn-accent:hover {
  background: #d97355;
}

/* Button Sizes */
.btn-small {
  padding: 0.5rem 1rem;
  font-size: 0.8125rem;
}

.btn-large {
  padding: 0.875rem 1.75rem;
  font-size: 1rem;
}

/* Button with icon */
.btn svg {
  width: 1em;
  height: 1em;
}

/* Pill Button (toggle/chip style) */
.btn-pill {
  padding: 0.5rem 1rem;
  border: 2px solid var(--color-gray-200);
  border-radius: var(--radius-full);
  background: white;
  color: var(--color-gray-700);
  cursor: pointer;
  transition: all var(--transition-fast);
  font-size: 0.9rem;
}

.btn-pill:hover {
  border-color: var(--color-accent);
  background: white;
}

.btn-pill.active {
  border-color: var(--color-accent);
  background: white;
  color: var(--color-gray-700);
}

/* Pill Accent (solid accent color) */
.btn-pill-accent {
  padding: 0.4rem 0.85rem;
  background: var(--color-accent);
  border: none;
  border-radius: var(--radius-full);
  font-size: 0.85rem;
  font-weight: 500;
  color: white;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-pill-accent:hover {
  background: #d97355;
}

/* ===================== */
/* Chips & Tags          */
/* ===================== */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.4rem 0.85rem;
  background: white;
  border: 2px solid var(--color-gray-200);
  border-radius: var(--radius-full);
  font-size: 0.85rem;
  color: var(--color-gray-700);
}

.chip.selected {
  border-color: var(--color-accent);
}

/* Button Groups (pill toggle selectors) */
.btn-pill-group {
  display: flex;
  gap: var(--space-sm);
  flex-wrap: wrap;
}

@media (max-width: 640px) {
  .btn-pill-group .btn-pill {
    flex: 1;
    min-width: 80px;
    text-align: center;
    padding: 0.5rem;
    font-size: 0.8rem;
  }
}

@media (max-width: 480px) {
  .btn-pill-group .btn-pill {
    font-size: 0.75rem;
    padding: 0.4rem;
  }
}

.chip-icon {
  width: 18px;
  height: 18px;
  border-radius: 3px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  font-weight: bold;
  color: white;
}

/* ===================== */
/* Cards                 */
/* ===================== */
.card {
  background: white;
  border: 1px solid var(--color-gray-200);
  border-radius: var(--radius-xl);
  padding: var(--space-lg);
  margin-bottom: var(--space-md);
}

.card h2 {
  font-size: 1rem;
  margin-bottom: var(--space-md);
}

/* ===================== */
/* Alerts & Messages     */
/* ===================== */
.alert {
  padding: var(--space-md);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-lg);
  font-size: 0.9375rem;
}

.alert-success {
  background: var(--color-success-light);
  color: #065f46;
  border: 1px solid #a7f3d0;
}

.alert-error {
  background: var(--color-error-light);
  color: #991b1b;
  border: 1px solid #fecaca;
}

.alert-warning {
  background: var(--color-warning-light);
  color: #92400e;
  border: 1px solid #fde68a;
}

.alert-info {
  background: var(--color-info-light);
  color: #1e40af;
  border: 1px solid #bfdbfe;
}

.alert a {
  color: inherit;
  font-weight: 600;
  text-decoration: underline;
}

/* ===================== */
/* Toggle Buttons        */
/* ===================== */
.toggle-btn,
.source-toggle-btn {
  padding: 0.5rem 1.25rem;
  border: 1px solid var(--color-gray-200);
  border-radius: var(--radius-full);
  background: white;
  color: var(--color-gray-500);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.toggle-btn:hover,
.source-toggle-btn:hover {
  border-color: var(--color-gray-300);
  color: var(--color-gray-700);
}

.toggle-btn.active,
.source-toggle-btn.active {
  border-color: var(--color-accent);
  background: var(--color-accent-light);
  color: #c75a3a;
}

/* ===================== */
/* Status Indicators     */
/* ===================== */
.status-indicator {
  display: inline-block;
  font-size: 0.9rem;
  line-height: 1;
}

.status-ok::before,
.status-success::before {
  content: '✓';
  color: var(--color-gray-800);
}

.status-error::before {
  content: '✗';
  color: var(--color-gray-400);
}

.status-warning::before {
  content: '!';
  color: var(--color-gray-600);
}

.status-info::before {
  content: 'i';
  color: var(--color-gray-600);
}

/* ===================== */
/* Badges & Tags         */
/* ===================== */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.125rem 0.5rem;
  font-size: 0.75rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  background: var(--color-gray-100);
  color: var(--color-gray-600);
}

.badge-success {
  background: var(--color-success-light);
  color: #065f46;
}

.badge-error {
  background: var(--color-error-light);
  color: #991b1b;
}

.badge-warning {
  background: var(--color-warning-light);
  color: #92400e;
}

.badge-info {
  background: var(--color-info-light);
  color: #1e40af;
}

/* ===================== */
/* Tables                */
/* ===================== */
table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  padding: 0.75rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--color-gray-200);
}

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

tr:hover td {
  background: var(--color-gray-50);
}

/* ===================== */
/* Modals                */
/* ===================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

/* For modals using .show class pattern */
.modal-overlay.animate {
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition-normal);
}

.modal-overlay.animate.show {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: white;
  border-radius: var(--radius-xl);
  padding: var(--space-lg);
  max-width: 500px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
  transform: scale(0.95);
  transition: transform var(--transition-normal);
}

.modal-overlay.show .modal {
  transform: scale(1);
}

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

.modal-header h2 {
  margin: 0;
}

.modal-close {
  background: none;
  border: none;
  padding: var(--space-sm);
  cursor: pointer;
  color: var(--color-gray-400);
  border-radius: var(--radius-md);
}

.modal-close:hover {
  background: var(--color-gray-100);
  color: var(--color-gray-600);
}

/* ===================== */
/* Utility Classes       */
/* ===================== */
.hidden {
  display: none !important;
}

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

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

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

.text-small {
  font-size: 0.875rem;
}

.text-xs {
  font-size: 0.75rem;
}

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

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

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

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

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

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

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

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

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

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

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

/* Spacing utilities */
.mt-sm { margin-top: var(--space-sm); }
.mt-md { margin-top: var(--space-md); }
.mt-lg { margin-top: var(--space-lg); }

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

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

/* ===================== */
/* Action Buttons Group  */
/* ===================== */
.action-buttons {
  display: flex;
  gap: var(--space-sm);
  flex-wrap: wrap;
}

.action-buttons button {
  padding: 0.5rem 1rem;
  font-size: 0.8125rem;
}

.action-buttons button[type="submit"] {
  padding: 0.625rem 1.5rem;
  font-size: 0.875rem;
}

/* ===================== */
/* Loading & Spinners    */
/* ===================== */
.spinner {
  display: inline-block;
  width: 1em;
  height: 1em;
  border: 2px solid var(--color-gray-200);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading {
  opacity: 0.6;
  pointer-events: none;
}

/* Fun Loading Indicator */
.fun-loader {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  background: var(--color-gray-100);
  border-radius: var(--radius-full);
  font-size: 0.875rem;
  color: var(--color-gray-600);
}

.fun-loader-dots {
  display: flex;
  gap: 3px;
}

.fun-loader-dot {
  width: 6px;
  height: 6px;
  background: #9ca3af; /* fallback */
  background: var(--color-gray-400, #9ca3af);
  border-radius: 50%;
  animation: funBounce 1.4s ease-in-out infinite;
}

.fun-loader-dot:nth-child(1) { animation-delay: 0s; }
.fun-loader-dot:nth-child(2) { animation-delay: 0.2s; }
.fun-loader-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes funBounce {
  0%, 80%, 100% {
    transform: scale(1);
    opacity: 0.4;
  }
  40% {
    transform: scale(1.3);
    opacity: 1;
  }
}

.fun-loader-text {
  font-weight: 500;
  min-width: 100px;
}

/* Fun Loader Modal - centered, offset for sidebar */
.fun-loader-modal {
  position: fixed;
  top: 50%;
  left: 50%;
  margin-left: 100px; /* offset for sidebar */
  transform: translate(-50%, -50%) scale(0.95);
  z-index: 9999;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease, transform 0.2s ease;
}

.fun-loader-modal.show {
  opacity: 1;
  visibility: visible;
  transform: translate(-50%, -50%) scale(1);
}

.fun-loader-modal-content {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.5rem;
  background: white;
  border-radius: 12px; /* fallback */
  border-radius: var(--radius-xl, 12px);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  border: 1px solid #e5e7eb; /* fallback */
  border: 1px solid var(--color-gray-200, #e5e7eb);
}

/* ===================== */
/* Responsive            */
/* ===================== */
@media (max-width: 768px) {
  :root {
    --space-lg: 1.25rem;
    --space-xl: 1.5rem;
  }

  h1 { font-size: 1.25rem; }

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

  button, .btn {
    padding: 0.5rem 1rem;
  }

  .action-buttons {
    flex-direction: column;
  }

  .action-buttons button {
    width: 100%;
  }
}

@media (max-width: 480px) {
  body {
    font-size: 0.9375rem;
  }

  .toggle-btn,
  .source-toggle-btn {
    padding: 0.375rem 0.875rem;
    font-size: 0.8125rem;
  }
}
