/* CSS Variables */
:root {
  --primary: #f97316;
  --primary-hover: #ea580c;
  --bg: #faf9f7;
  --bg-card: #ffffff;
  --text: #1f2937;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --gradient-start: #fef3c7;
  --gradient-mid: #fce7f3;
  --gradient-end: #dbeafe;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
}

/* Reset */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

/* Utility Classes */
.hidden {
  display: none !important;
}

.muted {
  color: var(--text-muted);
}

.small {
  font-size: 0.875rem;
}

.full {
  width: 100%;
}

.full-width {
  grid-column: 1 / -1;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.625rem 1rem;
  border: none;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.btn.primary {
  background: var(--primary);
  color: white;
}

.btn.primary:hover {
  background: var(--primary-hover);
}

.btn.ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}

.btn.ghost:hover {
  background: #f3f4f6;
}

.btn.danger {
  background: var(--danger);
  color: white;
}

.btn.danger:hover {
  background: #dc2626;
}

.btn.small {
  padding: 0.375rem 0.75rem;
  font-size: 0.8125rem;
}

.btn.full {
  width: 100%;
}

.btn-group {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

/* Form buttons stacked */
.form-card .btn.full+.btn.full {
  margin-top: 0.5rem;
}

/* Forms */
.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 0.5rem;
  color: var(--text);
}

.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9375rem;
  font-family: inherit;
  transition: border-color 0.2s;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--primary);
}

.form-group.inline {
  display: inline-flex;
  flex-direction: column;
  margin-right: 1rem;
  min-width: 120px;
}

/* Password Input Wrapper */
.password-input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.password-input-wrapper input {
  padding-right: 2.5rem;
}

.input-btn {
  position: absolute;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  color: #9ca3af;
  transition: color 0.2s;
  padding: 0.25rem;
}

.input-btn:hover {
  color: #374151;
}

.password-toggle {
  right: 0.5rem;
}

/* Checkbox */
.checkbox-group {
  margin-bottom: 1rem;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  font-size: 0.875rem;
}

.checkbox-label input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
}

/* Password Match Status */
.password-match-status {
  display: block;
  font-size: 0.8125rem;
  margin-top: 0.375rem;
  min-height: 1.25em;
}

.password-match-status.match {
  color: var(--success);
}

.password-match-status.no-match {
  color: var(--danger);
}

/* Cards */
.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
}

.card h3 {
  font-size: 1.125rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

/* Tables */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.data-table th,
.data-table td {
  padding: 0.875rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.data-table th {
  font-weight: 500;
  color: var(--text-muted);
  background: #f9fafb;
}

.data-table tbody tr:hover {
  background: #f9fafb;
}

.data-table .empty {
  text-align: center;
  color: var(--text-muted);
  padding: 2rem;
}

.data-table .actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.data-table .actions .btn {
  padding: 0.375rem 0.75rem;
  font-size: 0.8125rem;
}

/* Badge */
.badge {
  display: inline-block;
  padding: 0.25rem 0.75rem;
  background: rgba(249, 115, 22, 0.1);
  color: var(--primary);
  border-radius: 999px;
  font-size: 0.8125rem;
  font-weight: 500;
}

/* Status */
.status {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.25rem 0.625rem;
  border-radius: 999px;
  font-size: 0.8125rem;
  font-weight: 500;
}

.status::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

.status.pending {
  background: #fef3c7;
  color: #b45309;
}

.status.pending::before {
  background: #f59e0b;
}

.status.generating {
  background: #dbeafe;
  color: #1d4ed8;
}

.status.generating::before {
  background: #3b82f6;
}

.status.completed {
  background: #d1fae5;
  color: #047857;
}

.status.completed::before {
  background: #10b981;
}

.status.in_progress {
  background: #dbeafe;
  color: #1d4ed8;
}

.status.in_progress::before {
  background: #3b82f6;
}

/* Login Screen */
#login-screen {
  min-height: 100vh;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--gradient-start), var(--gradient-mid), var(--gradient-end));
}

.login-container {
  width: 100%;
  max-width: 400px;
  padding: 2rem;
}

.logo {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 2rem;
}

.logo-icon {
  width: 48px;
  height: 48px;
  background: var(--text);
  color: white;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.125rem;
}

.logo-text {
  display: flex;
  flex-direction: column;
}

.logo-title {
  font-weight: 600;
  font-size: 1.125rem;
}

.logo-subtitle {
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.auth-form {
  background: var(--bg-card);
  padding: 2rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
}

.auth-form h2 {
  font-size: 1.25rem;
  margin-bottom: 1.5rem;
}

.auth-switch {
  text-align: center;
  margin-top: 1rem;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.auth-switch a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 500;
}

/* Screen management */
.screen {
  display: none;
}

.screen.active {
  display: block;
}

#login-screen.active {
  display: flex;
}

/* Header */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 2rem;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.logo-small {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.logo-small .logo-icon {
  width: 36px;
  height: 36px;
  font-size: 0.875rem;
}

#page-title {
  font-weight: 600;
  font-size: 0.9375rem;
  color: var(--text-muted);
}

.nav {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.nav-link {
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text);
  font-size: 0.9375rem;
  font-weight: 500;
  transition: all 0.2s;
}

.nav-link:hover {
  background: #f3f4f6;
}

.nav-link.active {
  background: var(--text);
  color: white;
}

/* Main Content */
.main-content {
  padding: 2rem;
  max-width: 1400px;
  margin: 0 auto;
}

/* Pages */
.page {
  display: none;
}

.page.active {
  display: block;
}

.page-header {
  padding: 2rem;
  border-radius: var(--radius);
  margin-bottom: 2rem;
}

.page-header.gradient-bg {
  background: linear-gradient(135deg, var(--gradient-start), var(--gradient-mid), var(--gradient-end));
}

.page-header h1 {
  font-size: 2rem;
  font-weight: 700;
  line-height: 1.3;
  margin: 0.75rem 0;
}

.page-header p {
  color: var(--text-muted);
  margin-bottom: 1.5rem;
}

.project-meta {
  display: flex;
  gap: 1.5rem;
  margin-top: 1rem;
}

.meta-item {
  font-size: 0.9375rem;
}

.meta-item code {
  background: rgba(0, 0, 0, 0.05);
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  font-size: 0.8125rem;
}

/* Content Grid */
.content-grid {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1.5rem;
}

/* Info Item */
.info-item {
  display: flex;
  justify-content: space-between;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border);
}

.info-item .label {
  color: var(--text-muted);
  font-size: 0.875rem;
}

.info-item .value {
  font-weight: 500;
}

/* Quick Start */
.quick-start {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-top: 1rem;
}

.step {
  display: flex;
  gap: 1rem;
}

.step-num {
  width: 24px;
  height: 24px;
  background: var(--primary);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 600;
  flex-shrink: 0;
}

.step strong {
  display: block;
  margin-bottom: 0.25rem;
}

.step p {
  font-size: 0.8125rem;
  color: var(--text-muted);
}

/* Filter Row */
.filter-row {
  display: flex;
  align-items: flex-end;
  gap: 1rem;
  flex-wrap: wrap;
}

/* Token Result */
.token-result {
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

.token-result .warning {
  color: var(--warning);
  font-size: 0.875rem;
  font-weight: 500;
}

.token-display {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
  padding: 1rem;
  background: #f3f4f6;
  border-radius: var(--radius);
}

.token-display code {
  flex: 1;
  word-break: break-all;
  font-size: 0.8125rem;
}

/* Pattern List */
.pattern-list {
  list-style: none;
  margin-top: 0.5rem;
}

.pattern-list li {
  padding: 0.5rem 0;
}

.pattern-list code {
  background: #f3f4f6;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  font-size: 0.8125rem;
}

/* Pagination */
.pagination {
  display: flex;
  justify-content: center;
  gap: 0.25rem;
  margin-top: 1.5rem;
}

.pagination button {
  width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  background: white;
  border-radius: 6px;
  cursor: pointer;
}

.pagination button.active {
  background: var(--text);
  color: white;
  border-color: var(--text);
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal {
  background: var(--bg-card);
  border-radius: var(--radius);
  max-width: 600px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
}

.modal-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-muted);
}

.modal-content {
  padding: 2rem;
}

.modal-content h3 {
  font-size: 1.25rem;
  margin-bottom: 1.5rem;
}

/* Image Preview */
.image-preview {
  width: 100%;
  max-height: 400px;
  object-fit: contain;
  border-radius: var(--radius);
  background: #f3f4f6;
}

/* Upload Zone */
.upload-zone {
  border: 2px dashed var(--primary);
  border-radius: var(--radius);
  padding: 3rem 2rem;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
}

.upload-zone:hover {
  background: rgba(249, 115, 22, 0.05);
}

.upload-zone.dragover {
  background: rgba(249, 115, 22, 0.1);
  border-color: var(--primary-hover);
}

.upload-icon {
  font-size: 2rem;
  margin-bottom: 1rem;
}

.upload-zone p {
  margin-bottom: 0.5rem;
}

.upload-zone .muted {
  font-size: 0.8125rem;
}

/* Responsive */
@media (max-width: 1024px) {
  .content-grid {
    grid-template-columns: 1fr;
  }

  .dashboard-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  .header {
    flex-direction: column;
    gap: 1rem;
  }

  .nav {
    flex-wrap: wrap;
    justify-content: center;
  }

  .main-content {
    padding: 1rem;
  }

  .page-header h1 {
    font-size: 1.5rem;
  }
}