/**
 * Sayin.ink — Design Tokens & Core Stylesheet
 * Direction: Quiet, minimal, purposeful — Apple Notes inspired.
 */

:root {
  /* Colors */
  --page: #F7F7F5;
  --surface: #FFFFFF;
  --text: #1D1D1F;
  --text-muted: #6E6E73;
  --border: #E5E5E2;
  --accent: #C69A24;
  --accent-hover: #A9821D;
  --success: #237A4B;
  --danger: #B42318;
  --warning-bg: #FFF7DF;

  /* Typography */
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  
  /* Spacing Scale (4px base) */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-6: 24px;
  --space-8: 32px;
  --space-12: 48px;
  --space-16: 64px;

  /* Radii */
  --radius-input: 10px;
  --radius-panel: 14px;
  --radius-pill: 999px;

  /* Max Widths */
  --max-width-content: 1040px;
  --max-width-form: 480px;
  --max-width-admin: 1120px;
  --max-width-hero: 620px;
}

/* CSS Reset & Defaults */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background-color: var(--page);
  color: var(--text);
  font-family: var(--font-family);
  font-size: 16px;
  line-height: 24px;
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a {
  color: var(--text);
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-color: var(--border);
  transition: color 150ms ease, text-decoration-color 150ms ease;
}

a:hover {
  color: var(--text);
  text-decoration-color: var(--text);
}

a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Container */
.site-container {
  width: 100%;
  max-width: var(--max-width-content);
  margin-left: auto;
  margin-right: auto;
  padding-left: var(--space-6);
  padding-right: var(--space-6);
}

/* Header */
.site-header {
  height: 64px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
}

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

.brand-link {
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}

.brand-wordmark {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
}

.header-nav {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

.nav-link {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
}

.nav-link:hover {
  color: var(--text);
}

/* Main Layout */
.site-main {
  flex: 1;
  padding-top: var(--space-12);
  padding-bottom: var(--space-16);
}

/* Hero Section (Landing Page) */
.hero-container {
  display: flex;
  flex-direction: column;
}

.hero-content {
  max-width: var(--max-width-hero);
}

.hero-title {
  font-size: 40px;
  line-height: 48px;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin-bottom: var(--space-4);
}

.hero-lead {
  font-size: 18px;
  line-height: 28px;
  color: var(--text-muted);
  margin-bottom: var(--space-8);
}

.hero-cta-group {
  margin-bottom: var(--space-8);
}

/* Fact Cards */
.facts-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-panel);
  padding: var(--space-4) var(--space-6);
  margin-bottom: var(--space-8);
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-6);
}

.fact-item {
  display: flex;
  flex-direction: column;
}

.fact-label {
  font-size: 12px;
  line-height: 16px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: var(--space-1);
}

.fact-value {
  font-size: 14px;
  line-height: 20px;
  font-weight: 500;
  color: var(--text);
}

.purchase-guidance {
  padding-top: var(--space-4);
}

.guidance-text {
  font-size: 14px;
  line-height: 20px;
  color: var(--text-muted);
}

.link-inline {
  color: var(--text);
  font-weight: 500;
  margin-left: var(--space-2);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 var(--space-6);
  border-radius: var(--radius-input);
  font-family: inherit;
  font-size: 15px;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background-color 150ms ease, border-color 150ms ease, opacity 150ms ease;
  user-select: none;
  white-space: nowrap;
}

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

.btn-primary {
  background-color: var(--text);
  color: #FFFFFF;
  border-color: var(--text);
}

.btn-primary:hover:not(:disabled) {
  background-color: #333336;
  border-color: #333336;
  color: #FFFFFF;
}

.btn-secondary {
  background-color: var(--surface);
  color: var(--text);
  border-color: var(--border);
}

.btn-secondary:hover:not(:disabled) {
  background-color: var(--page);
  border-color: #D1D1CE;
}

.btn-sm {
  min-height: 36px;
  padding: 0 var(--space-3);
  font-size: 13px;
  border-radius: 8px;
}

.btn-block {
  width: 100%;
}

.btn-spinner {
  display: none;
  width: 16px;
  height: 16px;
  margin-left: var(--space-2);
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-radius: 50%;
  border-top-color: #FFFFFF;
  animation: spin 700ms linear infinite;
}

.btn.loading .btn-spinner {
  display: inline-block;
}

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

/* Forms */
.download-container, .admin-login-container {
  display: flex;
  justify-content: center;
}

.download-card, .login-card {
  width: 100%;
  max-width: var(--max-width-form);
}

.page-title {
  font-size: 32px;
  line-height: 40px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin-bottom: var(--space-2);
}

.page-subtitle {
  font-size: 16px;
  line-height: 24px;
  color: var(--text-muted);
  margin-bottom: var(--space-8);
}

.form-group {
  margin-bottom: var(--space-6);
  display: flex;
  flex-direction: column;
}

.form-label {
  font-size: 14px;
  line-height: 20px;
  font-weight: 500;
  margin-bottom: var(--space-2);
}

.form-input {
  min-height: 48px;
  padding: 0 var(--space-4);
  font-family: inherit;
  font-size: 15px;
  color: var(--text);
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-input);
  transition: border-color 150ms ease;
  width: 100%;
}

.form-input:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 1px var(--accent);
}

.form-input-sm {
  min-height: 36px;
  padding: 0 var(--space-3);
  font-size: 13px;
  border-radius: 8px;
}

.code-input {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  letter-spacing: 0.05em;
  font-weight: 500;
}

.form-hint {
  font-size: 13px;
  line-height: 18px;
  color: var(--text-muted);
  margin-top: var(--space-2);
}

.form-feedback {
  font-size: 14px;
  line-height: 20px;
  margin-top: var(--space-2);
  min-height: 20px;
}

.form-feedback.error {
  color: var(--danger);
}

.form-feedback.success {
  color: var(--success);
}

.download-footer-help {
  margin-top: var(--space-8);
  padding-top: var(--space-6);
  border-top: 1px solid var(--border);
}

.help-text {
  font-size: 14px;
  color: var(--text-muted);
}

/* Success State View */
.download-success-view {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-panel);
  padding: var(--space-8);
  text-align: left;
}

.success-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #E8F5E9;
  color: var(--success);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 600;
  margin-bottom: var(--space-4);
}

.success-title {
  font-size: 20px;
  line-height: 28px;
  font-weight: 600;
  margin-bottom: var(--space-2);
}

.success-desc {
  font-size: 15px;
  line-height: 22px;
  color: var(--text-muted);
  margin-bottom: var(--space-6);
}

.success-actions {
  margin-top: var(--space-6);
  margin-bottom: var(--space-4);
}

.success-hint {
  margin-top: 0;
}

/* Admin Styles */
.admin-container {
  max-width: var(--max-width-admin);
}

.admin-header .admin-user-nav {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

.admin-user-badge {
  font-size: 13px;
  color: var(--text-muted);
}

.dashboard-header {
  margin-bottom: var(--space-8);
}

/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-8);
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-panel);
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
}

.stat-num {
  font-size: 28px;
  line-height: 32px;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin-bottom: var(--space-1);
}

.stat-active {
  color: var(--accent);
}

.stat-label {
  font-size: 13px;
  color: var(--text-muted);
}

/* Panels */
.admin-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-panel);
  padding: var(--space-6);
  margin-bottom: var(--space-8);
}

.panel-title {
  font-size: 18px;
  line-height: 24px;
  font-weight: 600;
  margin-bottom: var(--space-4);
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-4);
}

.generate-actions {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  margin-top: var(--space-2);
}

.inline-feedback {
  margin-top: 0;
}

/* Code Reveal Box */
.code-reveal-panel {
  background: var(--warning-bg);
  border: 1px solid #EAD8A2;
  border-radius: var(--radius-panel);
  padding: var(--space-6);
  margin-bottom: var(--space-8);
}

.reveal-header {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-1);
}

.reveal-title {
  font-size: 18px;
  line-height: 24px;
  font-weight: 600;
}

.reveal-badge {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  background: #C69A24;
  color: #FFFFFF;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
}

.reveal-note {
  font-size: 14px;
  color: #6C5512;
  margin-bottom: var(--space-4);
}

.reveal-code-box {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  background: #FFFFFF;
  border: 1px solid #D8C287;
  border-radius: var(--radius-input);
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-3);
}

.revealed-code-text {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--text);
  flex: 1;
}

.reveal-meta {
  font-size: 13px;
  color: #6C5512;
  display: flex;
  gap: var(--space-6);
}

/* Table Controls */
.table-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-4);
  flex-wrap: wrap;
  gap: var(--space-4);
}

.filter-controls {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.search-box {
  width: 220px;
}

.filter-select {
  width: 140px;
}

/* Table */
.table-wrapper {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.codes-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  text-align: left;
}

.codes-table th, .codes-table td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.codes-table th {
  background-color: #FAFAFA;
  color: var(--text-muted);
  font-weight: 500;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

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

.codes-table tr:hover td {
  background-color: #FAFAFA;
}

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

.td-actions {
  text-align: right;
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
}

.td-empty {
  text-align: center;
  color: var(--text-muted);
  padding: var(--space-8) !important;
}

/* Status Badges */
.status-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  font-size: 12px;
  font-weight: 500;
  text-transform: capitalize;
}

.status-active {
  background-color: #E8F5E9;
  color: var(--success);
}

.status-redeemed {
  background-color: #E3F2FD;
  color: #1565C0;
}

.status-expired {
  background-color: #F5F5F5;
  color: var(--text-muted);
}

.status-revoked {
  background-color: #FFEBEE;
  color: var(--danger);
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  z-index: 100;
}

.modal-card {
  background: var(--surface);
  border-radius: var(--radius-panel);
  width: 100%;
  max-width: 540px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
}

.modal-header {
  padding: var(--space-4) var(--space-6);
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-title {
  font-size: 16px;
  font-weight: 600;
}

.modal-content {
  padding: var(--space-6);
  overflow-y: auto;
}

.audit-item {
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  font-size: 13px;
}

.audit-item:last-child {
  border-bottom: none;
}

.audit-type {
  font-weight: 500;
  color: var(--text);
}

.audit-time {
  color: var(--text-muted);
}

/* Footer */
.site-footer {
  border-top: 1px solid var(--border);
  padding: var(--space-6) 0;
  margin-top: auto;
}

.footer-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  color: var(--text-muted);
}

.footer-link {
  color: var(--text-muted);
  text-decoration: none;
}

.footer-link:hover {
  color: var(--text);
  text-decoration: underline;
}

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

/* Responsive Rules */
@media (max-width: 600px) {
  .site-container {
    padding-left: var(--space-4);
    padding-right: var(--space-4);
  }

  .site-main {
    padding-top: var(--space-8);
    padding-bottom: var(--space-8);
  }

  .hero-title {
    font-size: 32px;
    line-height: 40px;
  }

  .page-title {
    font-size: 28px;
    line-height: 36px;
  }

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

  .footer-inner {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-2);
  }

  .filter-controls {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
  }

  .search-box, .filter-select {
    width: 100%;
  }

  .reveal-code-box {
    flex-direction: column;
    align-items: stretch;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Editorial Landing Page Enhancements */
.hero-eyebrow {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
  margin-bottom: var(--space-3);
}

.editorial-section {
  margin-top: var(--space-16);
  padding-top: var(--space-8);
  border-top: 1px solid var(--border);
}

.section-title {
  font-size: 24px;
  line-height: 32px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin-bottom: var(--space-2);
}

.section-desc {
  font-size: 16px;
  line-height: 24px;
  color: var(--text-muted);
  max-width: var(--max-width-hero);
  margin-bottom: var(--space-8);
}

/* Steps Grid */
.steps-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-6);
  margin-bottom: var(--space-4);
}

.step-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-panel);
  padding: var(--space-6);
  display: flex;
  flex-direction: column;
}

.step-num {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--page);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: var(--space-4);
}

.step-title {
  font-size: 16px;
  line-height: 24px;
  font-weight: 600;
  margin-bottom: var(--space-2);
}

.step-text {
  font-size: 14px;
  line-height: 22px;
  color: var(--text-muted);
}

.kbd-pill {
  font-family: var(--font-family);
  font-size: 13px;
  padding: 2px 6px;
  border-radius: 6px;
  background: var(--page);
  border: 1px solid var(--border);
  box-shadow: 0 1px 0 var(--border);
  font-weight: 600;
  white-space: nowrap;
}

/* Features Grid */
.features-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-6);
}

.feature-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-panel);
  padding: var(--space-6);
}

.feature-title {
  font-size: 16px;
  line-height: 24px;
  font-weight: 600;
  margin-bottom: var(--space-2);
}

.feature-text {
  font-size: 14px;
  line-height: 22px;
  color: var(--text-muted);
}

/* Comparison Table */
.comparison-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-panel);
  background: var(--surface);
  margin-bottom: var(--space-6);
}

.comparison-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  text-align: left;
}

.comparison-table th, .comparison-table td {
  padding: var(--space-4) var(--space-6);
  border-bottom: 1px solid var(--border);
}

.comparison-table th {
  background: #FAFAFA;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
}

.th-highlight, .td-highlight {
  background: #FCFCF9;
  font-weight: 600;
  color: var(--text);
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
}

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

/* Specs & Permissions */
.specs-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-panel);
  padding: var(--space-6);
}

.specs-list {
  list-style: disc;
  padding-left: var(--space-6);
  font-size: 14px;
  line-height: 24px;
  color: var(--text-muted);
}

.specs-list li {
  margin-bottom: var(--space-2);
}

.specs-list strong {
  color: var(--text);
}

/* Final CTA Section */
.final-cta-section {
  margin-top: var(--space-16);
  padding-top: var(--space-12);
  border-top: 1px solid var(--border);
  text-align: left;
}

.final-cta-title {
  font-size: 24px;
  line-height: 32px;
  font-weight: 600;
  margin-bottom: var(--space-2);
}

.final-cta-subtitle {
  font-size: 15px;
  color: var(--text-muted);
  margin-bottom: var(--space-6);
}

/* Mobile Responsiveness for New Sections */
@media (max-width: 800px) {
  .steps-grid {
    grid-template-columns: 1fr;
  }

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

  .comparison-table th, .comparison-table td {
    padding: var(--space-3) var(--space-4);
    font-size: 13px;
  }
}
