/* Layout and components. Colors, fonts, corners and shadows all come from tokens in themes.css. */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--fl-bg2); color: var(--fl-fg1); padding: 16px; min-height: 100vh; }
@media (max-width: 40rem) { body { padding: 4px; } }

.sp {
  font-family: var(--fl-font); font-size: 14px; line-height: 20px; color: var(--fl-fg1);
  padding: 8px 8px 24px; display: grid; gap: 20px; max-width: 86rem; margin-inline: auto;
}
@media (max-width: 40rem) { .sp { padding: 8px; gap: 16px; } }
.sp :is(h1, h2, h3, p, ul) { margin: 0; }
.sp b, .sp strong { font-weight: 600; }
.sp [hidden] { display: none !important; }
.sp a { color: var(--fl-brand-mark); }

/* Header */
.sp-head { display: grid; gap: 12px; }
.sp-brandrow { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.sp-brandrow > .sp-titles { flex: 1 1 12rem; min-width: 0; }
.sp-logo { width: 40px; height: 40px; border-radius: var(--fl-r-lg); background: var(--fl-brand); color: var(--fl-on-brand); display: inline-flex; align-items: center; justify-content: center; flex: none; box-shadow: var(--fl-shadow2); }
.sp-logo svg { width: 26px; height: 26px; }
.sp-title { font-family: var(--fl-font-display); font-weight: 600; font-size: var(--fl-title-size); line-height: 1.25; letter-spacing: var(--fl-title-track); text-wrap: balance; }
.sp-eyebrow { font-size: 12px; line-height: 16px; color: var(--fl-fg2); }
.sp-take { color: var(--fl-fg2); max-width: 75ch; }
.sp .sp-take b { color: var(--fl-fg1); font-variant-numeric: tabular-nums; }
.sp-status { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; font-size: 12px; line-height: 16px; color: var(--fl-fg2); }
.sp-status .sp-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--color-ok); display: inline-block; margin-right: 6px; }
.sp-status .sp-dot.sp-busy { background: var(--color-warn); animation: sp-pulse 1s ease-in-out infinite; }
.sp-status .sp-dot.sp-err { background: var(--color-bad); }
@keyframes sp-pulse { 50% { opacity: 0.35; } }
.sp-linkbtn { font: inherit; font-weight: 600; color: var(--fl-brand-mark); background: none; border: 0; padding: 2px 4px; margin: -2px -4px; border-radius: var(--fl-r-md); cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.sp-linkbtn:hover { text-decoration-thickness: 2px; }

/* Theme switch */
.sp-mode { display: inline-flex; flex: none; flex-wrap: wrap; padding: 2px; gap: 2px; border-radius: var(--fl-r-md); border: 1px solid var(--fl-stroke1); background: var(--fl-bg1); align-self: center; }
.sp-modebtn { font: inherit; font-size: 12px; line-height: 16px; font-weight: 600; display: inline-flex; align-items: center; gap: 4px; min-height: 28px; padding: 4px 10px; border: 0; border-radius: var(--fl-r-sm); background: transparent; color: var(--fl-fg2); cursor: pointer; white-space: nowrap; }
.sp-modebtn svg { width: 16px; height: 16px; flex: none; }
.sp-modebtn:hover { background: var(--fl-bg-hover); color: var(--fl-fg1); }
.sp-modebtn[aria-pressed="true"] { background: var(--fl-brand); color: var(--fl-on-brand); }
.sp-mode-sep { width: 1px; align-self: stretch; margin: 4px 2px; background: var(--fl-stroke2); }
@media (max-width: 56rem) { .sp-modebtn span { display: none; } .sp-modebtn { padding: 4px 8px; } }

/* Buttons */
.sp-btn { font: inherit; font-size: 14px; line-height: 20px; font-weight: 600; min-height: 32px; padding: 5px 12px; border-radius: var(--fl-r-md); border: 1px solid var(--fl-stroke1); background: var(--fl-bg1); color: var(--fl-fg1); cursor: pointer; display: inline-flex; align-items: center; gap: 8px; }
.sp-btn:hover { background: var(--fl-bg-hover); }
.sp-btn.sp-primary { background: var(--fl-brand); border-color: transparent; color: var(--fl-on-brand); min-height: 40px; padding: 8px 20px; }
.sp-btn.sp-primary:hover { background: var(--fl-brand-hover); }
.sp-btn svg { width: 18px; height: 18px; flex: none; }
.sp :is(.sp-chip, .sp-tab, .sp-sort, .sp-clip, .sp-btn, .sp-linkbtn, .sp-modebtn, .sp-calbtn, .sp-calbill, .sp-node, .sp-q, .sp-sortsel):focus-visible { outline: 2px solid var(--fl-fg1); outline-offset: 1px; }

/* Sign-in gate */
.sp-gate { background: var(--fl-bg1); border: var(--fl-card-border); border-radius: var(--fl-r-lg); box-shadow: var(--fl-shadow4); padding: 32px 24px; display: grid; gap: 12px; justify-items: start; max-width: 40rem; }
.sp-gate h2 { font-family: var(--fl-font-display); font-size: 20px; line-height: 28px; font-weight: 600; }
.sp-gate p { color: var(--fl-fg2); max-width: 60ch; }
.sp-gate code { font-size: 13px; background: var(--fl-bg-subtle); padding: 1px 5px; border-radius: var(--fl-r-sm); border: 1px solid var(--fl-stroke2); }

/* TabList */
.sp-tabs { display: flex; flex-wrap: wrap; gap: 4px; border-bottom: 1px solid var(--fl-stroke2); }
.sp-tab { position: relative; font: inherit; font-size: 14px; line-height: 20px; color: var(--fl-fg2); background: transparent; border: 0; border-radius: var(--fl-r-md); padding: 10px 12px 12px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.sp-tab svg { width: 20px; height: 20px; flex: none; }
.sp-tab:hover { color: var(--fl-fg1); background: var(--fl-bg-hover); }
.sp-tab::after { content: ""; position: absolute; left: 12px; right: 12px; bottom: -1px; height: 3px; border-radius: 3px 3px 0 0; background: transparent; }
.sp-tab:hover::after { background: var(--fl-stroke1); }
.sp-tab[aria-selected="true"] { color: var(--fl-fg1); font-weight: 600; }
.sp-tab[aria-selected="true"]::after { background: var(--fl-brand-mark); }
.sp-tabgap { width: 1px; align-self: center; height: 20px; background: var(--fl-stroke2); margin-inline: 6px; }

/* Toolbar with toggle buttons */
.sp-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.sp-toolbar-label { font-size: 12px; line-height: 16px; color: var(--fl-fg2); margin-right: 4px; }
.sp-filter { display: flex; flex-wrap: wrap; gap: 4px; }
.sp-chip { font: inherit; font-size: 14px; line-height: 20px; font-weight: 600; min-height: 32px; padding: 5px 12px; border-radius: var(--fl-r-md); border: 1px solid var(--fl-stroke1); background: var(--fl-bg1); color: var(--fl-fg1); cursor: pointer; }
.sp-chip:hover { background: var(--fl-bg-hover); }
.sp-chip:active { background: var(--fl-bg-pressed); }
.sp-chip[aria-pressed="true"] { background: var(--fl-brand); border-color: transparent; color: var(--fl-on-brand); }
.sp-chip[aria-pressed="true"]:hover { background: var(--fl-brand-hover); }
.sp-chip small { font-weight: 400; opacity: 0.8; margin-left: 4px; font-variant-numeric: tabular-nums; }

/* Panels */
.sp-panel { display: grid; gap: 16px; align-content: start; min-width: 0; }
#app-body { display: grid; gap: 20px; min-width: 0; }

/* Cards */
.sp-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 13rem), 1fr)); gap: 16px; }
.sp-tile { background: var(--fl-bg1); border: var(--fl-card-border); border-radius: var(--fl-r-lg); box-shadow: var(--fl-shadow4); padding: 16px; display: grid; gap: 4px; align-content: start; min-width: 0; }
.sp-label { font-family: var(--fl-font-label); font-size: 14px; line-height: 20px; font-weight: 600; color: var(--fl-fg2); }
.sp-big { font-family: var(--fl-font-display); font-weight: 600; font-size: 28px; line-height: 36px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; color: var(--fl-fg1); }
.sp-note { font-size: 12px; line-height: 16px; color: var(--fl-fg2); }
.sp-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 26rem), 1fr)); gap: 16px; }
.sp-card { background: var(--fl-bg1); border: var(--fl-card-border); border-radius: var(--fl-r-lg); box-shadow: var(--fl-shadow4); padding: 16px 20px 20px; display: grid; gap: 12px; align-content: start; min-width: 0; }
.sp-card h2 { font-size: 16px; line-height: 22px; font-weight: 600; }
.sp-card h3 { font-size: 14px; line-height: 20px; font-weight: 600; }
.sp-cardhead { display: grid; gap: 2px; }
.sp-sub { display: grid; gap: 8px; align-content: start; min-width: 0; }

/* Loading shimmer */
.dash-skeleton { border-radius: var(--fl-r-md); background: linear-gradient(90deg, var(--fl-bg-subtle) 25%, var(--fl-bg-pressed) 50%, var(--fl-bg-subtle) 75%); background-size: 200% 100%; animation: sp-shimmer 1.4s linear infinite; }
b.dash-skeleton, span.dash-skeleton { color: transparent !important; }
@keyframes sp-shimmer { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .dash-skeleton, .sp-dot.sp-busy { animation: none; } }

/* Charts */
.sp-chart { position: relative; min-height: 18rem; }
.sp-chart.sp-tall { min-height: 22rem; }
.sp-chart.sp-short { min-height: 9rem; }
.sp-chart svg { display: block; }
.sp-chart svg text { font-family: var(--fl-font); }
.sp-legend { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 12px; line-height: 16px; color: var(--fl-fg2); padding: 0; list-style: none; }
.sp-legend li { display: flex; align-items: center; gap: 6px; }
.sp-sw { width: 10px; height: 10px; border-radius: var(--fl-r-sm); display: inline-block; flex: none; }
.sp-sw-0 { background: var(--sp-c0); } .sp-sw-1 { background: var(--sp-c1); } .sp-sw-2 { background: var(--sp-c2); } .sp-sw-3 { background: var(--sp-c3); } .sp-sw-4 { background: var(--sp-c4); }
.sp-sw-in { background: var(--sp-bin); } .sp-sw-out { background: var(--sp-bout); }
.sp-tip { position: absolute; pointer-events: none; background: var(--fl-bg1); border: 1px solid var(--fl-stroke2); border-radius: var(--fl-r-md); box-shadow: var(--fl-shadow16); padding: 8px 12px; font-size: 12px; line-height: 16px; white-space: nowrap; z-index: 2; display: grid; gap: 4px; }
.sp-tip .sp-tip-h { color: var(--fl-fg1); font-weight: 600; }
.sp-tip .sp-tip-r { display: flex; align-items: center; gap: 6px; font-variant-numeric: tabular-nums; color: var(--fl-fg2); }
.sp-fail { display: flex; align-items: center; justify-content: center; gap: 8px; height: 100%; min-height: inherit; color: var(--fl-fg2); font-size: 12px; }
.sp-fail span:first-child { width: 6px; height: 6px; border-radius: 50%; background: var(--color-bad); }

/* DataGrid */
.sp-tablebox { max-height: 32rem; overflow: auto; border: 1px solid var(--fl-stroke2); border-radius: var(--fl-r-md); }
.sp-table { width: 100%; border-collapse: collapse; font-size: 14px; line-height: 20px; font-variant-numeric: tabular-nums; }
.sp-table th { position: sticky; top: 0; background: var(--fl-bg1); text-align: left; font-weight: 600; color: var(--fl-fg1); padding: 10px 12px; border-bottom: 1px solid var(--fl-stroke1); z-index: 1; white-space: nowrap; }
.sp-table td { padding: 10px 12px; border-bottom: 1px solid var(--fl-stroke2); vertical-align: middle; }
.sp-table tbody tr:last-child td { border-bottom: 0; }
.sp-table tbody tr:hover { background: var(--fl-bg-hover); }
.sp-table .sp-num { text-align: right; white-space: nowrap; }
.sp-table td.sp-item { min-width: 12rem; }
.sp-table td.sp-muted { color: var(--fl-fg2); }
.sp-table td.sp-empty { color: var(--fl-fg2); text-align: center; padding: 24px 12px; }
.sp-neg { color: var(--color-ok); }
.sp-sort { font: inherit; font-weight: 600; color: inherit; background: none; border: 0; padding: 2px 4px; margin: -2px -4px; border-radius: var(--fl-r-md); cursor: pointer; text-transform: inherit; }
.sp-sort:hover { background: var(--fl-bg-hover); }
th[aria-sort="ascending"] .sp-sort::after { content: " \2191"; color: var(--fl-fg2); }
th[aria-sort="descending"] .sp-sort::after { content: " \2193"; color: var(--fl-fg2); }
.sp-bar { display: block; height: 4px; border-radius: 2px; background: var(--fl-brand-mark); margin-top: 4px; }

/* SearchBox */
.sp-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; justify-content: space-between; }
.sp-search { position: relative; display: flex; align-items: center; width: min(100%, 20rem); }
.sp-search svg { position: absolute; left: 10px; width: 16px; height: 16px; color: var(--fl-fg2); pointer-events: none; }
.sp-q { font: inherit; font-size: 14px; line-height: 20px; width: 100%; min-height: 32px; padding: 5px 10px 5px 32px; border: 1px solid var(--fl-stroke1); border-bottom-color: color-mix(in srgb, var(--color-fg) 45%, var(--color-panel)); border-radius: var(--fl-r-md); background: var(--fl-bg1); color: var(--fl-fg1); min-width: 0; outline: none; }
.sp-q:focus { border-bottom: 2px solid var(--fl-brand-mark); padding-bottom: 4px; }
.sp-q::placeholder { color: var(--fl-fg2); }

/* Document column and preview */
.sp-table th.sp-doc, .sp-table td.sp-doc { width: 2.5rem; text-align: center; padding-left: 4px; padding-right: 8px; }
.sp-clip { display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; border-radius: var(--fl-r-md); color: var(--fl-fg2); }
.sp-clip:hover { color: var(--fl-brand-mark); background: var(--fl-bg-pressed); }
.sp-clip svg { width: 16px; height: 16px; }
.sp-vh { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.sp-prev { position: fixed; z-index: 50; width: 15rem; pointer-events: none; background: var(--fl-bg1); border: 1px solid var(--fl-stroke2); border-radius: var(--fl-r-lg); box-shadow: var(--fl-shadow16); padding: 8px; }
.sp-prev img { display: block; width: 100%; height: auto; background: #fff; border-radius: var(--fl-r-md); }
.sp-prev p { margin: 8px 2px 2px; font-size: 12px; line-height: 16px; color: var(--fl-fg2); overflow-wrap: anywhere; text-align: left; }
.sp-prev .sp-prev-wait { height: 6rem; }

/* MessageBar */
.sp-msg { display: flex; gap: 8px; align-items: flex-start; padding: 8px 12px; border-radius: var(--fl-r-md); border: 1px solid var(--fl-stroke2); background: var(--fl-bg-subtle); font-size: 12px; line-height: 16px; color: var(--fl-fg1); }
.sp-msg svg { width: 16px; height: 16px; flex: none; color: var(--fl-brand-mark); margin-top: 0; }
.sp-msg.sp-warn svg { color: var(--color-warn); }
.sp-msg.sp-error { border-color: var(--color-bad); }
.sp-msg.sp-error svg { color: var(--color-bad); }
.sp-foot { font-size: 12px; line-height: 16px; color: var(--fl-fg2); max-width: 90ch; }

/* Subscriptions (Wallos-style list) */
.sp-subbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; justify-content: space-between; }
.sp-subbar .sp-toolbar { gap: 8px; }
.sp-sortsel { font: inherit; font-size: 14px; min-height: 32px; padding: 4px 8px; border-radius: var(--fl-r-md); background-color: var(--fl-bg1); color: var(--fl-fg1); border: 1px solid var(--fl-stroke1); }
.sp-subtable td { padding-top: 8px; padding-bottom: 8px; }
.sp-subname { display: flex; align-items: center; gap: 12px; min-width: 12rem; }
.sp-subname a { color: var(--fl-fg1); text-decoration: none; font-weight: 600; }
.sp-subname a:hover { text-decoration: underline; }
.sp-subname small { display: block; font-size: 12px; line-height: 16px; color: var(--fl-fg2); font-weight: 400; }
.sp-mono { width: 36px; height: 36px; border-radius: var(--fl-r-lg); color: #fff; font-weight: 600; font-size: 13px; display: inline-flex; align-items: center; justify-content: center; flex: none; letter-spacing: .02em; }
.sp-subtable tr.sp-off td { opacity: .55; }
.sp-badge { display: inline-block; font-size: 12px; line-height: 16px; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--fl-stroke2); color: var(--fl-fg2); white-space: nowrap; }
.sp-badge.sp-on { color: var(--color-ok); border-color: color-mix(in srgb, var(--color-ok) 40%, transparent); }
.sp-due { color: var(--fl-fg2); font-size: 12px; line-height: 16px; display: block; }
.sp-due.sp-soon { color: var(--fl-brand-mark); font-weight: 600; }

/* Bill calendar */
.sp-calhead { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; }
.sp-calnav { display: flex; align-items: center; gap: 4px; }
.sp-calbtn { font: inherit; font-size: 14px; line-height: 20px; font-weight: 600; min-height: 32px; min-width: 32px; padding: 5px 10px; display: inline-flex; align-items: center; justify-content: center; border: 1px solid var(--fl-stroke1); border-radius: var(--fl-r-md); background: var(--fl-bg1); color: var(--fl-fg1); cursor: pointer; }
.sp-calbtn svg { width: 16px; height: 16px; }
.sp-calbtn:hover { background: var(--fl-bg-hover); }
.sp-calbtn:disabled { opacity: .4; cursor: default; background: var(--fl-bg1); }
.sp-calmonth { font-family: var(--fl-font-display); font-size: 20px; line-height: 28px; font-weight: 600; min-width: 10ch; padding-inline: 8px; }
.sp-calsum { font-size: 12px; line-height: 16px; color: var(--fl-fg2); }
.sp-calsum b { color: var(--fl-fg1); font-variant-numeric: tabular-nums; }
.sp-calwrap { container-type: inline-size; display: grid; gap: 4px; }
.sp-calwk { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; font-size: 12px; line-height: 16px; font-weight: 600; color: var(--fl-fg2); padding-inline: 6px; }
@container (max-width: 36rem) { .sp-calwk { display: none; } }
.sp-cal { position: relative; min-height: 12rem; }
.sp-calgrid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.sp-calday { min-height: 6.5rem; min-width: 0; border: 1px solid var(--fl-stroke2); border-radius: var(--fl-r-md); background: var(--fl-bg1); padding: 4px; display: flex; flex-direction: column; gap: 3px; }
.sp-calday.sp-blank { background: transparent; border-style: dashed; opacity: .5; }
.sp-calday.sp-past { background: var(--fl-bg-subtle); }
.sp-calday.sp-past .sp-calbill { opacity: .6; }
.sp-calday.sp-today { border-color: var(--fl-brand-mark); box-shadow: inset 0 0 0 1px var(--fl-brand-mark); }
.sp-calnum { font-size: 12px; line-height: 16px; font-weight: 600; color: var(--fl-fg2); padding: 2px 4px; display: flex; justify-content: space-between; gap: 4px; }
.sp-calnum em { font-style: normal; font-weight: 400; font-variant-numeric: tabular-nums; }
.sp-calday.sp-today .sp-calnum > span:first-child { color: var(--fl-on-brand); background: var(--fl-brand); border-radius: 999px; padding: 0 6px; }
.sp-calbills { display: grid; gap: 3px; }
.sp-calbill { display: flex; align-items: center; gap: 6px; min-width: 0; font-size: 12px; line-height: 16px; padding: 3px 6px; border-radius: var(--fl-r-sm); background: var(--fl-bg-pressed); color: var(--fl-fg1) !important; text-decoration: none; border-left: 3px solid var(--sp-billc, var(--fl-brand-mark)); }
.sp-calbill:hover { background: color-mix(in srgb, var(--color-fg) 14%, var(--color-panel)); }
.sp-calbill .sp-bn { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sp-calbill .sp-ba { flex: none; font-variant-numeric: tabular-nums; color: var(--fl-fg2); }
.sp-callist { display: grid; gap: 8px; }
.sp-callist .sp-calday { min-height: 0; flex-direction: row; align-items: flex-start; gap: 8px; padding: 8px; }
.sp-callist .sp-calnum { flex: none; width: 6.5rem; flex-direction: column; font-size: 14px; line-height: 20px; color: var(--fl-fg1); padding: 2px 0; }
.sp-callist .sp-calday.sp-today .sp-calnum > span:first-child { align-self: flex-start; }
.sp-callist .sp-calbills { flex: 1 1 auto; min-width: 0; gap: 4px; }
.sp-callist .sp-calbill { font-size: 14px; line-height: 20px; padding: 4px 8px; }
.sp-calempty { color: var(--fl-fg2); padding: 24px 0; text-align: center; }

/* Assets: location tree */
.sp-tree, .sp-tree ul { list-style: none; margin: 0; padding: 0; }
.sp-tree ul { margin-left: 13px; padding-left: 12px; border-left: 1px solid var(--fl-stroke2); }
.sp-node { font: inherit; width: 100%; display: flex; align-items: center; gap: 8px; text-align: left; min-height: 32px; padding: 4px 8px; border: 0; border-radius: var(--fl-r-md); background: transparent; color: var(--fl-fg1); cursor: pointer; }
.sp-node:hover { background: var(--fl-bg-hover); }
.sp-node[aria-pressed="true"] { background: var(--fl-brand); color: var(--fl-on-brand); }
.sp-node svg { width: 18px; height: 18px; flex: none; opacity: 0.8; }
.sp-node .sp-node-name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.sp-node .sp-node-n { flex: none; font-size: 12px; font-variant-numeric: tabular-nums; opacity: 0.8; }
.sp-crumb { color: var(--fl-fg2); font-size: 12px; line-height: 16px; display: block; }
.sp-assetname a { color: var(--fl-fg1); text-decoration: none; font-weight: 600; }
.sp-assetname a:hover { text-decoration: underline; }
.sp-assetname small { display: block; font-size: 12px; line-height: 16px; color: var(--fl-fg2); font-weight: 400; }
.sp-assetgrid { display: grid; grid-template-columns: minmax(16rem, 1fr) minmax(0, 2.2fr); gap: 16px; align-items: start; }
@media (max-width: 60rem) { .sp-assetgrid { grid-template-columns: minmax(0, 1fr); } }

@media (max-width: 40rem) { .sp-hide-sm { display: none; } .sp-tab svg { display: none; } .sp-table td.sp-item { min-width: 8rem; } .sp-subname { min-width: 9rem; } .sp-table th, .sp-table td { padding-left: 8px; padding-right: 8px; } }
