/* ================================================================
   ClerkCheck — Styles
   Premium legal-tech aesthetic: serif gravitas + modern precision
   ================================================================ */

/* ── Custom Properties ─────────────────────────────────────────── */
:root {
  /* Palette */
  --bg:             #f5f3ed;
  --bg-warm:        #eceae3;
  --surface:        #ffffff;
  --surface-hover:  #fafaf8;

  --navy-950:       #070e1a;
  --navy-900:       #0b1426;
  --navy-800:       #111d33;
  --navy-700:       #182842;
  --navy-600:       #1f3354;
  --navy-500:       #2a4470;

  --gold-700:       #7d6323;
  --gold-600:       #9a7a2e;
  --gold-500:       #b8923e;
  --gold-400:       #cba452;
  --gold-300:       #ddb866;
  --gold-200:       #eedfa8;
  --gold-100:       #f7efd5;
  --gold-50:        #fcf8ec;

  --text-1:         #1a1a1a;
  --text-2:         #52524e;
  --text-3:         #8a8a85;

  --border:         #dfdcd4;
  --border-strong:  #ccc9c0;

  --red-600:        #b83a2e;
  --red-100:        #fce8e6;
  --green-600:      #2d6a4f;
  --green-100:      #dff5e8;

  /* Typography */
  --font-display:   'Cormorant Garamond', 'Georgia', serif;
  --font-body:      'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

  /* Spacing */
  --space-xs:  4px;
  --space-sm:  8px;
  --space-md:  16px;
  --space-lg:  24px;
  --space-xl:  32px;
  --space-2xl: 48px;
  --space-3xl: 64px;

  /* Radius */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;

  /* Shadows */
  --shadow-sm:  0 1px 2px rgba(11, 20, 38, 0.04), 0 1px 4px rgba(11, 20, 38, 0.03);
  --shadow-md:  0 2px 6px rgba(11, 20, 38, 0.05), 0 4px 12px rgba(11, 20, 38, 0.04);
  --shadow-lg:  0 4px 12px rgba(11, 20, 38, 0.06), 0 8px 24px rgba(11, 20, 38, 0.05);
  --shadow-gold: 0 0 0 3px rgba(184, 146, 62, 0.15);

  /* Transitions */
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --duration: 0.2s;
}

/* ── Reset ─────────────────────────────────────────────────────── */
[hidden] { display: none !important; }
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

body {
  font-family: var(--font-body);
  font-weight: 400;
  color: var(--text-1);
  background: var(--bg);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

img, svg { display: block; max-width: 100%; }
button { cursor: pointer; border: none; background: none; font: inherit; color: inherit; }
input, textarea, select { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
ol, ul { list-style: none; }

/* ── Background Grid ───────────────────────────────────────────── */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(184, 146, 62, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(184, 146, 62, 0.025) 1px, transparent 1px);
  background-size: 48px 48px;
  pointer-events: none;
  z-index: 0;
}

/* ── Layout ────────────────────────────────────────────────────── */
.container {
  max-width: 1120px;
  margin: 0 auto;
  padding-left: var(--space-lg);
  padding-right: var(--space-lg);
}

/* ── Top Rule ──────────────────────────────────────────────────── */
.top-rule {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--gold-700), var(--gold-400), var(--gold-700));
  z-index: 100;
}

/* ── Header ────────────────────────────────────────────────────── */
.header {
  position: sticky;
  top: 3px;
  z-index: 50;
  background: rgba(245, 243, 237, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

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

.logo {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  text-decoration: none;
}

.logo-symbol {
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 600;
  color: var(--gold-500);
  line-height: 1;
}

.logo-name {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 600;
  color: var(--navy-900);
  letter-spacing: -0.01em;
}

.header-tagline {
  font-size: 13px;
  font-weight: 400;
  color: var(--text-3);
  letter-spacing: 0.02em;
}

/* ── Intro ─────────────────────────────────────────────────────── */
.intro {
  padding: var(--space-3xl) 0 var(--space-xl);
  text-align: center;
  animation: fadeUp 0.6s var(--ease-out) both;
}

.intro-title {
  font-family: var(--font-display);
  font-size: clamp(28px, 4vw, 42px);
  font-weight: 500;
  color: var(--navy-900);
  line-height: 1.2;
  letter-spacing: -0.01em;
  margin-bottom: var(--space-md);
  overflow-wrap: break-word;
}

.intro-title em {
  font-style: italic;
  color: var(--gold-600);
}

.intro-desc {
  font-size: 16px;
  color: var(--text-2);
  max-width: 560px;
  margin: 0 auto;
  line-height: 1.65;
}

/* ── App Grid ──────────────────────────────────────────────────── */
.app-grid {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: var(--space-lg);
  align-items: start;
  padding-bottom: var(--space-3xl);
  animation: fadeUp 0.6s var(--ease-out) 0.1s both;
}

.workflow {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

/* ── Card ──────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  position: relative;
  z-index: 1;
}

/* ── Upload Zone ───────────────────────────────────────────────── */
.upload-card {
  overflow: hidden;
}

.upload-zone {
  padding: var(--space-2xl) var(--space-xl);
  text-align: center;
  border: 2px dashed var(--border);
  border-radius: var(--radius-md);
  margin: var(--space-md);
  transition:
    border-color var(--duration) var(--ease-out),
    background var(--duration) var(--ease-out),
    box-shadow var(--duration) var(--ease-out);
  outline: none;
}

.upload-zone:hover,
.upload-zone:focus-visible {
  border-color: var(--gold-400);
  background: var(--gold-50);
}

.upload-zone:focus-visible {
  box-shadow: var(--shadow-gold);
}

.upload-zone.drag-over {
  border-color: var(--gold-500);
  border-style: solid;
  background: var(--gold-50);
  box-shadow: var(--shadow-gold);
}

.upload-zone.has-file {
  border-style: solid;
  border-color: var(--border-strong);
  padding: var(--space-lg);
}

.upload-icon {
  color: var(--navy-700);
  margin: 0 auto var(--space-md);
  transition: transform 0.3s var(--ease-out);
}

.upload-zone:hover .upload-icon,
.upload-zone.drag-over .upload-icon {
  transform: translateY(-3px);
}

.upload-title {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 500;
  color: var(--navy-800);
  margin-bottom: var(--space-xs);
}

.upload-sub {
  font-size: 14px;
  color: var(--text-2);
  margin-bottom: var(--space-sm);
}

.upload-browse {
  color: var(--gold-600);
  font-weight: 500;
  text-decoration: underline;
  text-decoration-color: rgba(184, 146, 62, 0.3);
  text-underline-offset: 2px;
  transition: text-decoration-color var(--duration);
}

.upload-browse:hover {
  text-decoration-color: var(--gold-500);
}

.upload-hint {
  font-size: 12px;
  color: var(--text-3);
  letter-spacing: 0.02em;
}

/* File selected state */
.upload-selected {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  text-align: left;
}

.file-badge {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  background: var(--gold-50);
  border: 1px solid var(--gold-200);
  border-radius: var(--radius-sm);
  color: var(--gold-600);
}

.file-meta {
  flex: 1;
  min-width: 0;
}

.file-name {
  font-weight: 500;
  font-size: 14px;
  color: var(--text-1);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-size {
  font-size: 12px;
  color: var(--text-3);
  margin-top: 1px;
}

.file-remove {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-sm);
  color: var(--text-3);
  transition: color var(--duration), background var(--duration);
}

.file-remove:hover {
  color: var(--red-600);
  background: var(--red-100);
}

/* ── Options Panel ─────────────────────────────────────────────── */
.options-card {
  overflow: hidden;
}

.options-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: var(--space-md) var(--space-lg);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
  letter-spacing: 0.02em;
  text-transform: uppercase;
  transition: color var(--duration);
}

.options-toggle:hover {
  color: var(--text-1);
}

.chevron-icon {
  transition: transform 0.3s var(--ease-out);
}

.options-toggle[aria-expanded="true"] .chevron-icon {
  transform: rotate(180deg);
}

.options-body {
  padding: 0 var(--space-lg) var(--space-lg);
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.field label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-1);
  margin-bottom: var(--space-xs);
}

.field textarea {
  width: 100%;
  padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 14px;
  line-height: 1.5;
  resize: vertical;
  transition: border-color var(--duration), box-shadow var(--duration);
}

.field textarea:focus {
  outline: none;
  border-color: var(--gold-400);
  box-shadow: var(--shadow-gold);
}

.field textarea::placeholder {
  color: var(--text-3);
}

.field-help {
  font-size: 12px;
  color: var(--text-3);
  margin-top: var(--space-xs);
  line-height: 1.5;
}

.field-help em {
  font-style: italic;
}

/* ── Controls Row ──────────────────────────────────────────────── */
.controls-row {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  flex-wrap: wrap;
}

.style-group {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  flex-shrink: 0;
}

.style-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
}

.style-toggle {
  position: relative;
  display: flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 3px;
}

.style-opt {
  position: relative;
  z-index: 1;
  padding: 6px 16px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
  border-radius: 4px;
  transition: color var(--duration);
}

.style-opt.active {
  color: var(--navy-900);
}

.style-slider {
  position: absolute;
  top: 3px;
  left: 3px;
  width: calc(50% - 3px);
  height: calc(100% - 6px);
  background: var(--gold-100);
  border: 1px solid var(--gold-200);
  border-radius: 4px;
  transition: transform 0.3s var(--ease-out);
}

.style-toggle[data-active="california"] .style-slider {
  transform: translateX(100%);
}

/* ── Generate Button ───────────────────────────────────────────── */
.btn-generate {
  flex: 1;
  min-width: 180px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  background: var(--navy-800);
  color: #fff;
  font-weight: 600;
  font-size: 15px;
  letter-spacing: 0.01em;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
  transition:
    background var(--duration),
    box-shadow var(--duration),
    opacity var(--duration),
    transform 0.1s;
}

.btn-generate:hover:not(:disabled) {
  background: var(--navy-700);
  box-shadow: var(--shadow-md);
}

.btn-generate:active:not(:disabled) {
  transform: scale(0.985);
}

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

.btn-generate.loading {
  opacity: 0.85;
  cursor: wait;
}

.btn-loader {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

/* Dot pulse loader */
.dot-pulse {
  display: inline-flex;
  gap: 4px;
}

.dot-pulse::before,
.dot-pulse::after,
.dot-pulse span {
  content: '';
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #fff;
  animation: dotPulse 1.2s ease-in-out infinite;
}

.dot-pulse::before { animation-delay: 0s; }
.dot-pulse span    { animation-delay: 0.15s; }
.dot-pulse::after  { animation-delay: 0.3s; }

@keyframes dotPulse {
  0%, 80%, 100% { opacity: 0.25; transform: scale(0.8); }
  40% { opacity: 1; transform: scale(1); }
}

/* ── Error Banner ──────────────────────────────────────────────── */
.error-banner {
  display: flex;
  align-items: flex-start;
  gap: var(--space-sm);
  padding: var(--space-md) var(--space-lg);
  background: var(--red-100);
  border: 1px solid rgba(184, 58, 46, 0.15);
  border-radius: var(--radius-md);
  animation: fadeUp 0.3s var(--ease-out);
}

.error-icon {
  flex-shrink: 0;
  color: var(--red-600);
  margin-top: 1px;
}

.error-text {
  flex: 1;
  font-size: 14px;
  color: var(--red-600);
  line-height: 1.5;
}

.error-dismiss {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 4px;
  color: var(--red-600);
  opacity: 0.6;
  transition: opacity var(--duration);
}

.error-dismiss:hover { opacity: 1; }

/* ── Result Card ───────────────────────────────────────────────── */
.result-card {
  border-left: 3px solid var(--gold-500);
  animation: slideIn 0.4s var(--ease-out);
}

.result-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md) var(--space-lg);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  gap: var(--space-sm);
}

.form-badge {
  display: inline-flex;
  align-items: center;
  height: 24px;
  padding: 0 10px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--gold-700);
  background: var(--gold-100);
  border: 1px solid var(--gold-200);
  border-radius: 999px;
}

.result-actions {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.form-select {
  height: 32px;
  padding: 0 var(--space-sm);
  padding-right: 28px;
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='12' height='12' viewBox='0 0 12 12' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M3 4.5l3 3 3-3' stroke='%238a8a85' stroke-width='1.2' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  transition: border-color var(--duration);
}

.form-select:focus {
  outline: none;
  border-color: var(--gold-400);
  box-shadow: var(--shadow-gold);
}

.btn-copy {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 32px;
  padding: 0 12px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  transition: border-color var(--duration), color var(--duration), background var(--duration);
}

.btn-copy:hover {
  border-color: var(--border-strong);
  color: var(--text-1);
}

.btn-copy.copied {
  color: var(--green-600);
  border-color: rgba(45, 106, 79, 0.25);
  background: var(--green-100);
}

.copy-label { pointer-events: none; }

/* Citation Display */
.citation-display {
  padding: var(--space-lg);
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 400;
  line-height: 1.65;
  color: var(--navy-900);
  border: none;
  margin: 0;
  user-select: text;
}

.citation-display i {
  font-style: italic;
}

/* Metadata Details */
.meta-details {
  border-top: 1px solid var(--border);
}

.meta-details summary {
  padding: var(--space-md) var(--space-lg);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-3);
  letter-spacing: 0.03em;
  text-transform: uppercase;
  cursor: pointer;
  user-select: none;
  transition: color var(--duration);
}

.meta-details summary:hover {
  color: var(--text-2);
}

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

.meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: var(--space-sm) var(--space-lg);
  padding: var(--space-md) var(--space-lg);
}

.meta-item {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.meta-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-3);
}

.meta-value {
  font-size: 14px;
  color: var(--text-1);
  word-break: break-word;
}

.meta-value .ai-tag {
  display: inline-flex;
  align-items: center;
  height: 15px;
  padding: 0 4px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--gold-600);
  background: var(--gold-100);
  border-radius: 3px;
  margin-left: 4px;
  vertical-align: middle;
}

/* ── Sidebar ───────────────────────────────────────────────────── */
.sidebar {
  position: sticky;
  top: calc(3px + 56px + var(--space-lg));
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  animation: fadeUp 0.6s var(--ease-out) 0.2s both;
  z-index: 1;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md) var(--space-lg);
  border-bottom: 1px solid var(--border);
}

.sidebar-title {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 600;
  color: var(--navy-800);
}

.sidebar-clear {
  font-size: 12px;
  color: var(--text-3);
  padding: 4px 8px;
  border-radius: 4px;
  transition: color var(--duration), background var(--duration);
}

.sidebar-clear:hover {
  color: var(--red-600);
  background: var(--red-100);
}

.history-list {
  max-height: 60vh;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.history-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-2xl) var(--space-lg);
  text-align: center;
  font-size: 13px;
  color: var(--text-3);
}

.history-item {
  padding: var(--space-md) var(--space-lg);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background var(--duration);
}

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

.history-item:hover {
  background: var(--surface-hover);
}

.history-item.active {
  background: var(--gold-50);
  border-left: 2px solid var(--gold-500);
  padding-left: calc(var(--space-lg) - 2px);
}

.history-citation {
  font-family: var(--font-display);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-1);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.history-citation i { font-style: italic; }

.history-meta {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  margin-top: var(--space-xs);
  font-size: 11px;
  color: var(--text-3);
}

.history-kind {
  text-transform: capitalize;
}

.history-dot {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--border-strong);
}

/* ── Footer ────────────────────────────────────────────────────── */
.footer {
  margin-top: auto;
  border-top: 1px solid var(--border);
  background: var(--bg-warm);
  position: relative;
  z-index: 1;
}

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

.footer-links a {
  color: var(--text-3);
  transition: color var(--duration);
}

.footer-links a:hover {
  color: var(--gold-600);
}

/* ── Animations ────────────────────────────────────────────────── */
@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

/* ── Responsive ────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .app-grid {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
  }

  .history-list {
    max-height: 300px;
  }

  .header-tagline {
    display: none;
  }
}

@media (max-width: 600px) {
  .container {
    padding-left: var(--space-md);
    padding-right: var(--space-md);
  }

  .intro {
    padding: var(--space-2xl) 0 var(--space-lg);
  }

  .intro {
    padding: var(--space-xl) 0 var(--space-md);
  }

  .intro-title {
    font-size: 20px;
  }

  .controls-row {
    flex-direction: column;
    align-items: stretch;
  }

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

  .btn-generate {
    width: 100%;
  }

  .result-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .citation-display {
    font-size: 16px;
    padding: var(--space-md);
  }

  .upload-zone {
    padding: var(--space-xl) var(--space-md);
    margin: var(--space-sm);
  }

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

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

:focus-visible {
  outline: 2px solid var(--gold-500);
  outline-offset: 2px;
}

/* Scrollbar styling */
.history-list::-webkit-scrollbar {
  width: 4px;
}

.history-list::-webkit-scrollbar-track {
  background: transparent;
}

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

.history-list::-webkit-scrollbar-thumb:hover {
  background: var(--border-strong);
}
