:root {
  --bg: #F4F6F8;
  --surface: #FFFFFF;
  --ink: #0F172A;
  --muted: #475569;
  --line: #DCE2E9;
  --accent: #1D4ED8;
  --accent-ink: #FFFFFF;
  --mark: #F59E0B;
  --ok: #15803D;
  --warn: #B45309;
  --radius: 12px;
  --radius-sm: 8px;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

[hidden] {
  display: none !important;
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg);
  color: var(--ink);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
.site-header {
  background-color: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 16px 24px;
}

.header-content {
  max-width: 1120px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.wordmark {
  font-size: 20px;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -0.01em;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 9999px;
  font-size: 12px;
  font-weight: 500;
  background-color: var(--bg);
  color: var(--muted);
  border: 1px solid var(--line);
}

/* Main */
.main-content {
  flex: 1;
  max-width: 1120px;
  width: 100%;
  margin: 0 auto;
  padding: 24px 24px;
}

/* Hero Section with Blueprint Grid */
.hero-section {
  position: relative;
  border-radius: var(--radius);
  padding: 40px 24px;
  margin-bottom: 24px;
  background-color: var(--surface);
  border: 1px solid var(--line);
  background-image:
    linear-gradient(to right, rgba(15, 23, 42, 0.05) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(15, 23, 42, 0.05) 1px, transparent 1px);
  background-size: 24px 24px;
  text-align: center;
}

.hero-section.is-compact {
  padding: 12px 20px;
  margin-bottom: 20px;
  text-align: left;
}

.hero-section.is-compact .hero-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.hero-section.is-compact .hero-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 0;
}

.hero-section.is-compact .hero-subtitle {
  display: none;
}

.hero-title {
  font-size: clamp(28px, 4vw, 44px);
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--ink);
  margin-bottom: 12px;
  line-height: 1.2;
}

.hero-subtitle {
  font-size: 16px;
  color: var(--muted);
  max-width: 680px;
  margin: 0 auto 32px;
}

/* Drop Zone */
.drop-zone {
  max-width: 560px;
  margin: 0 auto;
  padding: 36px 24px;
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  background-color: var(--surface);
  transition: border-color 0.15s ease, background-color 0.15s ease;
  cursor: pointer;
}

.drop-zone.dragover {
  border-color: var(--accent);
  background-color: #EEF3FF;
}

.drop-zone-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.drop-icon {
  color: var(--muted);
}

.drop-text {
  font-size: 15px;
  color: var(--muted);
}

.sample-link-wrapper {
  margin-top: 4px;
}

.sample-link {
  font-size: 14px;
  color: var(--accent);
  text-decoration: underline;
  cursor: pointer;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}

.sample-link:hover {
  color: #1E40AF;
}

/* Loading Status */
.loading-status {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 24px;
  padding: 16px;
  border-radius: var(--radius-sm);
  background-color: var(--surface);
  border: 1px solid var(--line);
  font-size: 15px;
  color: var(--ink);
}

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Cards & Sections */
.card {
  background-color: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 24px;
  min-width: 0;
  max-width: 100%;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  gap: 12px;
  flex-wrap: wrap;
}

.card-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--ink);
  min-width: 0;
  overflow-wrap: break-word;
}

.card-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.copy-status {
  font-size: 13px;
  font-weight: 500;
  color: var(--ok);
}

.copy-status:empty {
  /* Keep live region mounted in accessibility tree without adding flex gap when empty. */
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  margin: 0;
}

.copy-status.is-error {
  color: var(--warn);
}

.section-block {
  margin-bottom: 32px;
}

.section-title {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 16px;
  color: var(--ink);
}

/* Summary Strip */
.summary-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.summary-item {
  background-color: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.summary-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.summary-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

/* Tables */
.table-wrap {
  overflow-x: auto;
  overflow-y: auto;
  max-height: 65vh;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  -webkit-overflow-scrolling: touch;
}

.data-table {
  width: max-content;
  min-width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 14px;
  text-align: left;
  font-variant-numeric: tabular-nums;
}

.data-table th,
.data-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
  white-space: normal;
  overflow-wrap: break-word;
  max-width: 28ch;
}

.data-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background-color: var(--bg);
  font-weight: 600;
  color: var(--muted);
  box-shadow: inset 0 -1px 0 var(--line);
}

.data-table tbody tr {
  cursor: pointer;
  transition: background-color 0.1s ease;
}

.data-table tbody tr:hover {
  background-color: #F8FAFC;
}

.data-table tbody tr:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  background-color: #EEF3FF;
}

.data-table tfoot td {
  font-weight: 600;
  background-color: var(--bg);
}

/* Sheets List */
.sheets-list {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}

.sheets-list-item {
  padding: 12px 16px;
  background-color: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sheet-item-number {
  font-weight: 700;
  color: var(--ink);
  font-size: 14px;
}

.sheet-item-title {
  font-size: 13px;
  color: var(--muted);
}

/* Feedback */
.feedback-card {
  text-align: center;
  padding: 24px;
}

.feedback-question {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 12px;
}

.feedback-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
}

.feedback-comment-block {
  margin-top: 16px;
  max-width: 480px;
  margin-left: auto;
  margin-right: auto;
  text-align: left;
}

.feedback-label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 6px;
}

.comment-row {
  display: flex;
  gap: 8px;
}

.feedback-input {
  flex: 1;
  min-width: 0;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: 14px;
  min-height: 44px;
}

.feedback-thanks {
  font-size: 15px;
  font-weight: 500;
  color: var(--ok);
  padding: 8px;
}

/* States */
.state-card {
  max-width: 560px;
  margin: 24px auto 0;
  padding: 24px;
  background-color: var(--surface);
  border: 1px solid var(--warn);
  border-radius: var(--radius);
  text-align: center;
}

.state-empty {
  border-color: var(--line);
  text-align: left;
}

.state-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 8px;
}

.state-text {
  font-size: 15px;
  color: var(--ink);
  margin-bottom: 16px;
}

.state-contact {
  font-size: 14px;
  color: var(--muted);
  margin-bottom: 16px;
}

.results-footer-actions {
  margin-top: 32px;
  text-align: center;
}

/* Preview Modal */
.preview-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.preview-backdrop {
  position: absolute;
  inset: 0;
  background-color: rgba(15, 23, 42, 0.6);
}

.preview-content {
  position: relative;
  z-index: 101;
  max-width: 960px;
  width: 100%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  margin-bottom: 0;
}

.preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.preview-body {
  flex: 1;
  overflow: auto;
  background-color: var(--bg);
  border-radius: var(--radius-sm);
  padding: 16px;
}

.preview-status {
  margin-top: 0;
}

.preview-status.is-error {
  border-color: var(--warn);
}

#previewCanvas {
  display: block;
  margin: 0 auto;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: inherit;
  font-weight: 500;
  font-size: 14px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  min-height: 44px;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.btn-primary {
  background-color: var(--accent);
  color: var(--accent-ink);
}

.btn-primary:hover {
  background-color: #1E40AF;
}

.btn-secondary {
  background-color: var(--surface);
  color: var(--ink);
  border-color: var(--line);
}

.btn-secondary:hover {
  background-color: var(--bg);
}

.btn-outline {
  background-color: transparent;
  color: var(--ink);
  border-color: var(--line);
}

.btn-outline:hover {
  background-color: var(--bg);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 13px;
  min-height: 44px;
}

.btn:focus-visible,
input:focus-visible,
a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* Footer */
.site-footer {
  margin-top: auto;
  background-color: var(--surface);
  border-top: 1px solid var(--line);
  padding: 24px;
}

.footer-content {
  max-width: 1120px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.footer-note {
  font-size: 14px;
  color: var(--muted);
}

.footer-links {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.footer-link {
  color: var(--accent);
  text-decoration: underline;
}

/* Mobile Responsive */
@media (max-width: 600px) {
  .site-header {
    padding: 12px 16px;
  }
  .main-content {
    padding: 20px 16px;
  }
  .hero-section {
    padding: 28px 16px;
  }
  .hero-section.is-compact {
    padding: 12px 16px;
  }
  .summary-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
  }
  .summary-item {
    padding: 12px 14px;
  }
  .summary-value {
    font-size: 20px;
  }
  .card {
    padding: 16px;
  }
  .sheets-list {
    grid-template-columns: 1fr;
  }
  .footer-content {
    flex-direction: column;
    align-items: flex-start;
  }
}
