/* ============================================================
   components.css — the building blocks of the Business Suite look.
   Needs tokens.css. Markup for each block: references/components.md.
   ============================================================ */

/* ---------- Page ---------- */
.page { display: flex; flex-direction: column; gap: 1rem; animation: fadeUp 0.25s ease; }
.page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 0.5rem; }
.page-header h1 { margin-bottom: 0.25rem; }
.page-header p { color: var(--color-secondary-text); font-size: 0.9rem; }
.page-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
.muted { color: var(--color-secondary-text); font-size: 0.82rem; }
.hint { color: var(--color-muted-text); font-size: 0.78rem; }

/* ---------- Cards ---------- */
.card {
  background: var(--bg-secondary); border: 1px solid var(--color-border); border-radius: var(--radius-xl);
  padding: 1.5rem; box-shadow: var(--shadow-sm);
  transition: box-shadow 0.2s var(--ease), border-color 0.2s var(--ease);
}
.card:hover { box-shadow: var(--shadow-md); }
.card h2 { margin-bottom: 0.25rem; }
.card h3 { margin: 0 0 0.6rem; font-size: 0.95rem; }
.card-head { display: flex; justify-content: space-between; gap: 1rem; align-items: flex-start; flex-wrap: wrap; margin-bottom: 1rem; }
.card-description { font-size: 0.8125rem; color: var(--color-secondary-text); max-width: 680px; margin-top: 0.25rem; }
.card--tight { padding: 1.1rem 1.25rem; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr)); gap: 1rem; }
/* A wide card beside a narrow one (a chart and its ranking): 2/3 + 1/3, one column on phones */
.grid--2-1 { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 1rem; }
.grid--1-2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); gap: 1rem; }
@media (max-width: 960px) { .grid--2-1, .grid--1-2 { grid-template-columns: 1fr; } }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
  padding: 0.5625rem 1.125rem; font-family: inherit; font-size: 0.875rem; font-weight: 700; letter-spacing: -0.005em;
  border-radius: 0.75rem; border: none; cursor: pointer; white-space: nowrap; text-decoration: none;
  transition: transform 0.15s, box-shadow 0.15s, background 0.15s, filter 0.15s;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--gradient-brand); color: #fff; box-shadow: 0 1px 0 rgba(255,255,255,0.25) inset, 0 6px 16px -6px rgba(91, 91, 246, 0.6); }
.btn-primary:hover:not(:disabled) { filter: brightness(1.06); transform: translateY(-1px); box-shadow: 0 1px 0 rgba(255,255,255,0.25) inset, 0 10px 22px -8px rgba(91, 91, 246, 0.7); }
.btn-outline { background: transparent; color: var(--color-accent); border: 1px solid var(--color-accent); }
.btn-outline:hover:not(:disabled) { background: var(--color-accent-light); }
.btn-ghost { background: var(--bg-secondary); color: var(--color-secondary-text); border: 1px solid var(--color-border); box-shadow: var(--shadow-sm); }
.btn-ghost:hover:not(:disabled) { background: var(--bg-primary); color: var(--color-primary-text); }
.btn-danger { background: transparent; color: #dc2626; border: 1px solid #fecaca; }
.btn-danger:hover:not(:disabled) { background: #fef2f2; border-color: #f87171; }
.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.8rem; border-radius: 0.6rem; }
.btn-icon { width: 34px; height: 34px; padding: 0; }

/* ---------- Forms ---------- */
input[type='text'], input[type='url'], input[type='email'], input[type='search'], input[type='password'], input[type='tel'],
input[type='date'], input[type='time'], input[type='datetime-local'], input[type='number'], select, textarea {
  font-family: inherit; font-size: 0.88rem; color: var(--color-primary-text);
  padding: 0.55rem 0.75rem; border-radius: 0.7rem; border: 1px solid var(--color-border); background: var(--bg-secondary);
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--color-accent); box-shadow: 0 0 0 4px var(--color-accent-ring); }
input[readonly] { background: var(--bg-subtle); color: var(--color-secondary-text); }
.field { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.82rem; font-weight: 600; color: var(--color-primary-text); }
.field small { font-weight: 500; color: var(--color-muted-text); font-size: 0.75rem; }
.field input, .field select, .field textarea { width: 100%; }
.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 0.7rem; }
.check-row { display: flex; gap: 0.6rem; align-items: flex-start; font-size: 0.84rem; cursor: pointer; }
.check-row input { margin-top: 0.25rem; accent-color: var(--color-accent); }
/* Switch: <button class="switch is-on" role="switch" aria-checked="true"><span></span></button> */
.switch { width: 38px; height: 22px; border-radius: 999px; border: none; background: var(--color-border-strong); position: relative; cursor: pointer; transition: background 0.15s; flex-shrink: 0; }
.switch span { position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: var(--shadow-sm); transition: transform 0.18s var(--ease); }
.switch.is-on { background: var(--color-accent); }
.switch.is-on span { transform: translateX(16px); }

/* ---------- Segmented tabs (section switcher) ---------- */
.tabs {
  display: inline-flex; align-items: center; gap: 0.4rem; padding: 0.4rem; max-width: 100%; overflow-x: auto; scrollbar-width: none;
  background: var(--bg-secondary); border: 1px solid var(--color-border); border-radius: 0.95rem; box-shadow: var(--shadow-sm);
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  border: none; background: none; font-family: inherit; cursor: pointer; padding: 0.65rem 1.25rem; min-height: 42px;
  border-radius: 0.75rem; font-size: 0.9rem; font-weight: 600; color: var(--color-secondary-text); white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}
.tab:hover:not(.is-active) { background: var(--bg-subtle); }
.tab.is-active { background: var(--color-accent-light); color: var(--color-accent); }

/* ---------- Chips (filters, toggles) ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.chip {
  border: 1px solid var(--color-border); background: var(--bg-secondary); border-radius: 999px; padding: 0.35rem 0.8rem;
  font-family: inherit; font-size: 0.8rem; font-weight: 600; color: var(--color-secondary-text); cursor: pointer;
  display: inline-flex; align-items: center; gap: 0.35rem;
}
.chip.is-on { background: var(--color-accent-light); border-color: var(--color-accent); color: var(--color-accent); }

/* ---------- Tables ---------- */
.table-wrap { border-radius: var(--radius-xl); overflow: auto; border: 1px solid var(--color-border); background: var(--bg-secondary); box-shadow: var(--shadow-sm); }
.table { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 0.86rem; }
.table th {
  text-align: left; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--color-muted-text);
  font-weight: 700; background: var(--bg-subtle); border-bottom: 1px solid var(--color-border); padding: 0.7rem 0.9rem; white-space: nowrap;
}
.table td { border-bottom: 1px solid var(--color-border); padding: 0.75rem 0.9rem; vertical-align: middle; }
.table tbody tr { transition: background 0.12s; }
.table tbody tr:hover { background: var(--bg-subtle); }
.table tbody tr:last-child td { border-bottom: none; }
.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
/* A table with a title inside a card: the table runs to the card's edges, no second border */
.card > .table-wrap { margin: 0 -1.5rem -1.5rem; border: none; border-top: 1px solid var(--color-border); border-radius: 0 0 var(--radius-xl) var(--radius-xl); box-shadow: none; }

/* ---------- Status chips ---------- */
.status { display: inline-flex; align-items: center; border-radius: 999px; padding: 3px 10px; font-size: 0.75rem; font-weight: 700; white-space: nowrap; }
.status::before { content: '●'; margin-right: 5px; font-size: 0.6rem; }
.status--draft   { background: #f1f5f9; color: #64748b; }
.status--pending { background: #f3e8ff; color: #7e22ce; }
.status--active  { background: var(--color-accent-light); color: var(--color-accent); }
.status--done    { background: #d1fae5; color: #065f46; }
.status--warn    { background: #ffedd5; color: #c2410c; }
.status--error   { background: #fee2e2; color: #dc2626; }

/* Small pill (counts, tags) */
.pill { display: inline-flex; align-items: center; gap: 0.3rem; padding: 1px 8px; border-radius: 999px; font-size: 0.72rem; font-weight: 700; background: var(--bg-subtle); color: var(--color-secondary-text); border: 1px solid var(--color-border); }
.pill--accent { background: var(--color-accent-light); color: var(--color-accent); border-color: transparent; }

/* ---------- KPIs ---------- */
/* Strip: several figures in one card, separated by thin rules */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 0.5rem 0; }
.kpi { padding: 0.25rem 1.5rem; border-left: 1px solid var(--color-border); }
.kpi:first-child { border-left: none; padding-left: 0.25rem; }
.kpi-label { font-size: 0.82rem; color: var(--color-secondary-text); font-weight: 600; display: flex; align-items: center; gap: 0.25rem; }
.kpi-value { display: flex; align-items: baseline; gap: 0.5rem; flex-wrap: wrap; margin-top: 0.15rem; }
.kpi-value strong { font-size: 1.6rem; font-weight: 800; letter-spacing: -0.03em; line-height: 1.15; white-space: nowrap; }
/* Phones: two figures a row, a rule above instead of beside */
@media (max-width: 560px) {
  .kpis { grid-template-columns: 1fr 1fr; gap: 0.75rem 1rem; }
  .kpi, .kpi:first-child { border-left: none; padding: 0.5rem 0 0; border-top: 1px solid var(--color-border); }
  .kpi:nth-child(-n+2) { border-top: none; padding-top: 0; }
  .kpi-value strong { font-size: 1.35rem; }
}
/* Tile: one figure per card, coloured top edge (set --tile-color) */
.kpi-tile { position: relative; overflow: hidden; background: var(--bg-secondary); border: 1px solid var(--color-border); border-radius: var(--radius-xl); padding: 1.1rem 1.25rem; box-shadow: var(--shadow-sm); transition: transform 0.2s var(--ease), box-shadow 0.2s var(--ease); }
.kpi-tile::before { content: ''; position: absolute; inset: 0 0 auto; height: 3px; background: var(--tile-color, var(--color-accent)); opacity: 0.9; }
.kpi-tile:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
/* Change vs previous period: ▲ 12 % */
.delta { display: inline-flex; align-items: center; gap: 2px; font-size: 0.72rem; font-weight: 700; padding: 1px 7px; border-radius: 999px; white-space: nowrap; }
.delta.is-good { color: #047857; background: var(--color-success-light); }
.delta.is-bad { color: #b91c1c; background: var(--color-danger-light); }

/* ---------- Bar list (ranking) ---------- */
.barlist { list-style: none; display: flex; flex-direction: column; gap: 0.85rem; }
.barlist-row { display: flex; justify-content: space-between; gap: 0.75rem; align-items: baseline; margin-bottom: 0.35rem; }
.barlist-label { font-size: 0.84rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.barlist-label small { display: block; font-weight: 500; font-size: 0.72rem; color: var(--color-muted-text); }
.barlist-num { font-size: 0.85rem; font-weight: 700; flex-shrink: 0; }
.barlist-track { height: 6px; border-radius: 999px; background: var(--chart-grid); overflow: hidden; }
.barlist-track > div { height: 100%; border-radius: inherit; background: var(--gradient-brand); transition: width 0.6s var(--ease); }

/* ---------- Notes & banners ---------- */
.note { padding: 0.65rem 0.85rem; border-radius: 0.7rem; background: var(--bg-subtle); border: 1px solid var(--color-border); font-size: 0.84rem; color: var(--color-secondary-text); }
.note--info { background: var(--color-accent-light); border-color: rgba(91, 91, 246, 0.2); color: #3730a3; }
.note--warn { background: #fffbeb; border-color: #fcd34d; color: #92400e; }
.note--error { background: #fef2f2; border-color: #fca5a5; color: #b91c1c; }
.note--ok { background: #f0fdf4; border-color: #bbf7d0; color: #15803d; }

/* ---------- Empty state ---------- */
.empty { padding: 2.5rem 1.5rem; text-align: center; color: var(--color-secondary-text); display: flex; flex-direction: column; align-items: center; gap: 0.6rem; }
.empty h3 { color: var(--color-primary-text); margin: 0; }
.empty p { max-width: 420px; font-size: 0.88rem; }

/* ---------- Help «?» bubble ---------- */
.help-q {
  display: inline-grid; place-items: center; flex-shrink: 0; width: 15px; height: 15px; margin-left: 0.3rem; vertical-align: middle;
  border: 1.4px solid currentColor; border-radius: 50%; font-size: 0.6rem; font-weight: 800; line-height: 1; font-style: normal;
  color: var(--color-muted-text); opacity: 0.75; cursor: help; position: relative;
}
.help-q:hover, .help-q:focus-visible { opacity: 1; color: var(--color-accent); outline: none; }
.help-q .help-tip {
  display: none; position: absolute; z-index: 4000; bottom: calc(100% + 8px); left: 50%; transform: translateX(-50%); width: 260px;
  padding: 0.7rem 0.85rem; background: var(--bg-secondary); color: var(--color-secondary-text); border: 1px solid var(--color-border);
  border-radius: 0.7rem; box-shadow: 0 14px 32px rgba(15, 23, 42, 0.18); font-size: 0.8rem; font-weight: 500; line-height: 1.45; text-align: left;
}
.help-q:hover .help-tip, .help-q:focus .help-tip { display: block; }
.help-tip strong { display: block; color: var(--color-primary-text); font-size: 0.82rem; margin-bottom: 0.2rem; }

/* ---------- Modal ---------- */
.modal-overlay { position: fixed; inset: 0; background: rgba(15, 23, 42, 0.55); backdrop-filter: blur(4px); display: flex; align-items: center; justify-content: center; z-index: 1000; padding: 1rem; animation: overlayIn 0.2s ease; }
@keyframes overlayIn { from { opacity: 0; } to { opacity: 1; } }
.modal-box { background: var(--bg-secondary); border-radius: var(--radius-xl); box-shadow: 0 25px 60px rgba(0,0,0,0.25); width: min(580px, 96vw); max-height: 90vh; display: flex; flex-direction: column; animation: boxIn 0.2s ease; }
.modal-box--wide { width: min(720px, 96vw); }
@keyframes boxIn { from { opacity: 0; transform: scale(0.96) translateY(-8px); } to { opacity: 1; transform: none; } }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 1.25rem 1.5rem; border-bottom: 1px solid var(--color-border); }
.modal-header h2 { font-size: 1rem; font-weight: 700; }
.modal-close-btn { width: 30px; height: 30px; border-radius: 50%; background: var(--bg-primary); border: 1px solid var(--color-border); display: flex; align-items: center; justify-content: center; cursor: pointer; color: var(--color-secondary-text); transition: background 0.15s, color 0.15s; }
.modal-close-btn:hover { background: #fee2e2; color: #dc2626; border-color: #fca5a5; }
.modal-body { padding: 1.25rem 1.5rem; display: flex; flex-direction: column; gap: 0.85rem; overflow-y: auto; }
.modal-footer { display: flex; gap: 0.5rem; align-items: center; padding: 1rem 1.5rem; border-top: 1px solid var(--color-border); }
.modal-footer .spacer { flex: 1; }

/* ---------- Toasts (bottom-right) ---------- */
.toast-container { position: fixed; bottom: 1.5rem; right: 1.5rem; display: flex; flex-direction: column; gap: 0.6rem; z-index: 99999; pointer-events: none; }
.toast { display: flex; align-items: center; gap: 0.6rem; padding: 0.75rem 1rem; border-radius: 10px; min-width: 280px; max-width: 420px; font-size: 0.875rem; font-weight: 500; box-shadow: 0 8px 30px rgba(0,0,0,0.18); pointer-events: all; border-left: 4px solid transparent; animation: toast-in 0.28s cubic-bezier(0.34,1.56,0.64,1) both; }
@keyframes toast-in { from { transform: translateX(120%); opacity: 0; } to { transform: none; opacity: 1; } }
.toast--success { background: #f0fdf4; border-color: #22c55e; color: #15803d; }
.toast--error { background: #fef2f2; border-color: #ef4444; color: #b91c1c; }
.toast--warn { background: #fffbeb; border-color: #f59e0b; color: #92400e; }
.toast--info { background: #eff6ff; border-color: #3b82f6; color: #1d4ed8; }
@media (max-width: 560px) { .toast-container { left: 1rem; right: 1rem; bottom: 1rem; } .toast { min-width: 0; max-width: none; } }

/* ---------- Chart helpers (for hand-drawn SVG charts) ---------- */
.ch-axis { font-size: 11px; fill: var(--color-muted-text); font-family: inherit; }
.ch-grid { stroke: var(--chart-grid); }
.ch-tip { position: absolute; pointer-events: none; padding: 0.45rem 0.6rem; border-radius: 0.6rem; background: #0f172a; color: #fff; font-size: 0.78rem; font-weight: 600; box-shadow: var(--shadow-md); white-space: nowrap; }
.ch-tip span { opacity: 0.7; font-size: 0.7rem; display: block; }
.legend { display: flex; flex-wrap: wrap; gap: 0.9rem; font-size: 0.78rem; color: var(--color-secondary-text); }
/* SVG bars: <rect class="ch-bar" rx="4"/>; the one that matters (the current period) gets .is-current */
.ch-bar { fill: var(--chart-1); opacity: 0.85; transition: opacity 0.15s; }
.ch-bar:hover { opacity: 1; }
.ch-bar.is-current { opacity: 1; }
.ch-prev { fill: none; stroke: var(--chart-muted); stroke-width: 1.8; stroke-dasharray: 5 5; }
.ch-foot { display: flex; flex-wrap: wrap; gap: 0.4rem 1.5rem; font-size: 0.8rem; color: var(--color-secondary-text); margin-top: 0.6rem; }
.ch-foot b { color: var(--color-primary-text); }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; margin-right: 0.35rem; vertical-align: -1px; }
