/* KingItemSync Report */
:root {
  --ink: #1c2633; --muted: #5f6b7a; --line: #d5dde8; --bg: #f3f6fa; --panel: #fff;
  --brand: #16365c; --brand2: #24548a; --green: #2e7d32; --have: #1b5e20; --blue: #1565c0; --red: #c62828;
  --miss-bg: #fde4e4; --miss: #b71c1c; --orange: #ef6c00;
  font-family: "Segoe UI", Tahoma, Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { min-height: 100%; }
body { margin: 0; color: var(--ink); background: var(--bg); font-size: 14px; display: flex; flex-direction: column; }
a { color: var(--blue); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.err { color: var(--red); }
.mono { font-family: Consolas, "Courier New", monospace; font-size: 12.5px; }
[hidden] { display: none !important; }

/* top bar */
.topbar { display: flex; align-items: center; gap: 14px; padding: 8px 16px; background: var(--brand); color: #fff; }
.topbar a { color: #cfe0f5; }
.topbar-logo { width: 40px; height: 40px; border-radius: 8px; background: #fff; }
.app-name { font-weight: 700; font-size: 18px; }
.version { font-weight: 400; font-size: 11px; color: #a9bdd6; }
.store-name { font-size: 13px; color: #d6e3f2; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 14px; }
.toplink { text-decoration: none; }
.toplink:hover { text-decoration: underline; }
.user { font-weight: 600; }

main { flex: 1; padding: 12px 16px; display: flex; flex-direction: column; gap: 12px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px 16px; }
h1 { font-size: 19px; margin: 0 0 2px; color: var(--brand); }
h3 { font-size: 15px; margin: 14px 0 6px; color: var(--brand); }
h3.miss-head { color: var(--miss); }
.run-head { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
.run-head p { margin: 0 0 8px; }
.run-actions { margin-left: auto; display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.run-status { font-size: 13px; text-align: right; max-width: 520px; }
.warn { background: #fff3e0; border: 1px solid #ffcc80; border-radius: 6px; padding: 8px 12px; margin: 6px 0; color: #7a3d00; }

.btn { font: inherit; font-weight: 700; border: 2px solid transparent; border-radius: 6px; padding: 7px 14px; cursor: pointer; color: #fff; line-height: 1.2; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-small { padding: 4px 10px; font-size: 12px; }
.btn-primary { background: var(--brand2); border-color: var(--brand); padding: 9px 22px; font-size: 15px; }
.btn-green { background: var(--green); border-color: #1b5e20; }
.btn-red { background: var(--red); border-color: #8e1b1b; }
.btn-plain { background: #fff; color: var(--ink); border: 1px solid #b9c4d2; font-weight: 600; }
.btn:not(:disabled):hover { filter: brightness(1.08); }

/* devices */
.devices { border-collapse: collapse; width: 100%; font-size: 13px; margin-top: 6px; }
.devices th { text-align: left; font-size: 12px; color: var(--muted); border-bottom: 2px solid var(--line); padding: 5px 8px; white-space: nowrap; }
.devices td { padding: 5px 8px; border-bottom: 1px solid #edf1f6; vertical-align: top; }
.devices tr.central td { background: #f1f5fb; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.devices th.num { text-align: right; }
.pill { display: inline-block; border-radius: 10px; padding: 1px 8px; font-size: 11.5px; font-weight: 700; }
.pill.central { background: var(--brand); color: #fff; }
.pill.only { background: #fff3e0; color: #8a4b00; }
.state { font-weight: 600; font-size: 12.5px; }
.state.waiting { color: var(--muted); }
.state.connecting, .state.reading { color: var(--blue); }
.state.done { color: var(--have); }
.state.error { color: var(--red); }
.spinner { display: inline-block; width: 12px; height: 12px; border: 2px solid #b9c9de; border-top-color: var(--brand2); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* results */
.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--line); margin-bottom: 10px; }
.tab { font: inherit; font-weight: 600; background: none; border: 0; border-bottom: 3px solid transparent; margin-bottom: -2px; padding: 8px 14px; cursor: pointer; color: var(--muted); }
.tab.on { color: var(--brand); border-bottom-color: var(--brand2); }
.count { display: inline-block; min-width: 22px; padding: 0 7px; border-radius: 10px; background: #e3eaf4; color: var(--brand); font-size: 12px; text-align: center; }
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 6px; }
.filters label { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; color: var(--brand); }
.filters .grow { flex: 1; min-width: 220px; }
.filters .grow input { flex: 1; }
.filters .spacer { flex: 0; }
.check { cursor: pointer; }
select, input[type=search] { font: inherit; padding: 5px 7px; border: 1px solid #b9c4d2; border-radius: 5px; background: #fff; }
select { max-width: 260px; }
.view-note { font-size: 13px; margin: 4px 0 8px; }
.grid-wrap { overflow: auto; max-height: calc(100vh - 220px); }
.grid { border-collapse: separate; border-spacing: 0; width: max-content; min-width: 100%; font-size: 13px; }
.grid th { position: sticky; top: 0; z-index: 1; background: #e9eff7; border-bottom: 2px solid #b9c4d2; padding: 6px 8px; text-align: left; white-space: nowrap; font-size: 12px; }
.grid td { padding: 3px 8px; border-bottom: 1px solid #edf1f6; white-space: nowrap; }
.grid tbody tr:hover td { background: #eef4fb; }
.grid th.dev, .grid td.dev { text-align: center; min-width: 46px; }
.grid td.have { color: var(--have); font-weight: 700; }
.grid td.miss { background: var(--miss-bg); color: var(--miss); font-weight: 700; }
.empty { padding: 24px; text-align: center; color: var(--muted); }
.more { display: flex; gap: 10px; align-items: center; padding: 10px 4px; }
.foot { text-align: center; padding: 8px; }

/* Yellow help box on controls (data-tip), as in the other King apps. */
[data-tip] { position: relative; }
[data-tip]::after {
  content: attr(data-tip); position: absolute; left: 0; top: calc(100% + 6px); z-index: 50;
  width: max-content; max-width: 300px; padding: 7px 10px; border: 1px solid #d4b106; border-radius: 6px;
  background: #fff8c5; color: #3d3300; font: 400 12.5px/1.4 "Segoe UI", Tahoma, Arial, sans-serif;
  text-align: left; white-space: normal; box-shadow: 0 4px 14px rgba(0,0,0,.18);
  opacity: 0; visibility: hidden; pointer-events: none; transition: opacity .12s;
}
[data-tip]:hover::after, [data-tip]:focus-visible::after { opacity: 1; visibility: visible; transition-delay: .35s; }
[data-tip].tip-right::after { left: auto; right: 0; }

/* sign-in */
.signin-page { min-height: 100vh; align-items: center; justify-content: center; background: linear-gradient(160deg, #16365c, #24548a); }
.signin-card { background: #fff; border-radius: 12px; padding: 28px 30px; width: min(380px, 92vw); text-align: center; box-shadow: 0 12px 40px rgba(0,0,0,.3); display: flex; flex-direction: column; gap: 6px; }
.signin-card h1 { margin: 4px 0 0; font-size: 22px; }
.signin-logo { width: 72px; height: 72px; margin: 0 auto; }
.signin-card form { display: flex; flex-direction: column; gap: 8px; text-align: left; margin-top: 10px; }
.signin-card input { font-size: 16px; padding: 8px 10px; border: 1px solid #b9c4d2; border-radius: 6px; }
.signin-card .btn { padding: 9px; }
.alert { background: #fde4e4; color: var(--red); border-radius: 6px; padding: 7px 10px; margin-top: 8px; font-size: 13px; }

@media (max-width: 900px) {
  .topbar { flex-wrap: wrap; }
  .topbar-right { margin-left: 0; }
  .run-actions { margin-left: 0; align-items: flex-start; }
}
@media print {
  .topbar-right, .filters, .tabs, .more, #btnRun, .foot { display: none !important; }
  body { background: #fff; }
  .grid-wrap { max-height: none; overflow: visible; }
  .grid th { position: static; }
  .grid tr { break-inside: avoid; }
}
