/* === Design Tokens === */
:root {
  --color-primary: #1a56db;
  --color-primary-hover: #1e40af;
  --color-primary-light: #dbeafe;
  --color-success: #059669;
  --color-success-light: #d1fae5;
  --color-error: #dc2626;
  --color-error-light: #fee2e2;
  --color-warning: #d97706;
  --color-warning-light: #fef3c7;
  --color-bg: #f8fafc;
  --color-surface: #ffffff;
  --color-text: #0f172a;
  --color-text-secondary: #475569;
  --color-text-muted: #94a3b8;
  --color-border: #e2e8f0;
  --color-border-focus: #1a56db;
  --font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 10px 24px rgba(0, 0, 0, 0.1);
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
}

/* === Reset === */
*, *::before, *::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-family);
  background: var(--color-bg);
  color: var(--color-text);
  font-size: 15px;
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* === Top Bar === */
.top-bar {
  height: 56px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 0;
  z-index: 10;
}

.top-bar .app-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 16px;
  color: var(--color-text);
}

.top-bar .app-title svg {
  color: var(--color-primary);
  flex-shrink: 0;
}

.auth-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  background: var(--color-bg);
  color: var(--color-text-secondary);
  border: 1px solid var(--color-border);
}

.auth-pill.authenticated {
  background: var(--color-success-light);
  color: #065f46;
  border-color: #a7f3d0;
}

.auth-pill.expiring {
  background: var(--color-warning-light);
  color: #92400e;
  border-color: #fde68a;
}

.auth-pill .pill-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-text-muted);
}

.auth-pill.authenticated .pill-dot {
  background: var(--color-success);
}

.auth-pill.expiring .pill-dot {
  background: var(--color-warning);
}

/* === Main Container === */
.container {
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
  padding: 32px 16px 64px;
  flex: 1;
}

/* === Stepper Header === */
.stepper-header {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 24px;
  margin-bottom: 32px;
}

.step-indicator {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  cursor: default;
  position: relative;
}

.step-indicator.clickable {
  cursor: pointer;
}

.step-circle {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  border: 2px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text-muted);
  transition: all 0.2s ease;
}

.step-indicator.active .step-circle {
  border-color: var(--color-primary);
  background: var(--color-primary);
  color: #ffffff;
}

.step-indicator.completed .step-circle {
  border-color: var(--color-success);
  background: var(--color-success);
  color: #ffffff;
}

.step-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text-muted);
  white-space: nowrap;
}

.step-indicator.active .step-label {
  color: var(--color-primary);
  font-weight: 600;
}

.step-indicator.completed .step-label {
  color: var(--color-success);
}

.step-connector {
  flex: 1;
  height: 2px;
  background: var(--color-border);
  margin: 0 12px;
  margin-bottom: 28px;
  transition: background 0.2s ease;
}

.step-connector.completed {
  background: var(--color-success);
}

/* === Step Panels === */
.step-panel {
  display: none;
}

.step-panel.active {
  display: block;
  animation: fadeIn 0.25s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.step-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.step-card-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--color-border);
}

.step-card-header h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: var(--color-text);
}

.step-card-header p {
  margin: 4px 0 0;
  font-size: 14px;
  color: var(--color-text-secondary);
}

.step-card-body {
  padding: 24px;
}

.step-card-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--color-border);
  background: #fafbfc;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

/* === Auth States (Step 1) === */
.auth-state {
  display: none;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 24px 0;
  gap: 16px;
}

.auth-state.visible {
  display: flex;
}

.auth-state .auth-icon {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.auth-state .auth-icon.lock {
  background: var(--color-primary-light);
  color: var(--color-primary);
}

.auth-state .auth-icon.check {
  background: var(--color-success-light);
  color: var(--color-success);
}

.auth-state .auth-icon.error {
  background: var(--color-error-light);
  color: var(--color-error);
}

.auth-state h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

.auth-state p {
  margin: 0;
  color: var(--color-text-secondary);
  font-size: 14px;
}

.auth-state .token-expiry {
  font-size: 13px;
  color: var(--color-text-muted);
}

.auth-state .token-expiry.warning {
  color: var(--color-warning);
}

/* === Buttons === */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.15s ease;
  text-decoration: none;
  line-height: 1.4;
}

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

.btn-primary {
  background: var(--color-primary);
  color: #ffffff;
}

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

.btn-ghost {
  background: transparent;
  color: var(--color-text-secondary);
  border: 1px solid var(--color-border);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--color-bg);
  border-color: var(--color-text-muted);
}

.btn-sm {
  padding: 6px 14px;
  font-size: 13px;
}

.btn-lg {
  padding: 12px 24px;
  font-size: 15px;
}

.btn-danger {
  background: transparent;
  color: var(--color-error);
  border: 1px solid var(--color-error-light);
}

.btn-danger:hover:not(:disabled) {
  background: var(--color-error-light);
}

.btn-link {
  background: none;
  border: none;
  color: var(--color-primary);
  padding: 0;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: underline;
}

.btn-link:hover {
  color: var(--color-primary-hover);
}

/* === Form Elements === */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 14px;
  font-weight: 500;
  color: var(--color-text);
  margin-bottom: 6px;
}

.form-group input,
.form-group textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: var(--font-family);
  color: var(--color-text);
  background: var(--color-surface);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-group input:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--color-border-focus);
  box-shadow: 0 0 0 3px rgba(26, 86, 219, 0.1);
}

.form-group input.error {
  border-color: var(--color-error);
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.1);
}

.form-group .field-error {
  display: none;
  font-size: 13px;
  color: var(--color-error);
  margin-top: 4px;
}

.form-group .field-error.visible {
  display: block;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

/* === Advanced Details === */
details.advanced-section {
  margin-top: 8px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
}

details.advanced-section summary {
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 500;
  color: var(--color-text-secondary);
  cursor: pointer;
  user-select: none;
}

details.advanced-section summary:hover {
  color: var(--color-text);
}

details.advanced-section[open] summary {
  border-bottom: 1px solid var(--color-border);
}

details.advanced-section .details-body {
  padding: 14px;
}

/* === Spinner + Progress Steps === */
.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 20px;
}

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

.progress-steps {
  list-style: none;
  padding: 0;
  margin: 0;
}

.progress-steps li {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 8px 0;
  font-size: 14px;
  color: var(--color-text-muted);
  position: relative;
}

.progress-steps li:not(:last-child)::after {
  content: '';
  position: absolute;
  left: 9px;
  top: 28px;
  bottom: -8px;
  width: 2px;
  background: var(--color-border);
}

.progress-steps li.active {
  color: var(--color-primary);
  font-weight: 500;
}

.progress-steps li.active::after {
  background: var(--color-primary-light);
}

.progress-steps li.completed {
  color: var(--color-success);
}

.progress-steps li.completed::after {
  background: var(--color-success);
}

.progress-steps .step-dot {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--color-border);
  background: var(--color-surface);
}

.progress-steps li.active .step-dot {
  border-color: var(--color-primary);
  background: var(--color-primary-light);
}

.progress-steps li.completed .step-dot {
  border-color: var(--color-success);
  background: var(--color-success);
}

.progress-steps li.completed .step-dot svg {
  color: #ffffff;
}

/* === Certificate Details (success view) === */
.cert-details {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin: 16px 0;
}

.cert-details .detail-row {
  display: flex;
  justify-content: space-between;
  padding: 10px 16px;
  font-size: 14px;
}

.cert-details .detail-row:not(:last-child) {
  border-bottom: 1px solid var(--color-border);
}

.cert-details .detail-label {
  color: var(--color-text-secondary);
  font-weight: 500;
}

.cert-details .detail-value {
  color: var(--color-text);
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 13px;
}

/* === Alerts === */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.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-success {
  background: var(--color-success-light);
  color: #065f46;
  border: 1px solid #a7f3d0;
}

.alert svg {
  flex-shrink: 0;
  margin-top: 1px;
}

/* === Generation States (Step 3) === */
.gen-state {
  display: none;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 24px 0;
  gap: 16px;
}

.gen-state.visible {
  display: flex;
}

.gen-state .success-icon {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--color-success-light);
  color: var(--color-success);
  display: flex;
  align-items: center;
  justify-content: center;
}

.gen-state h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}

.gen-state p {
  margin: 0;
  color: var(--color-text-secondary);
  font-size: 14px;
}

.gen-actions {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 8px;
}

/* === Log Drawer === */
.log-drawer {
  margin-top: 32px;
}

.log-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  background: none;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 8px 14px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text-secondary);
  width: 100%;
  justify-content: center;
  transition: all 0.15s ease;
}

.log-toggle:hover {
  background: var(--color-bg);
  border-color: var(--color-text-muted);
}

.log-badge {
  display: none;
  background: var(--color-primary);
  color: #ffffff;
  font-size: 11px;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 999px;
  min-width: 18px;
  text-align: center;
}

.log-badge.visible {
  display: inline-block;
}

.log-panel {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
  border: 1px solid transparent;
  border-radius: 0 0 var(--radius-md) var(--radius-md);
}

.log-panel.open {
  max-height: 400px;
  border-color: var(--color-border);
  border-top: none;
}

.log-panel-inner {
  padding: 12px;
}

.log-panel pre {
  margin: 0;
  max-height: 280px;
  overflow: auto;
  font-size: 12px;
  line-height: 1.6;
  color: var(--color-text-secondary);
  font-family: 'SF Mono', 'Fira Code', ui-monospace, monospace;
}

.log-panel .log-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 8px;
}

/* === Footer === */
.app-footer {
  text-align: center;
  padding: 16px;
  font-size: 13px;
  color: var(--color-text-muted);
  border-top: 1px solid var(--color-border);
}

/* === Top Bar Right === */
.top-bar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* === Tab Bar === */
.tab-bar {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--color-border);
  margin-bottom: 24px;
}

.tab {
  padding: 10px 20px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  font-size: 14px;
  font-weight: 500;
  color: var(--color-text-muted);
  cursor: pointer;
  transition: all 0.15s ease;
}

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

.tab.active {
  color: var(--color-primary);
  border-bottom-color: var(--color-primary);
  font-weight: 600;
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

/* === Certificate Table === */
.cert-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.cert-table th {
  text-align: left;
  padding: 10px 12px;
  font-weight: 600;
  font-size: 13px;
  color: var(--color-text-secondary);
  border-bottom: 2px solid var(--color-border);
  white-space: nowrap;
}

.cert-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--color-border);
  color: var(--color-text);
}

.cert-table tr:last-child td {
  border-bottom: none;
}

.cert-table td:first-child {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 13px;
}

/* === Status Badges === */
.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

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

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

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

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

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

.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }

/* === Responsive === */
@media (max-width: 600px) {
  .top-bar {
    padding: 0 12px;
  }

  .top-bar .app-title span {
    display: none;
  }

  .container {
    padding: 20px 12px 48px;
  }

  .stepper-header {
    padding: 0 8px;
  }

  .step-label {
    font-size: 11px;
  }

  .step-circle {
    width: 30px;
    height: 30px;
    font-size: 12px;
  }

  .step-connector {
    margin: 0 6px;
    margin-bottom: 24px;
  }

  .form-row {
    grid-template-columns: 1fr;
  }

  .step-card-header,
  .step-card-body,
  .step-card-footer {
    padding-left: 16px;
    padding-right: 16px;
  }

  .cert-details .detail-row {
    flex-direction: column;
    gap: 2px;
  }

  .gen-actions {
    flex-direction: column;
    width: 100%;
  }

  .gen-actions .btn {
    width: 100%;
  }

  .cert-table {
    font-size: 12px;
  }

  .cert-table th,
  .cert-table td {
    padding: 8px 6px;
  }
}
