/*
 * 21Digby KPI Dashboard — component styles
 *
 * Starter stylesheet for the "Gradient ribbon" design. Uses only variables
 * from tokens.css (load tokens.css first). Plain CSS, no build step.
 * Class names follow a simple block__element--modifier pattern.
 * See docs/STYLE.md for what each component is for.
 */

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

body {
  margin: 0;
  background: var(--color-page);
  color: var(--color-text);
  font-family: var(--font-body);
  font-size: var(--text-body);
  line-height: var(--line-height);
}

a { color: var(--color-link); }
a:hover { color: var(--color-link-hover); }

h1, h2, h3 { font-family: var(--font-display); margin: 0; letter-spacing: -0.01em; }

button, input, select { font: inherit; }

:focus-visible { outline: var(--focus-ring); outline-offset: var(--focus-offset); }

/* Components set their own display, so make the hidden attribute always win */
[hidden] { display: none !important; }

.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;
}

/* ---------- Header bar ---------- */
.app-header { background: var(--color-charcoal); color: var(--color-on-charcoal); }

.app-header__inner {
  max-width: var(--page-max-width);
  margin: 0 auto;
  padding: var(--space-3) var(--page-gutter);
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: var(--space-4);
}

.app-nav { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.app-nav__user { padding: 0 var(--space-2); font-size: var(--text-small); color: var(--color-on-charcoal-muted); }
/* A form that only wraps one button (e.g. Log out) and shouldn't affect the layout */
.inline-form { display: contents; }

/* Text logo stand-in. Replace with the official SVG wordmark (reversed version) when available. */
.logo {
  display: inline-flex; align-items: baseline;
  font-family: var(--font-display); font-weight: var(--weight-black);
  font-size: 24px; letter-spacing: -0.03em; line-height: 1; text-decoration: none;
}
.logo__21 { background: var(--gradient-logo); -webkit-background-clip: text; background-clip: text; color: transparent; }
.logo__digby { color: var(--color-on-charcoal); }
.logo__dot { width: 7px; height: 7px; margin-left: 2px; border-radius: 50%; background: var(--color-signal-on-dark); }

/* ---------- Footer bar ---------- */
.app-footer { background: var(--color-charcoal); color: var(--color-footer-text); }
.app-footer__inner {
  max-width: var(--page-max-width);
  margin: 0 auto;
  padding: var(--space-5) var(--page-gutter);
}
.app-footer__text { margin: 0; font-size: var(--text-small); font-weight: var(--weight-semibold); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: var(--control-height);
  padding: 0 var(--space-5);
  border: 0; border-radius: var(--radius-md);
  font-weight: var(--weight-bold); font-size: var(--text-label);
  letter-spacing: var(--tracking-label); text-transform: uppercase;
  text-decoration: none; cursor: pointer;
}
.btn svg { width: 16px; height: 16px; }

.btn--primary { background: var(--color-charcoal); color: var(--color-on-charcoal); box-shadow: var(--shadow-button); }
.btn--primary:hover { background: #000; color: var(--color-on-charcoal); }

.btn--secondary { background: transparent; color: var(--color-text); border: 1px solid #CFCAC0; }
.btn--secondary:hover { background: var(--color-surface-sunken); color: var(--color-text); }

/* Buttons that sit on the charcoal header */
.btn--on-dark-primary { background: var(--color-surface); color: var(--color-charcoal); }
.btn--on-dark-primary:hover { color: var(--color-charcoal); background: var(--color-surface-sunken); }
.btn--on-dark { background: var(--color-charcoal-raised); color: var(--color-on-charcoal); }
.btn--on-dark:hover { color: var(--color-on-charcoal); background: #3A404B; }
.btn--quiet-on-dark {
  background: transparent; color: var(--color-on-charcoal-muted);
  text-transform: none; letter-spacing: 0; font-weight: var(--weight-semibold); font-size: var(--text-small);
  padding: 0 var(--space-2);
}
.btn--quiet-on-dark:hover { color: var(--color-on-charcoal); }

.btn--lg { min-height: var(--control-height-lg); padding: 0 26px; }

/* ---------- Page layout ---------- */
.page {
  max-width: var(--page-max-width);
  margin: 0 auto;
  padding: var(--space-8) var(--page-gutter) var(--space-18);
  display: flex; flex-direction: column; gap: var(--space-8);
}
.page--narrow { max-width: var(--form-max-width); gap: var(--space-5); }
.page--login { max-width: var(--login-max-width); }

@media (max-width: 900px) {
  :root { --page-gutter: 24px; }
}

.back-link {
  align-self: flex-start; display: inline-flex; align-items: center; gap: 6px;
  min-height: var(--control-height); color: var(--color-text);
  font-weight: var(--weight-semibold); font-size: var(--text-small); text-decoration: none;
}

/* ---------- Cards ---------- */
.card { background: var(--color-surface); border-radius: var(--radius-2xl); box-shadow: var(--shadow-card); }
.card--lg { border-radius: var(--radius-3xl); box-shadow: var(--shadow-card-lg); }

/* Thin ribbon strip across the top of a card */
.card--accent { position: relative; overflow: hidden; }
.card--accent::before {
  content: ""; position: absolute; left: 0; right: 0; top: 0; height: 6px;
  background: var(--gradient-ribbon);
}

/* ---------- Filter bar ---------- */
.filter-bar {
  padding: var(--space-5) var(--space-6);
  display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: var(--space-5);
}
.filter-bar__fields { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--space-3); }

.eyebrow {
  font-size: var(--text-micro); font-weight: var(--weight-bold);
  letter-spacing: 0.08em; text-transform: uppercase; color: var(--color-text-muted);
}
.page-title { font-size: var(--text-h1); font-weight: var(--weight-bold); line-height: 1.15; letter-spacing: -0.02em; }

/* ---------- Form fields ---------- */
.field { display: flex; flex-direction: column; gap: 6px; font-size: var(--text-label); font-weight: var(--weight-bold); }
.field--compact { font-size: var(--text-micro); color: var(--color-text-muted); gap: var(--space-1); }
.field__help { font-weight: var(--weight-regular); color: var(--color-text-muted); }
.field__ref { font-weight: var(--weight-semibold); color: var(--color-text-subtle); }
.field__error { font-weight: var(--weight-semibold); color: var(--color-error); }
.control[aria-invalid="true"] { border-color: var(--color-error); }

.control {
  min-height: var(--control-height);
  padding: 0 var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface-sunken);
  color: var(--color-text);
  font-size: 15px; font-weight: var(--weight-medium);
}
.control--lg { min-height: var(--control-height-lg); border-radius: 14px; font-size: var(--text-body); padding: 0 14px; }
.control--number {
  min-height: 52px; background: var(--color-surface); border-radius: 14px; padding: 0 14px;
  font-family: var(--font-display); font-size: 20px; font-weight: var(--weight-semibold);
}
.control--client { min-width: 210px; }
.control--month { min-width: 140px; }

/* ---------- Stat tiles ---------- */
.tiles {
  display: grid;
  /* Fixed-width tiles, so one or two tiles don't stretch across the page */
  grid-template-columns: repeat(auto-fill, var(--tile-width));
  gap: var(--space-4);
}

/* White card with a solid bar down the left edge in the source's color (set data-source) */
.tile {
  position: relative; overflow: hidden;
  border-radius: var(--radius-2xl);
  padding: var(--space-5);
  padding-left: calc(var(--space-5) + var(--tile-bar-width));
  display: flex; flex-direction: column; gap: 14px;
  color: var(--color-text);
  background: var(--color-surface);
  box-shadow: var(--shadow-card);
  --tile-accent: var(--color-border); /* fallback for a source without its own color */
}
.tile::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: var(--tile-bar-width);
  background: var(--tile-accent);
}
.tile[data-source="LinkedIn"] { --tile-accent: var(--source-linkedin); }
.tile[data-source="Facebook"] { --tile-accent: var(--source-facebook); }
.tile[data-source="Instagram"] { --tile-accent: var(--source-instagram); }
.tile[data-source="YouTube"] { --tile-accent: var(--source-youtube); }
.tile[data-source="Website"] { --tile-accent: var(--source-website); }
.tile .source-icon { border: 1px solid var(--color-border-soft); }

.tile__head { display: flex; align-items: center; gap: var(--space-3); }
.tile__name { font-family: var(--font-display); font-weight: var(--weight-bold); font-size: 18px; line-height: 1.25; }
.tile__month { font-size: var(--text-micro); font-weight: var(--weight-semibold); color: var(--color-text-muted); }
.tile__metrics { display: flex; flex-direction: column; gap: var(--space-2); }

.metric-row { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); }
.metric-row__label { display: flex; flex-direction: column; line-height: 1.25; font-size: var(--text-label); font-weight: var(--weight-bold); }
.metric-row__delta { font-size: 11px; font-weight: var(--weight-semibold); color: var(--color-text-muted); }
.chip {
  padding: 5px var(--space-3); border-radius: var(--radius-sm);
  background: var(--color-surface-sunken);
  font-family: var(--font-display); font-weight: var(--weight-bold); font-size: var(--text-chip); white-space: nowrap;
}

/* Source icons: official platform logo inside a white circle */
.source-icon {
  flex: 0 0 auto; width: 44px; height: 44px; border-radius: 50%;
  background: var(--color-surface);
  display: flex; align-items: center; justify-content: center; color: var(--color-text);
}
.source-icon img, .source-icon svg { width: 24px; height: 24px; }
/* Keeps non-square logos (YouTube) in proportion */
.source-icon img { object-fit: contain; }
.source-icon--sm { width: 36px; height: 36px; border: 1px solid var(--color-border-soft); }
.source-icon--sm img, .source-icon--sm svg { width: 18px; height: 18px; }
/* Placeholder until official logo files are added */
.source-icon--placeholder {
  font-size: 9px; font-weight: var(--weight-bold); letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--color-text-muted); outline: 1.5px dashed #B8BFCB; outline-offset: -5px;
}

/* ---------- Source sections and chart cards ---------- */
.source-section { display: flex; flex-direction: column; gap: var(--space-4); }
.section-head { display: flex; align-items: center; gap: var(--space-3); }
.section-head__title { font-size: var(--text-h2); font-weight: var(--weight-bold); line-height: 1.2; }
.section-head__rule { flex: 1 1 auto; height: 1px; background: var(--color-rule); }
.section-head__meta { font-size: var(--text-label); color: var(--color-text-muted); }

.chart-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 18px; }

.chart-card {
  margin: 0; padding: 18px var(--space-5) 14px;
  background: var(--color-surface); border-radius: var(--radius-xl); box-shadow: var(--shadow-card);
  display: flex; flex-direction: column; gap: var(--space-2);
}
.chart-card__head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-2); }
.chart-card__label {
  font-size: var(--text-label); font-weight: var(--weight-bold);
  letter-spacing: var(--tracking-label); text-transform: uppercase; color: var(--color-text-muted);
}
.chart-card__value { font-family: var(--font-display); font-weight: var(--weight-bold); font-size: var(--text-stat); }
.chart { min-height: 200px; }

/* Summary numbers for the date range, between the chart label and the chart */
.chart-stats {
  margin: 0; padding: var(--space-2) 0 var(--space-1);
  border-top: 1px solid var(--color-rule);
  display: grid; grid-template-columns: repeat(auto-fit, minmax(72px, 1fr)); gap: var(--space-2);
}
.chart-stats__item { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.chart-stats__label { font-size: var(--text-micro); color: var(--color-text-muted); }
.chart-stats__value {
  margin: 0; font-family: var(--font-display); font-weight: var(--weight-semibold);
  font-size: var(--text-body); white-space: nowrap;
}

/* ---------- Notices ---------- */
.notice {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3);
  padding: 14px 18px; border-radius: var(--radius-lg);
  background: var(--color-surface); border: 1px solid var(--color-border-soft);
  font-size: var(--text-small);
}
.notice--success { border-color: #DCE6FA; box-shadow: 0 12px 28px -18px rgba(30, 34, 41, 0.4); font-size: var(--text-body); }
.notice--editing { background: var(--brand-blue-mist); border-color: #C9DAFB; font-size: var(--text-body); }
/* Error notice: the "!" mark and the wording carry the meaning, not just the color */
.notice--error { background: var(--color-error-soft); border-color: var(--color-error); font-size: var(--text-body); }
.notice__icon {
  flex: 0 0 auto; width: 20px; height: 20px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--color-error); color: var(--color-surface);
  font-size: var(--text-micro); font-weight: var(--weight-bold);
}
.signal-dot { flex: 0 0 auto; width: 12px; height: 12px; border-radius: 50%; background: var(--brand-signal-blue); }

/* ---------- Entry form ---------- */
.form-card { padding: 36px 36px 28px; display: flex; flex-direction: column; gap: var(--space-7); }
.form-card__title { font-size: 32px; font-weight: var(--weight-bold); line-height: 1.15; letter-spacing: -0.02em; }
.form-card__intro { margin: 0; color: var(--color-text-muted); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: var(--space-4); }
.form-actions { display: flex; flex-wrap: wrap-reverse; align-items: center; justify-content: space-between; gap: var(--space-3); padding-top: var(--space-1); }
.form-actions--end { justify-content: flex-end; }
/* Keeps several main buttons together on the right */
.form-actions__group { display: flex; flex-wrap: wrap; gap: var(--space-3); }

fieldset.plain { margin: 0; padding: 0; border: 0; min-width: 0; }
fieldset.plain > legend { padding: 0; margin-bottom: 10px; font-size: var(--text-label); font-weight: var(--weight-bold); }

.source-picker { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; }
/* Each option is a radio input + label, styled as a button */
.source-option input { position: absolute; opacity: 0; pointer-events: none; }
.source-option label {
  min-height: 64px; display: flex; align-items: center; gap: 10px; padding: 10px var(--space-3);
  border-radius: var(--radius-lg); border: 1px solid var(--color-border);
  background: var(--color-surface); font-weight: var(--weight-bold); font-size: 15px; cursor: pointer;
}
.source-option input:checked + label {
  border: 2px solid var(--color-charcoal);
  background: linear-gradient(110deg, var(--brand-sun), var(--brand-mango) 60%, var(--brand-coral));
  box-shadow: 0 14px 26px -14px rgba(214, 90, 40, 0.7);
}
.source-option input:focus-visible + label { outline: var(--focus-ring); outline-offset: var(--focus-offset); }

.values-panel {
  margin: 0; padding: 22px; border: 0; border-radius: var(--radius-xl);
  background: var(--color-surface-sunken);
  display: flex; flex-direction: column; gap: var(--space-4); min-width: 0;
}
.values-panel > legend {
  float: left; width: 100%; padding: 0;
  display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: var(--space-2);
}
.values-panel__title { font-family: var(--font-display); font-weight: var(--weight-semibold); font-size: var(--text-h3); }
.values-panel__meta { font-size: var(--text-label); color: var(--color-text-muted); }
.values-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: var(--space-4); }

/* ---------- Clients page ---------- */
/* Main card holding a title row and a table */
.list-card { padding: 36px; display: flex; flex-direction: column; gap: var(--space-6); }
.list-card__head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: var(--space-4); }

.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
  padding: 0 var(--space-3) var(--space-2); text-align: left;
  font-size: var(--text-label); font-weight: var(--weight-bold); color: var(--color-text-muted);
  text-transform: uppercase; letter-spacing: var(--tracking-label);
  border-bottom: 1px solid var(--color-rule);
}
.data-table td { padding: var(--space-2) var(--space-3); border-bottom: 1px solid var(--color-border-soft); font-weight: var(--weight-semibold); }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover { background: var(--color-row-hover); }
.data-table .data-table__status { width: 90px; text-align: center; }
.data-table .data-table__action { width: 60px; text-align: right; }

/* Green check / red X. The shape (and hidden text) carries the meaning, not just the color. */
.status-icon { width: 22px; height: 22px; vertical-align: middle; }
.status-icon--yes { color: var(--color-status-yes); }
.status-icon--no { color: var(--color-status-no); }

/* Square icon-only link (the pencil), 44px touch target */
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: var(--control-height); height: var(--control-height); border-radius: var(--radius-md);
  color: var(--color-text);
}
.icon-btn:hover { background: var(--color-surface-sunken); color: var(--color-text); }
.icon-btn svg { width: 18px; height: 18px; }

/* Active / Inactive choice on the client form (items reuse .source-option) */
.status-picker { display: grid; grid-template-columns: repeat(2, minmax(0, 200px)); gap: 10px; margin-bottom: var(--space-2); }

/* ---------- Empty states ---------- */
.empty-state { padding: var(--space-12); display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-10); }
.empty-state__text { flex: 1 1 360px; display: flex; flex-direction: column; gap: 14px; }
.empty-state__title { font-size: 30px; font-weight: var(--weight-bold); line-height: 1.2; }
.empty-state__body { margin: 0; font-size: 17px; color: var(--color-text-subtle); max-width: 520px; }
.empty-state__action { align-self: flex-start; margin-top: var(--space-2); }

.steps { flex: 1 1 320px; margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 14px; }
.steps li { display: flex; gap: var(--space-4); align-items: flex-start; padding: var(--space-4) 18px; border-radius: 18px; background: var(--color-surface-sunken); }
.steps__num { font-family: var(--font-display); font-weight: var(--weight-bold); font-size: 20px; color: var(--color-numbered); }
.steps strong { display: block; }
.steps__desc { color: var(--color-text-muted); }

.ghost-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 18px; opacity: 0.7; }
.ghost-tile {
  min-height: 170px; border-radius: var(--radius-2xl); border: 2px dashed #D3CEC4; padding: var(--space-5);
  display: flex; flex-direction: column; gap: 14px;
}
.ghost-tile__bar { height: 12px; border-radius: 6px; background: var(--color-border-soft); }
.ghost-tile .source-icon { background: var(--color-border-soft); }

.missing-sources {
  grid-column: span 2; min-height: 170px; border-radius: var(--radius-2xl); border: 2px dashed #D3CEC4;
  padding: var(--space-6); display: flex; flex-direction: column; justify-content: center; gap: 6px;
}
.missing-sources__title { font-family: var(--font-display); font-weight: var(--weight-semibold); font-size: 18px; }
@media (max-width: 700px) { .missing-sources { grid-column: auto; } }
