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

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface-hover: #23273a;
  --border: #2d3148;
  --text: #e1e4ed;
  --text-muted: #8b90a5;
  --primary: #6c72cb;
  --primary-hover: #7f85d8;
  --error: #e05252;
  --success: #4caf82;
  --radius: 8px;
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", "Fira Code", "Cascadia Code", monospace;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

/* Container */
.container {
  max-width: 800px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

/* Login */
.login-container {
  max-width: 400px;
  margin-top: 12vh;
}

.login-container h1 {
  font-size: 1.75rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
}

.subtitle {
  color: var(--text-muted);
  margin-bottom: 2rem;
}

/* Forms */
label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 0.375rem;
  margin-top: 1rem;
}

input[type="text"],
input[type="password"] {
  width: 100%;
  padding: 0.625rem 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.95rem;
  font-family: var(--font);
  outline: none;
  transition: border-color 0.15s;
}

input:focus {
  border-color: var(--primary);
}

button[type="submit"],
button.btn {
  width: 100%;
  padding: 0.625rem 1.25rem;
  margin-top: 1.5rem;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  transition: background 0.15s;
}

button[type="submit"]:hover,
button.btn:hover {
  background: var(--primary-hover);
}

button[type="submit"]:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Alert */
.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.alert-error {
  background: rgba(224, 82, 82, 0.1);
  border: 1px solid rgba(224, 82, 82, 0.3);
  color: var(--error);
}

/* Dashboard header */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

header h1 {
  font-size: 1.5rem;
  font-weight: 700;
}

.logout-form {
  margin: 0;
}

.btn-link {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.85rem;
  cursor: pointer;
  font-family: var(--font);
  padding: 0.375rem 0.75rem;
  border-radius: var(--radius);
  transition: color 0.15s, background 0.15s;
}

.btn-link:hover {
  color: var(--text);
  background: var(--surface);
}

/* Upload section */
.upload-section {
  margin-bottom: 2.5rem;
}

.upload-section h2,
.history-section h2 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 1rem;
}

/* Dropzone */
.dropzone {
  position: relative;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 2.5rem 1.5rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.dropzone:hover,
.dropzone.dragover {
  border-color: var(--primary);
  background: rgba(108, 114, 203, 0.05);
}

.dropzone input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.dropzone-text {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.dropzone-file {
  color: var(--primary);
  font-size: 0.85rem;
  margin-top: 0.5rem;
  font-weight: 500;
  min-height: 1.2em;
}

/* Spinner */
.spinner {
  text-align: center;
  padding: 2rem 0;
}

.spinner p {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-top: 1rem;
}

.spinner-ring {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  margin: 0 auto;
  animation: spin 0.8s linear infinite;
}

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

/* HTMX indicator: hidden by default, shown when request in-flight */
.htmx-indicator {
  display: none;
}

.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator {
  display: block;
}

/* Results */
.result-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-top: 1.5rem;
}

.result-success {
  border-color: rgba(76, 175, 130, 0.3);
}

.result-error {
  border-color: rgba(224, 82, 82, 0.3);
}

.result-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
}

.result-card h3,
.result-header h3 {
  font-size: 0.95rem;
  font-weight: 600;
  margin: 0;
}

.result-duration {
  color: var(--text-muted);
  font-weight: 400;
  font-size: 0.8rem;
  background: var(--surface);
  padding: 0.2rem 0.6rem;
  border-radius: 20px;
}

.result-error p {
  color: var(--error);
  font-size: 0.9rem;
}

/* Analysis cards grid */
.analysis-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.card-wide {
  grid-column: 1 / -1;
}

.card-highlight {
  border-color: rgba(108, 114, 203, 0.3);
  background: rgba(108, 114, 203, 0.05);
}

.card-highlight .card-value {
  color: var(--text);
}

/* Card with icon + body (hero cards) */
.card-icon {
  font-size: 1.25rem;
  flex-shrink: 0;
  display: none;
}

.card-hero {
  display: flex;
  align-items: flex-start;
  padding: 1rem;
  gap: 0.75rem;
}

.card-hero .card-icon {
  display: block;
}

.card-body {
  min-width: 0;
}

.card-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.card-value {
  font-size: 0.9rem;
  line-height: 1.4;
  color: var(--text);
}

.card-value-lg {
  font-size: 1rem;
  font-weight: 500;
}

/* Card with header + fields */
.card-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.625rem 1rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
  font-weight: 600;
}

.card-header-icon {
  font-size: 1rem;
}

.card-badge {
  font-size: 0.65rem;
  font-weight: 500;
  background: rgba(108, 114, 203, 0.15);
  color: var(--primary);
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  margin-left: 0.25rem;
}

.card-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
}

.card-field {
  padding: 0.5rem 1rem;
  border-bottom: 1px solid var(--border);
}

.card-field:last-child,
.card-field:nth-last-child(2):nth-child(odd) {
  border-bottom: none;
}

/* When odd number of fields, last item spans full width */
.card-grid > .card-field:last-child:nth-child(odd) {
  grid-column: 1 / -1;
}

.card-field-label {
  display: block;
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 0.125rem;
}

.card-field-value {
  display: block;
  font-size: 0.85rem;
  line-height: 1.4;
  color: var(--text);
}

/* Responsive: stack on small screens */
@media (max-width: 600px) {
  .analysis-grid {
    grid-template-columns: 1fr;
  }
  .card-wide {
    grid-column: 1;
  }
  .card-grid {
    grid-template-columns: 1fr;
  }
}

.json-output {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  font-family: var(--mono);
  font-size: 0.8rem;
  line-height: 1.5;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 500px;
  overflow-y: auto;
  color: var(--text);
}

/* History */
.history-section {
  border-top: 1px solid var(--border);
  padding-top: 1.5rem;
}

.history-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 0.75rem;
}

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
}

.history-filename {
  font-weight: 500;
  font-size: 0.9rem;
}

.history-meta {
  color: var(--text-muted);
  font-size: 0.8rem;
}

details {
  border-top: 1px solid var(--border);
}

details summary {
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
  color: var(--primary);
  cursor: pointer;
  user-select: none;
}

details summary:hover {
  color: var(--primary-hover);
}

.history-body {
  padding: 0.75rem 1rem 1rem;
}

details .json-output {
  margin: 0;
  border: none;
  border-radius: 0 0 var(--radius) var(--radius);
}
