/* Modern shadcn-inspired Design System for 7 Figure Script Writer */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
  /* Background colors */
  --background: 222.2 84% 4.9%;
  --foreground: 210 40% 98%;
  
  --muted: 217.2 32.6% 10%;
  --muted-foreground: 215 20.2% 55%;
  
  --card: 222.2 84% 6%;
  --card-foreground: 210 40% 98%;
  
  --popover: 222.2 84% 6%;
  --popover-foreground: 210 40% 98%;
  
  /* Border colors */
  --border: 217.2 32.6% 12%;
  --input: 217.2 32.6% 12%;
  --ring: 212.7 26.8% 83.9%;
  
  /* Primary - Blue accent */
  --primary: 207 90% 54%;
  --primary-foreground: 222.2 47.4% 11.2%;
  
  /* Secondary */
  --secondary: 217.2 32.6% 12%;
  --secondary-foreground: 210 40% 98%;
  
  /* Accent */
  --accent: 217.2 32.6% 14%;
  --accent-foreground: 210 40% 98%;
  
  /* Destructive */
  --destructive: 0 62.8% 50%;
  --destructive-foreground: 210 40% 98%;
  
  /* Sidebar */
  --sidebar: 240 5.9% 8%;
  --sidebar-foreground: 240 4.8% 95.9%;
  --sidebar-accent: 240 3.7% 12%;
  --sidebar-border: 240 3.7% 12%;
  
  /* UI properties */
  --radius: 0.5rem;
  
  /* Legacy variables for compatibility */
  --bg-base: hsl(var(--background));
  --bg-elevated: hsl(var(--sidebar));
  --bg-card: hsl(var(--card));
  --bg-card-hover: hsl(var(--accent));
  --bg-input: hsl(217.2 32.6% 8%);
  
  --border-subtle: hsl(var(--border));
  --border-default: hsl(217.2 32.6% 15%);
  --border-focus: hsl(var(--primary));
  
  --text-primary: hsl(var(--foreground));
  --text-secondary: hsl(var(--muted-foreground));
  --text-muted: hsl(215 20.2% 45%);
  
  --success: hsl(142.1 76.2% 36.3%);
  --error: hsl(var(--destructive));
  
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.1);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.2);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.3);
  
  --radius-sm: calc(var(--radius) - 4px);
  --radius-md: calc(var(--radius) - 2px);
  --radius-lg: var(--radius);
  --radius-xl: calc(var(--radius) + 4px);
  --radius-full: 9999px;
}

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

body {
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-base);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Layout */
.layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  width: 280px;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-header {
  padding: 16px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.logo {
  font-weight: 700;
  font-size: 1.125rem;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.sidebar-header-actions {
  display: flex;
  gap: 8px;
}

.new-btn {
  padding: 8px 14px;
  border-radius: var(--radius-md);
  border: none;
  background: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.new-btn:hover {
  opacity: 0.9;
}

.logout-btn {
  padding: 8px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-default);
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.logout-btn:hover {
  background: var(--bg-card);
  color: var(--text-primary);
}

.sidebar-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  padding: 8px;
  gap: 2px;
}

.nav-link {
  padding: 10px 12px;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  gap: 10px;
}

.nav-link:hover {
  background: var(--bg-card);
  color: var(--text-primary);
}

.nav-link-active {
  background: hsl(var(--sidebar-accent));
  color: var(--text-primary);
}

.nav-link-active:hover {
  background: hsl(var(--sidebar-accent));
}

.logout-nav-btn {
  width: 100%;
  background: transparent;
  border: none;
  cursor: pointer;
  text-align: left;
  margin-top: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--border-subtle);
}

.logout-nav-btn:hover {
  color: hsl(0, 84%, 60%);
}

.sidebar-history {
  padding: 8px 12px 16px;
  border-top: 1px solid var(--border-subtle);
  margin-top: auto;
  flex: 1;
  overflow-y: auto;
}

.sidebar-history-header {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
  padding: 4px;
}

.sidebar-group {
  margin-bottom: 12px;
}

.sidebar-group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 4px;
  cursor: pointer;
  padding: 4px;
  border-radius: var(--radius-sm);
  transition: background 0.15s ease;
}

.sidebar-group-header:hover {
  background: var(--bg-card);
}

.sidebar-group-label {
  flex: 1;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.sidebar-group-count {
  font-size: 0.7rem;
  color: var(--text-muted);
  background: var(--bg-card);
  padding: 2px 6px;
  border-radius: var(--radius-full);
  margin-right: 6px;
}

.sidebar-group-toggle {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.65rem;
  cursor: pointer;
  padding: 2px 4px;
  transition: color 0.2s ease;
}

.sidebar-group-toggle:hover {
  color: var(--text-secondary);
}

.sidebar-item {
  padding: 8px 10px;
  border-radius: var(--radius-md);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 2px;
  position: relative;
  transition: all 0.15s ease;
  border: 1px solid transparent;
}

.sidebar-item:hover {
  background: var(--bg-card);
}

.sidebar-item.selected {
  background: hsl(var(--sidebar-accent));
  border-color: var(--border-default);
}

.sidebar-item-title {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-right: 40px;
}

.sidebar-item-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.sidebar-empty {
  font-size: 0.875rem;
  color: var(--text-muted);
  text-align: center;
  padding: 16px 8px;
}

.sidebar-item-actions {
  position: absolute;
  right: 8px;
  top: 8px;
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.sidebar-item:hover .sidebar-item-actions {
  opacity: 1;
}

.sidebar-item-action-btn {
  border: none;
  background: var(--bg-elevated);
  color: var(--text-muted);
  font-size: 0.7rem;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  transition: all 0.15s ease;
}

.sidebar-item-action-btn:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
}

/* Main Content */
.main {
  flex: 1;
  padding: 24px 32px;
  overflow-y: auto;
  background: var(--bg-base);
}

.main h1 {
  font-size: 1.75rem;
  font-weight: 700;
  margin: 0 0 8px;
  letter-spacing: -0.03em;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 12px;
}

.main h1 svg {
  color: hsl(var(--primary));
  width: 28px;
  height: 28px;
}

h1 {
  font-size: 1.5rem;
  font-weight: 600;
  margin: 0 0 6px;
  letter-spacing: -0.025em;
  color: var(--text-primary);
}

h2 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 8px;
}

h2 svg {
  width: 18px;
  height: 18px;
  color: hsl(var(--primary));
}

.small {
  font-size: 0.875rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

/* Grid Layout */
.grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 20px;
  margin-top: 20px;
}

/* Cards */
.card {
  background: var(--bg-card);
  border-radius: 12px;
  padding: 24px;
  border: 1px solid var(--border-subtle);
  transition: all 0.2s ease;
}

.card:hover {
  border-color: var(--border-default);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.card + .card {
  margin-top: 20px;
}

.card h2 {
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-subtle);
}

/* Form Elements */
label {
  display: block;
  margin-bottom: 8px;
  font-weight: 500;
  font-size: 0.8125rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

input[type="text"],
select,
textarea {
  width: 100%;
  padding: 12px 16px;
  border-radius: 8px;
  border: 1px solid var(--border-default);
  background: var(--bg-input);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.9375rem;
  transition: all 0.2s ease;
}

input[type="text"]:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: hsl(var(--primary));
  box-shadow: 0 0 0 3px hsl(var(--primary) / 0.15);
}

input[type="text"]::placeholder,
textarea::placeholder {
  color: var(--text-muted);
}

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' fill='none'%3E%3Cpath d='M2.5 4.5L6 8L9.5 4.5' stroke='%2371717a' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 40px;
}

select option {
  background: var(--bg-card);
  color: var(--text-primary);
}

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

/* Buttons */
button.primary {
  padding: 12px 24px;
  border-radius: 8px;
  border: none;
  background: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
  font-weight: 600;
  font-size: 0.9375rem;
  cursor: pointer;
  margin-top: 16px;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

button.primary:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px hsl(var(--primary) / 0.3);
}

button.primary:active:not(:disabled) {
  transform: translateY(0);
}

button.primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

button.secondary {
  padding: 10px 20px;
  border-radius: 8px;
  border: 1px solid var(--border-default);
  background: var(--bg-card);
  color: var(--text-primary);
  font-weight: 500;
  font-size: 0.875rem;
  cursor: pointer;
  margin-top: 12px;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

button.secondary:hover:not(:disabled) {
  background: var(--bg-card-hover);
  border-color: hsl(var(--primary) / 0.5);
}

button.secondary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Code/Pre blocks */
pre {
  white-space: pre-wrap;
  word-wrap: break-word;
  background: hsl(222.2 84% 3.5%);
  padding: 20px;
  border-radius: 10px;
  font-size: 0.9rem;
  font-family: 'SF Mono', Monaco, Consolas, monospace;
  overflow-x: auto;
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  line-height: 1.8;
  margin-top: 12px;
}

/* Login Page */
.login-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg-base);
  padding: 20px;
}

.login-card {
  background: var(--bg-card);
  padding: 32px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  max-width: 380px;
  width: 100%;
  border: 1px solid var(--border-subtle);
}

.login-card h1 {
  font-size: 1.25rem;
  margin-bottom: 6px;
  text-align: center;
}

.login-card .small {
  text-align: center;
  margin-bottom: 24px;
}

.login-card input {
  margin-bottom: 12px;
}

.login-card button {
  width: 100%;
  margin-top: 4px;
}

.error {
  color: var(--error);
  font-size: 0.875rem;
  margin-top: 10px;
  text-align: center;
}

/* Status indicator */
#status {
  margin-left: 12px;
  font-size: 0.875rem;
  color: var(--text-muted);
}

/* Responsive */
@media (max-width: 1024px) {
  .grid {
    grid-template-columns: 1fr;
  }
  
  .main {
    padding: 20px;
  }
}

/* Mobile header with hamburger */
.mobile-header {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 56px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border-subtle);
  padding: 0 16px;
  align-items: center;
  justify-content: space-between;
  z-index: 100;
}

.mobile-header .logo {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.beta-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 6px;
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: linear-gradient(135deg, hsl(var(--primary)), hsl(280, 70%, 50%));
  color: white;
  border-radius: 4px;
  vertical-align: middle;
}

.mobile-header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.report-error-link {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 12px;
  padding: 6px 10px;
  border-radius: var(--radius-md);
  transition: all 0.15s ease;
}

.report-error-link:hover {
  color: var(--text-primary);
  background: var(--accent);
}

.report-error-link svg {
  width: 14px;
  height: 14px;
}

/* Desktop report error link in sidebar */
.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border-subtle);
  margin-top: auto;
}

.sidebar-footer .report-error-link {
  width: 100%;
  justify-content: center;
  padding: 8px 12px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
}

.hamburger-btn {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  width: 40px;
  height: 40px;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 8px;
  gap: 5px;
}

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

.hamburger-btn.active span:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}

.hamburger-btn.active span:nth-child(2) {
  opacity: 0;
}

.hamburger-btn.active span:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

.sidebar-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 98;
}

@media (max-width: 768px) {
  .mobile-header {
    display: flex;
  }
  
  .sidebar {
    position: fixed;
    top: 56px;
    left: 0;
    bottom: 0;
    z-index: 99;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    width: 280px;
  }
  
  .sidebar.open {
    transform: translateX(0);
  }
  
  .sidebar-overlay.visible {
    display: block;
  }
  
  .main {
    padding: 16px;
    margin-top: 56px;
    height: calc(100vh - 56px);
    overflow-y: auto;
  }
  
  .layout {
    display: block;
    height: auto;
    overflow: visible;
  }
}

/* Form row for side-by-side inputs */
.form-row {
  display: flex;
  gap: 12px;
  margin-top: 12px;
}

.form-row > div {
  flex: 1;
}

/* Section spacing */
.section-gap {
  margin-top: 16px;
}

/* Badge styles */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 500;
  background: hsl(var(--secondary));
  color: var(--text-secondary);
}

/* Smooth scrollbar */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: hsl(var(--border));
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* Collapsible Card */
.card-collapsible .card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  user-select: none;
  padding-bottom: 12px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--border-subtle);
  transition: border-color 0.15s ease;
}

.card-collapsible.collapsed .card-header {
  padding-bottom: 0;
  margin-bottom: 0;
  border-bottom: none;
}

.card-header h2 {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-header .toggle-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-size: 14px;
  transition: all 0.15s ease;
}

.card-header:hover .toggle-icon {
  background: var(--bg-card-hover);
  color: var(--text-primary);
}

.card-collapsible .card-body {
  overflow: hidden;
  transition: max-height 0.2s ease, opacity 0.15s ease;
  max-height: 2000px;
  opacity: 1;
}

.card-collapsible.collapsed .card-body {
  max-height: 0;
  opacity: 0;
  padding-top: 0;
}

/* Scrollable output */
.scrollable-output {
  max-height: 500px;
  overflow-y: auto;
}

/* Output toolbar */
.output-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  gap: 12px;
}

.output-toolbar .small {
  margin: 0;
  flex: 1;
}

.copy-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-default);
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.copy-btn:hover {
  background: var(--bg-card);
  color: var(--text-primary);
  border-color: var(--border-default);
}

.copy-btn svg {
  flex-shrink: 0;
}

/* Hook regenerate button */
.regenerate-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-default);
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.regenerate-btn:hover:not(:disabled) {
  background: var(--bg-card);
  color: var(--text-primary);
}

.regenerate-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Secondary button style */
button.secondary {
  padding: 10px 20px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-default);
  background: transparent;
  color: var(--text-secondary);
  font-weight: 500;
  font-size: 0.875rem;
  cursor: pointer;
  margin-top: 12px;
  transition: all 0.15s ease;
}

button.secondary:hover:not(:disabled) {
  background: var(--bg-card);
  color: var(--text-primary);
}

button.secondary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Loading spinner */
.loading-spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid transparent;
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-right: 6px;
}

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