/* PrintPulse — application styles */

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

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-size: 15px;
  line-height: 1.5;
}

#app { min-height: 100%; display: flex; flex-direction: column; }

a { color: var(--tsb-blue); text-decoration: none; }
a:hover { text-decoration: underline; }

button { font-family: inherit; cursor: pointer; }

h1, h2, h3 { margin: 0; font-weight: 800; letter-spacing: -0.01em; color: var(--ink); }

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

/* ============================ Buttons ============================ */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 16px; border-radius: var(--r-sm);
  border: 1px solid var(--line-strong); background: var(--surface);
  color: var(--ink); font-weight: 600; font-size: 14px;
  transition: background .15s, border-color .15s, color .15s, box-shadow .15s;
}
.btn:hover { border-color: var(--tsb-red); color: var(--tsb-red); }
.btn.primary { background: var(--tsb-red); border-color: var(--tsb-red); color: #fff; }
.btn.primary:hover { background: var(--tsb-red-dark); border-color: var(--tsb-red-dark); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-soft); }
.btn.ghost:hover { background: var(--surface-2); color: var(--ink); }
.btn.sm { padding: 6px 12px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ============================ HOME ============================ */
.home {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 40px 20px; text-align: center;
}
.home__inner { width: 100%; max-width: 720px; }

.home__logo { width: min(360px, 78vw); height: auto; margin: 0 auto 10px; display: block; }
.home__tagline {
  color: var(--ink-soft); font-size: 17px; font-weight: 500;
  margin: 0 0 36px;
}
.home__tagline strong { color: var(--tsb-red); font-weight: 700; }

/* Upload dropzone */
.dropzone {
  position: relative;
  border: 2px dashed var(--line-strong);
  background: var(--surface);
  border-radius: var(--r-xl);
  padding: 46px 28px;
  transition: border-color .18s, background .18s, box-shadow .18s, transform .18s;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
}
.dropzone:hover { border-color: var(--tsb-red); box-shadow: var(--shadow-md); }
.dropzone.is-drag {
  border-color: var(--tsb-red);
  background: var(--tsb-red-tint);
  box-shadow: 0 0 0 4px rgba(204,0,0,.10), var(--shadow-md);
  transform: translateY(-2px);
}
.dropzone__icon {
  width: 58px; height: 58px; margin: 0 auto 16px; display: block;
  color: var(--tsb-red);
}
.dropzone.is-drag .dropzone__icon { transform: translateY(-2px); }
.dropzone__title { font-size: 19px; font-weight: 700; margin-bottom: 6px; }
.dropzone__sub { color: var(--muted); font-size: 14px; }
.dropzone__sub b { color: var(--ink-soft); }
.dropzone__drag-hint {
  position: absolute; inset: 0; display: none;
  align-items: center; justify-content: center;
  border-radius: var(--r-xl); pointer-events: none;
  font-size: 20px; font-weight: 800; color: var(--tsb-red);
}
.dropzone.is-drag .dropzone__drag-hint { display: flex; }
.dropzone.is-drag .dropzone__content { opacity: 0; }

.home__help { margin-top: 26px; font-size: 14px; }
.home__help a { color: var(--ink-soft); border-bottom: 1px dashed var(--line-strong); }
.home__help a:hover { color: var(--tsb-red); border-color: var(--tsb-red); text-decoration: none; }

.home__error {
  margin-top: 18px; color: var(--err); font-weight: 600; font-size: 14px;
}
.home__parsing { margin-top: 22px; }
.progress {
  height: 8px; border-radius: 999px; background: var(--surface-2);
  overflow: hidden; max-width: 420px; margin: 10px auto 6px;
}
.progress__bar { height: 100%; width: 0; background: var(--tsb-red); transition: width .2s; }
.home__parsing small { color: var(--muted); }

/* ============================ Footer ============================ */
.footer {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  text-align: center; color: var(--muted); font-size: 13px;
  padding: 24px 20px; border-top: 1px solid var(--line);
}
.footer a { color: var(--muted); }
.footer__logo { height: 17px; width: auto; opacity: .8; }

/* ============================ App header (dashboard) ============================ */
.appbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px;
  padding: 12px 22px; background: rgba(255,255,255,.9);
  backdrop-filter: saturate(180%) blur(8px);
  border-bottom: 1px solid var(--line);
}
.appbar__brand { display: flex; align-items: center; gap: 12px; cursor: pointer; }
.appbar__brand img { height: 30px; width: auto; }
.appbar__spacer { flex: 1; }
.appbar__meta { color: var(--muted); font-size: 13px; }

/* ============================ Dashboard shell ============================ */
.wrap { width: 100%; max-width: var(--maxw); margin: 0 auto; padding: 22px; }

.toolbar {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: center;
  margin-bottom: 20px;
}
.toolbar__spacer { flex: 1; }

.seg {
  display: inline-flex; background: var(--surface-2); border-radius: var(--r-sm);
  padding: 3px; gap: 3px; border: 1px solid var(--line);
}
.seg button {
  border: none; background: transparent; color: var(--ink-soft);
  padding: 7px 14px; border-radius: 6px; font-weight: 600; font-size: 13px;
}
.seg button.active { background: var(--surface); color: var(--tsb-red); box-shadow: var(--shadow-sm); }

/* Date filter */
.datefilter { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.chips { display: inline-flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--line-strong); background: var(--surface);
  color: var(--ink-soft); padding: 6px 12px; border-radius: 999px;
  font-size: 13px; font-weight: 600;
}
.chip:hover { border-color: var(--tsb-blue); color: var(--tsb-blue); }
.chip.active { background: var(--tsb-blue); border-color: var(--tsb-blue); color: #fff; }
.date-inputs { display: inline-flex; align-items: center; gap: 6px; }
.date-inputs input[type="date"] {
  font-family: inherit; font-size: 13px; padding: 7px 10px;
  border: 1px solid var(--line-strong); border-radius: var(--r-sm);
  color: var(--ink); background: var(--surface);
}
.date-inputs span { color: var(--muted); }

/* Device filter */
.devicefilter { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.devicefilter .lbl { color: var(--muted); font-size: 13px; font-weight: 600; margin-right: 2px; }

/* ============================ Metric cards ============================ */
.grid { display: grid; gap: var(--gap); }
.kpis { grid-template-columns: repeat(4, 1fr); margin-bottom: var(--gap); }
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-md); padding: 18px; box-shadow: var(--shadow-sm);
}
.kpi__label { color: var(--muted); font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.kpi__value { font-size: 30px; font-weight: 800; margin-top: 6px; letter-spacing: -0.02em; }
.kpi__sub { color: var(--ink-soft); font-size: 13px; margin-top: 4px; }
.kpi__value .u { font-size: 15px; color: var(--muted); font-weight: 600; margin-left: 4px; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 5px; vertical-align: middle; }
.dot.color { background: var(--c-color); }
.dot.mono { background: var(--c-mono); }
.dot.blue { background: var(--tsb-blue); }

/* Chart cards */
.charts { grid-template-columns: repeat(12, 1fr); }
.col-4 { grid-column: span 4; }
.col-6 { grid-column: span 6; }
.col-8 { grid-column: span 8; }
.col-12 { grid-column: span 12; }
.card__head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.card__title { font-size: 15px; font-weight: 700; }
.card__hint { color: var(--muted); font-size: 12px; }
.chart-box { position: relative; height: 260px; }
.chart-box.tall { height: 320px; }

/* Tables (top users / documents) */
.rank { list-style: none; margin: 0; padding: 0; }
.rank li {
  display: grid; grid-template-columns: 22px 1fr auto; gap: 10px;
  align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line);
}
.rank li:last-child { border-bottom: none; }
.rank__pos { color: var(--muted); font-weight: 700; font-size: 13px; text-align: center; }
.rank__name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank__name small { display: block; color: var(--muted); font-weight: 500; font-size: 12px; }
.rank__val { font-weight: 700; color: var(--ink); font-variant-numeric: tabular-nums; }
.rank__val small { color: var(--muted); font-weight: 500; }
.rank__bar { grid-column: 2 / 4; height: 4px; border-radius: 999px; background: var(--surface-2); margin-top: 2px; overflow: hidden; }
.rank__bar > span { display: block; height: 100%; background: var(--tsb-red); }

.empty { text-align: center; color: var(--muted); padding: 40px 10px; }

/* Files summary strip */
.filestrip { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.filetag {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 999px; padding: 5px 12px 5px 10px; font-size: 13px;
}
.filetag .model { font-weight: 700; color: var(--tsb-red); }
.filetag .count { color: var(--muted); }
.filetag.bad { border-color: var(--err); color: var(--err); }

/* ============================ Compare mode ============================ */
.compare-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--gap); }
.period-drop {
  border: 2px dashed var(--line-strong); border-radius: var(--r-lg);
  padding: 26px; text-align: center; background: var(--surface);
  transition: border-color .18s, background .18s;
}
.period-drop.is-drag { border-color: var(--tsb-red); background: var(--tsb-red-tint); }
.period-drop.a { border-top: 4px solid var(--tsb-red); }
.period-drop.b { border-top: 4px solid var(--tsb-blue); }
.period-drop h3 { font-size: 15px; margin-bottom: 4px; }
.period-drop .badge { font-size: 12px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.period-drop.a .badge { color: var(--tsb-red); }
.period-drop.b .badge { color: var(--tsb-blue); }
.period-drop p { color: var(--muted); font-size: 13px; margin: 8px 0 0; }
.period-drop .loaded { color: var(--ink-soft); font-weight: 600; font-size: 13px; }

.cmp-kpi { display: grid; grid-template-columns: 1fr auto 1fr auto; gap: 12px; align-items: center; }
.cmp-kpi + .cmp-kpi { border-top: 1px solid var(--line); padding-top: 12px; margin-top: 12px; }
.cmp-side { font-variant-numeric: tabular-nums; }
.cmp-side .n { font-size: 22px; font-weight: 800; }
.cmp-side.a .n { color: var(--tsb-red); }
.cmp-side.b .n { color: var(--tsb-blue); }
.cmp-side .l { color: var(--muted); font-size: 12px; }
.cmp-metric { grid-column: 1 / -1; font-weight: 700; font-size: 13px; color: var(--ink-soft); }
.cmptable { width: 100%; border-collapse: collapse; }
.cmptable th, .cmptable td { padding: 11px 10px; text-align: right; font-variant-numeric: tabular-nums; }
.cmptable th { font-size: 12px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .03em; border-bottom: 1px solid var(--line); }
.cmptable td { border-bottom: 1px solid var(--line); }
.cmptable tr:last-child td { border-bottom: none; }
.cmptable .metric { text-align: left; font-weight: 600; color: var(--ink); }
.cmptable .a-val { font-weight: 800; color: var(--tsb-red); }
.cmptable .b-val { font-weight: 800; color: var(--tsb-blue); }
.cmptable .a-val small, .cmptable .b-val small { color: var(--muted); font-weight: 600; }
.cmptable td.delta-cell { text-align: center; }

.delta { font-weight: 800; font-size: 14px; padding: 3px 8px; border-radius: 999px; }
.delta.up { color: var(--ok); background: rgba(27,127,75,.10); }
.delta.down { color: var(--err); background: var(--tsb-red-tint); }
.delta.flat { color: var(--muted); background: var(--surface-2); }

/* ============================ Detail listing ========================== */
.detail-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
  margin-bottom: 14px;
}
.detail-bar .lbl { color: var(--muted); font-size: 13px; font-weight: 600; }
.detail-bar__spacer { flex: 1; }
.detail-search-wrap {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line-strong); border-radius: var(--r-sm);
  padding: 0 10px; background: var(--surface); color: var(--muted);
}
.detail-search {
  border: none; outline: none; background: transparent; font-family: inherit;
  font-size: 13px; padding: 8px 2px; width: 190px; color: var(--ink);
}
.detail-summary { color: var(--ink-soft); font-size: 13px; font-weight: 600; margin: 4px 2px 12px; }

.dtable { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.dtable thead th {
  position: sticky; top: 56px; z-index: 1; background: var(--surface);
  font-size: 12px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .02em;
  text-align: right; padding: 10px 12px; border-bottom: 1px solid var(--line);
  cursor: pointer; user-select: none; white-space: nowrap;
}
.dtable thead th.l { text-align: left; }
.dtable thead th.active { color: var(--tsb-red); }
.dtable thead th:hover { color: var(--ink); }

.dtable tbody tr.grp { cursor: pointer; }
.dtable tbody tr.grp:hover { background: var(--surface-2); }
.dtable tbody tr.grp.open { background: var(--tsb-red-tint); }
.dtable tbody tr.grp td {
  text-align: right; padding: 10px 12px; border-bottom: 1px solid var(--line);
  font-weight: 600; white-space: nowrap;
}
.dtable td.l { text-align: left; }
.dtable td.name { display: flex; align-items: center; gap: 8px; }
.dtable td.name .caret { color: var(--muted); font-size: 11px; width: 10px; }
.dtable td.grp-name, .dtable .grp-name { overflow: hidden; text-overflow: ellipsis; }
.dtable td.strong { color: var(--ink); font-weight: 800; }
.dtable .c-color { color: var(--tsb-red); }
.dtable .c-mono { color: var(--c-mono); }

.dtable tr.sub > td { padding: 0 0 0 26px; background: var(--surface-2); border-bottom: 1px solid var(--line); }

.jtable { width: 100%; border-collapse: collapse; margin: 4px 0 10px; }
.jtable th {
  font-size: 11px; color: var(--muted); font-weight: 700; text-transform: uppercase;
  text-align: right; padding: 6px 10px; border-bottom: 1px solid var(--line);
}
.jtable th.l { text-align: left; }
.jtable td {
  text-align: right; padding: 6px 10px; border-bottom: 1px solid var(--line);
  font-size: 13px; white-space: nowrap;
}
.jtable td.l { text-align: left; }
.jtable td.doc { max-width: 320px; overflow: hidden; text-overflow: ellipsis; }
.jtable td.nowrap { white-space: nowrap; color: var(--ink-soft); }
.jtable td.strong { font-weight: 800; color: var(--ink); }
.jtable tr:last-child td { border-bottom: none; }
.jtable .muted { color: var(--muted); }
.st { font-size: 12px; font-weight: 600; color: var(--ink-soft); }
.st.ok { color: var(--ok); }
.st.warn { color: var(--warn); }

@media (max-width: 640px) {
  .dtable thead th, .dtable tbody tr.grp td { padding: 8px 7px; font-size: 13px; }
  .jtable td.doc { max-width: 140px; }
  .detail-search { width: 120px; }
}

/* ============================ Instructions ============================ */
.doc { max-width: 760px; margin: 0 auto; padding: 40px 22px; flex: 1; }
.doc h1 { font-size: 30px; margin-bottom: 12px; }
.doc p { color: var(--ink-soft); }
.doc .placeholder {
  margin-top: 20px; padding: 22px; border: 1px dashed var(--line-strong);
  border-radius: var(--r-md); background: var(--surface); color: var(--muted);
}
.back-link { display: inline-flex; align-items: center; gap: 6px; margin-bottom: 20px; font-weight: 600; }

/* ============================ Responsive ============================ */
@media (max-width: 960px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .col-4, .col-6, .col-8 { grid-column: span 12; }
  .compare-grid { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .kpis { grid-template-columns: 1fr; }
  .wrap { padding: 16px; }
  .cmp-kpi { grid-template-columns: 1fr auto; }
}
