/* -------------------------------------------------------------------------- */
/* Restaurant Profit Dashboard — layout, tokens, responsive cards            */
/* -------------------------------------------------------------------------- */

:root {
  color-scheme: light;
  --bg: #eef1f6;
  --surface: #ffffff;
  --text: #141824;
  --muted: #5b6478;
  --border: #d9dee8;
  --shadow: 0 8px 24px rgba(20, 24, 36, 0.06);
  --radius: 14px;
  --radius-sm: 10px;
  --accent: #1f4fa3;
  --accent-soft: #e8eef9;
  --profit: #0f6a45;
  --profit-bg: #e6f4ed;
  --loss: #9b1c1c;
  --loss-bg: #fde8e8;
  --warn: #7a4e00;
  --warn-bg: #fff4d6;
  --danger: #b42318;
  --focus: #2563eb;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, Cantarell, "Noto Sans", Arial, sans-serif;
  --max: 1120px;
}

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

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: auto;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

.skip-link:focus {
  left: 16px;
  top: 16px;
  width: auto;
  height: auto;
  padding: 10px 14px;
  background: var(--surface);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  z-index: 1000;
  outline: 2px solid var(--focus);
}

.wrap {
  width: min(100% - 32px, var(--max));
  margin-inline: auto;
}

.site-header {
  padding: 28px 0 8px;
}

.site-header h1 {
  margin: 0 0 12px;
  font-size: clamp(1.65rem, 4vw, 2.1rem);
  line-height: 1.2;
  letter-spacing: -0.02em;
}

.lead {
  margin: 0;
  max-width: 70ch;
  color: var(--muted);
  font-size: 1.05rem;
}

.main-grid {
  display: grid;
  gap: 24px;
  padding: 20px 0 32px;
}

@media (min-width: 960px) {
  .main-grid {
    grid-template-columns: minmax(0, 1fr) 360px;
    align-items: start;
  }
}

.panels {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.summary-aside {
  min-width: 0;
}

.summary-sticky {
  position: relative;
}

@media (min-width: 960px) {
  .summary-sticky {
    position: sticky;
    top: 16px;
  }
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 20px 22px;
  box-shadow: var(--shadow);
}

.card-title {
  margin: 0 0 14px;
  font-size: 1.15rem;
  letter-spacing: -0.01em;
}

.fieldset-reset {
  border: 0;
  margin: 0;
  padding: 0;
}

.field {
  margin-bottom: 16px;
}

.field:last-child {
  margin-bottom: 0;
}

.field label {
  display: block;
  font-weight: 600;
  font-size: 0.95rem;
  margin-bottom: 8px;
}

.input {
  width: 100%;
  min-height: 48px;
  padding: 12px 14px;
  font-size: 1.05rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fbfcfe;
  color: var(--text);
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.input:hover {
  border-color: #c5ccd9;
}

.input:focus {
  outline: none;
  border-color: var(--focus);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
  background: #fff;
}

.input[aria-invalid="true"] {
  border-color: var(--danger);
  box-shadow: 0 0 0 2px rgba(180, 35, 24, 0.12);
}

.input-select {
  cursor: pointer;
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 22px) calc(50% - 3px), calc(100% - 16px) calc(50% - 3px);
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
}

.field-error {
  margin: 6px 0 0;
  font-size: 0.875rem;
  color: var(--danger);
}

.hint {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 0.92rem;
}

.period-badge {
  margin: -6px 0 14px;
  display: inline-block;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
  font-size: 0.9rem;
}

.kpi-grid {
  display: grid;
  gap: 12px;
  margin-bottom: 4px;
}

/* -------------------------------------------------------------------------- */
/* Visual summary (CSS-only bars)                                             */
/* -------------------------------------------------------------------------- */

.visual-summary-wrap {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.visual-summary-heading {
  margin: 0 0 14px;
  font-size: 1.02rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text);
}

.visual-summary-body {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.visual-block {
  margin: 0;
}

.visual-block-title {
  margin: 0 0 4px;
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--text);
}

.visual-block-desc {
  margin: 0 0 10px;
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.4;
}

.visual-rows {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.visual-row-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.visual-row-label {
  font-size: 0.82rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.visual-row-value {
  font-size: 0.95rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.visual-row-value--profit {
  color: var(--profit);
}

.visual-row-value--loss {
  color: var(--loss);
}

.visual-row-value--even {
  color: var(--warn);
}

.visual-track {
  position: relative;
  width: 100%;
  border-radius: 8px;
  background: #e8ecf4;
  overflow: hidden;
  min-height: 10px;
}

.visual-track--thick {
  min-height: 14px;
}

.visual-track--net-loss {
  background: #fde8e8;
  box-shadow: inset 0 0 0 1px rgba(155, 28, 28, 0.2);
}

.visual-fill {
  height: 100%;
  min-width: 0;
  border-radius: inherit;
  transition: width 0.2s ease;
}

.visual-fill--revenue {
  background: linear-gradient(90deg, #2563eb, #1f4fa3);
}

.visual-fill--expense {
  background: linear-gradient(90deg, #64748b, #475569);
}

.visual-fill--profit {
  background: linear-gradient(90deg, #0f9d6a, #0f6a45);
}

.visual-fill--loss {
  background: linear-gradient(90deg, #dc2626, #9b1c1c);
}

.visual-fill--even {
  background: linear-gradient(90deg, #94a3b8, #64748b);
}

.visual-fill--food {
  background: linear-gradient(90deg, #d97706, #b45309);
}

.visual-fill--labor {
  background: linear-gradient(90deg, #7c3aed, #5b21b6);
}

.visual-row-note {
  margin: 6px 0 0;
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.35;
}

/* -------------------------------------------------------------------------- */
/* Previous period comparison                                                 */
/* -------------------------------------------------------------------------- */

.compare-wrap {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.compare-section-heading {
  margin: 0 0 12px;
  font-size: 1.02rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text);
}

.compare-actions.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 10px;
}

.compare-summary {
  margin-top: 4px;
}

.compare-empty {
  margin: 0;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  border: 1px dashed var(--border);
  background: #f8f9fc;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.45;
}

.compare-meta {
  margin: 0 0 12px;
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.4;
}

.compare-cards {
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr;
}

.compare-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px 14px;
  background: #fafbff;
}

.compare-card-title {
  margin: 0 0 10px;
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text);
}

.compare-dl {
  margin: 0;
  padding: 0;
}

.compare-dl-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px 16px;
  padding: 6px 0;
  border-bottom: 1px solid #e8ecf4;
  font-size: 0.88rem;
}

.compare-dl-row:last-of-type {
  border-bottom: 0;
}

.compare-dl-row dt {
  margin: 0;
  font-weight: 600;
  color: var(--muted);
}

.compare-dl-row dd {
  margin: 0;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.compare-trend {
  margin: 10px 0 0;
}

.compare-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 700;
}

.compare-chip--up {
  background: var(--profit-bg);
  color: var(--profit);
}

.compare-chip--down {
  background: var(--loss-bg);
  color: var(--loss);
}

.compare-chip--same {
  background: #eef1f6;
  color: var(--muted);
}

.kpi {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 14px 12px;
  background: #fafbff;
}

.kpi-label {
  margin: 0 0 6px;
  font-size: 0.82rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.kpi-value {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  word-break: break-word;
}

.kpi-sub {
  margin: 6px 0 0;
  font-size: 0.88rem;
  color: var(--muted);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.95rem;
}

.status-pill--profit {
  background: var(--profit-bg);
  color: var(--profit);
}

.status-pill--loss {
  background: var(--loss-bg);
  color: var(--loss);
}

.status-pill--even {
  background: var(--warn-bg);
  color: var(--warn);
}

.card-actions .btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.btn {
  min-height: 48px;
  padding: 0 18px;
  font-size: 1rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  font-family: inherit;
}

.btn:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.btn-secondary {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: #c9d6f2;
}

.btn-secondary:hover {
  filter: brightness(0.97);
}

.btn-danger {
  background: #fff;
  color: var(--danger);
  border-color: #f1c0bc;
}

.btn-danger:hover {
  background: #fff5f5;
}

.prose-sections {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding-bottom: 48px;
}

.prose h2 {
  margin-top: 0;
}

.prose ol,
.prose ul {
  padding-left: 1.2rem;
}

.faq-dl dt {
  font-weight: 700;
  margin-top: 12px;
}

.faq-dl dt:first-child {
  margin-top: 0;
}

.faq-dl dd {
  margin: 6px 0 0;
  color: var(--muted);
}

.site-footer {
  padding: 24px 0 40px;
  border-top: 1px solid var(--border);
  background: #e7ebf3;
}

.footer-note {
  margin: 0;
  font-size: 0.9rem;
  color: var(--muted);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

code {
  font-size: 0.92em;
}

/* -------------------------------------------------------------------------- */
/* Summary actions (print / export) + clipboard status                        */
/* -------------------------------------------------------------------------- */

.summary-actions.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.export-status {
  margin: 0 0 8px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--profit);
}

/* -------------------------------------------------------------------------- */
/* Export fallback dialog (clipboard unavailable)                             */
/* -------------------------------------------------------------------------- */

.export-fallback {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(20, 24, 36, 0.45);
}

.export-fallback[hidden] {
  display: none !important;
}

.export-fallback-panel {
  width: min(100%, 520px);
  max-height: min(90vh, 640px);
  overflow: auto;
  padding: 22px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.export-fallback-title {
  margin: 0 0 10px;
  font-size: 1.2rem;
}

.export-fallback-hint {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.92rem;
}

.export-fallback-textarea {
  width: 100%;
  min-height: 220px;
  padding: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85rem;
  line-height: 1.45;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  resize: vertical;
  color: var(--text);
  background: #fbfcfe;
}

.export-fallback-actions {
  margin-top: 14px;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* -------------------------------------------------------------------------- */
/* Print host: hidden on screen, populated only for window.print()            */
/* -------------------------------------------------------------------------- */

.print-summary-host {
  position: fixed;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
}

@media print {
  @page {
    margin: 14mm;
  }

  body {
    background: #fff !important;
    color: #000 !important;
  }

  .no-print {
    display: none !important;
  }

  .print-summary-host {
    position: static !important;
    width: auto !important;
    height: auto !important;
    overflow: visible !important;
    opacity: 1 !important;
    pointer-events: auto !important;
  }

  .print-summary-inner {
    font-family: var(--font);
    font-size: 11pt;
    line-height: 1.45;
    color: #000;
    max-width: 100%;
  }

  .print-title {
    margin: 0 0 12pt;
    font-size: 18pt;
    font-weight: 700;
    letter-spacing: -0.02em;
  }

  .print-meta {
    margin: 0 0 6pt;
    font-size: 10pt;
  }

  .print-section-title {
    margin: 14pt 0 6pt;
    font-size: 12pt;
    font-weight: 700;
    border-bottom: 1pt solid #ccc;
    padding-bottom: 3pt;
  }

  .print-muted {
    margin: 0 0 8pt;
    font-size: 10pt;
    color: #444;
  }

  .print-list {
    margin: 0 0 10pt;
    padding-left: 14pt;
    list-style: disc;
  }

  .print-list li {
    margin-bottom: 4pt;
    break-inside: avoid;
  }

  .print-line-label {
    font-weight: 600;
  }

  .print-line-value {
    margin-left: 6pt;
    font-variant-numeric: tabular-nums;
  }

  .print-kpi .print-line-value {
    font-weight: 600;
  }
}
