/* UNIWISE shared components.  Requires theme.css.  Class prefix: u-  (page CSS must not restyle these). */

/* ---------- Header ---------- */
.u-header { position: sticky; top: 0; z-index: 40; background: rgba(255,255,255,0.86); backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid var(--u-line); }
.u-header__inner { max-width: var(--u-max); margin: 0 auto; padding: 12px clamp(14px, 2.6vw, 40px); display: flex; align-items: center; gap: var(--u-s4); }
.u-brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.u-logo { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 21px;
  background: linear-gradient(140deg, #ff8a4c 0%, var(--u-orange) 45%, var(--u-orange-600) 100%);
  box-shadow: 0 8px 18px -6px rgba(242,101,34,0.55), inset 0 1px 0 rgba(255,255,255,0.35); }
.u-brand strong { display: block; font-size: 16px; letter-spacing: 0.16em; color: var(--u-ink); line-height: 1.1; }
.u-brand small { display: block; font-size: 10.5px; letter-spacing: 0.12em; color: var(--u-muted); font-weight: 600; text-transform: uppercase; }
.u-nav { display: flex; gap: 4px; margin-left: var(--u-s4); }
.u-nav a { text-decoration: none; color: var(--u-text-2); font-weight: 600; font-size: var(--u-fs-sm); padding: 6px 12px; border-radius: var(--u-r-pill); }
.u-nav a:hover { background: var(--u-surface-sunk); }
.u-nav a[aria-current="page"] { background: var(--u-ink); color: #fff; }
.u-header__right { margin-left: auto; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.u-clock { font-weight: 600; font-size: var(--u-fs-sm); color: var(--u-ink); padding: 4px 10px; }

/* ---------- Tags / chips ---------- */
.u-tag { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--u-line-strong); background: var(--u-surface-soft); color: var(--u-text-2);
  border-radius: var(--u-r-pill); padding: 3px 11px; font-size: var(--u-fs-xs); font-weight: 700; letter-spacing: 0.04em; white-space: nowrap; }
.u-tag--orange { background: var(--u-orange-50); color: var(--u-orange-700); border-color: #fdc9a8; }
.u-tag--dark { background: var(--u-ink); color: #fff; border-color: var(--u-ink); }
.u-tag--good { background: var(--u-good-bg); color: var(--u-good); border-color: #a7e3bb; }
.u-tag--bad { background: var(--st-blocked-bg); color: var(--st-blocked-fg); border-color: #f8b4b4; }
.u-tag__dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

.u-chip { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: var(--u-r-pill); font-size: 12px; font-weight: 700; white-space: nowrap; }
.u-chip::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.u-chip--working { background: var(--st-working-bg); color: var(--st-working-fg); }
.u-chip--idle { background: var(--st-idle-bg); color: var(--st-idle-fg); }
.u-chip--meeting { background: var(--st-meeting-bg); color: var(--st-meeting-fg); }
.u-chip--waiting { background: var(--st-waiting-bg); color: var(--st-waiting-fg); }
.u-chip--rest { background: var(--st-rest-bg); color: var(--st-rest-fg); }
.u-chip--blocked { background: var(--st-blocked-bg); color: var(--st-blocked-fg); }
.u-chip--training { background: var(--st-training-bg); color: var(--st-training-fg); }
.u-chip--offline { background: var(--st-offline-bg); color: var(--st-offline-fg); }
.u-source { font-size: 11px; font-weight: 600; color: var(--u-muted); border: 1px dashed var(--u-line-strong); border-radius: var(--u-r-pill); padding: 1px 8px; white-space: nowrap; }
.u-source--schedule { color: var(--u-orange-700); border-color: #fdc9a8; background: var(--u-orange-50); border-style: solid; }

/* ---------- Buttons (UI only — view toggles, never actions) ---------- */
.u-btn { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--u-line-strong); background: var(--u-surface); color: var(--u-ink);
  border-radius: 10px; padding: 7px 13px; font-size: var(--u-fs-sm); font-weight: 600; cursor: pointer; box-shadow: var(--u-shadow-1);
  transition: background .15s, border-color .15s, transform .1s; }
.u-btn:hover { border-color: var(--u-orange); }
.u-btn:active { transform: scale(0.98); }
.u-btn--ghost { box-shadow: none; background: transparent; }
.u-btn svg { width: 16px; height: 16px; }

/* ---------- Card ---------- */
.u-card { background: var(--u-surface); border: 1px solid var(--u-line); border-radius: var(--u-r-lg); box-shadow: var(--u-shadow-2); padding: var(--u-s5); min-width: 0; }
.u-card__head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--u-s3); margin-bottom: var(--u-s4); flex-wrap: wrap; }
.u-card__head h2 { margin-top: 2px; }

/* ---------- KPI ---------- */
.u-kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--u-s4); }
.u-kpi { position: relative; overflow: hidden; background: var(--u-surface); border: 1px solid var(--u-line); border-radius: var(--u-r-md); padding: 14px 18px; box-shadow: var(--u-shadow-1); }
.u-kpi::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 3px; background: var(--kpi-accent, var(--u-orange)); }
.u-kpi__label { font-size: 12px; font-weight: 700; color: var(--u-muted); letter-spacing: 0.02em; }
.u-kpi__value { font-size: 30px; font-weight: 700; color: var(--u-ink); line-height: 1.15; font-variant-numeric: tabular-nums; }
.u-kpi__sub { font-size: 12px; color: var(--u-muted); }

/* ---------- Alert list ---------- */
.u-alerts { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.u-alert { display: grid; grid-template-columns: auto 1fr; gap: 10px; align-items: start; padding: 10px 12px; border-radius: var(--u-r-md);
  background: var(--u-surface-soft); border: 1px solid var(--u-line); border-left: 4px solid var(--u-line-strong); }
.u-alert--bad { border-left-color: var(--st-blocked-fg); background: #fff8f8; }
.u-alert--warn { border-left-color: var(--st-waiting-fg); background: #fffcf3; }
.u-alert--info { border-left-color: var(--u-orange); }
.u-alert__badge { font-size: 11px; font-weight: 700; border-radius: 6px; padding: 1px 7px; background: var(--u-surface-sunk); color: var(--u-text-2); white-space: nowrap; }
.u-alert--bad .u-alert__badge { background: var(--st-blocked-bg); color: var(--st-blocked-fg); }
.u-alert--warn .u-alert__badge { background: var(--st-waiting-bg); color: var(--st-waiting-fg); }
.u-alert__title { font-weight: 600; font-size: var(--u-fs-sm); color: var(--u-ink); }
.u-alert__detail { font-size: 12px; color: var(--u-muted); }
.u-empty { font-size: var(--u-fs-sm); color: var(--u-muted); padding: 10px 12px; border: 1px dashed var(--u-line-strong); border-radius: var(--u-r-md); background: var(--u-surface-soft); }

/* ---------- Meter (quota / health bars) ---------- */
.u-meters { display: grid; gap: 10px; }
.u-meter { display: grid; grid-template-columns: 74px 1fr auto; align-items: center; gap: 10px; font-size: 12.5px; }
.u-meter__label { font-weight: 700; color: var(--u-text-2); }
.u-meter__track { height: 8px; border-radius: var(--u-r-pill); background: var(--u-surface-sunk); overflow: hidden; box-shadow: inset 0 1px 1px rgba(0,0,0,0.05); }
.u-meter__fill { height: 100%; width: 0; border-radius: inherit; background: linear-gradient(90deg, #ff9a62, var(--u-orange)); transition: width .8s var(--u-ease); }
.u-meter--warn .u-meter__fill { background: linear-gradient(90deg, #f59e0b, #d97706); }
.u-meter--bad .u-meter__fill { background: linear-gradient(90deg, #ef4444, #b91c1c); }
.u-meter--none .u-meter__track { background: repeating-linear-gradient(45deg, var(--u-surface-sunk) 0 6px, #e9ecf0 6px 12px); }
.u-meter__value { font-weight: 700; color: var(--u-ink); font-variant-numeric: tabular-nums; min-width: 64px; text-align: right; }
.u-meter--none .u-meter__value { color: var(--u-muted); font-weight: 600; }

/* ---------- Character sprite + speech bubble ---------- */
.u-sprite { position: absolute; height: var(--sprite-h, 16%); aspect-ratio: 0.42; transform: translate(-50%, -100%);
  transition: left var(--walk-ms, 2400ms) cubic-bezier(.45,.05,.4,1), top var(--walk-ms, 2400ms) cubic-bezier(.45,.05,.4,1);
  cursor: pointer; z-index: var(--z, 10); }
.u-sprite__body { position: absolute; inset: 0; transform-origin: 50% 100%; }
.u-sprite__img { width: 100%; height: 100%; object-fit: contain; object-position: 50% 100%; display: block; user-select: none; -webkit-user-drag: none;
  filter: drop-shadow(0 2px 2px rgba(17,24,39,0.22)); transform-origin: 50% 100%; }
.u-sprite__shadow { position: absolute; left: 18%; right: 18%; bottom: -2%; height: 5%; border-radius: 50%; background: rgba(17,24,39,0.18); filter: blur(1px); }
.u-sprite__name { position: absolute; top: 101%; left: 50%; transform: translateX(-50%); white-space: nowrap; font-size: clamp(8px, .72cqw, 13px); font-weight: 700;
  color: #fff; background: rgba(38,45,54,0.9); border-radius: 6px; padding: 0 .55em; line-height: 1.6; box-shadow: var(--u-shadow-1); }
.u-sprite.is-working .u-sprite__name { background: var(--u-orange); }
.u-sprite.is-meeting .u-sprite__name { background: #6d28d9; }
.u-sprite.is-waiting .u-sprite__name { background: #b45309; }
.u-sprite.is-training .u-sprite__name { background: var(--st-training-fg); }
.u-sprite.is-training .u-sprite__body { animation: u-work 1.3s ease-in-out infinite alternate; }
.u-sprite.is-training .u-sprite__shadow { background: rgba(15,118,110,0.32); }
.u-sprite.is-flip .u-sprite__img { transform: scaleX(-1); }
.u-sprite.is-working .u-sprite__body { animation: u-work 0.9s ease-in-out infinite alternate; }
.u-sprite.is-working .u-sprite__shadow { background: rgba(242,101,34,0.35); }
.u-sprite.is-meeting .u-sprite__body, .u-sprite.is-waiting .u-sprite__body { animation: u-nod 2.6s ease-in-out infinite; }
.u-sprite.is-idle .u-sprite__body, .u-sprite.is-rest .u-sprite__body, .u-sprite.is-offline .u-sprite__body { animation: u-sway 3.2s ease-in-out infinite alternate; }
.u-sprite.is-rest .u-sprite__img, .u-sprite.is-offline .u-sprite__img { filter: drop-shadow(0 2px 2px rgba(17,24,39,0.2)) saturate(0.75); }
.u-sprite.is-walking .u-sprite__body { animation: u-walk 0.42s ease-in-out infinite alternate !important; }
.u-sprite:hover { z-index: 60; }

.u-bubble { position: absolute; bottom: 103%; left: 50%; transform: translateX(-50%) translateY(4px) scale(.96); opacity: 0; pointer-events: none;
  width: max-content; max-width: clamp(96px, 11.5cqw, 220px); background: #fff; color: var(--u-ink); border: 1.5px solid var(--u-orange);
  border-radius: 12px; padding: .38em .7em; font-size: clamp(9px, .82cqw, 15px); line-height: 1.35; font-weight: 600; text-align: left;
  box-shadow: 0 10px 22px -8px rgba(17,24,39,0.35); transition: opacity .35s var(--u-ease), transform .35s var(--u-ease); z-index: 70; }
.u-sprite.is-alt .u-bubble { bottom: 124%; }
.u-bubble::after { content: ""; position: absolute; top: 100%; left: 50%; transform: translateX(-50%); border: 6px solid transparent; border-top-color: var(--u-orange); }
.u-bubble.is-on, .u-sprite:hover .u-bubble { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
.u-bubble--meeting { border-color: #7c3aed; } .u-bubble--meeting::after { border-top-color: #7c3aed; }
.u-bubble--waiting { border-color: #d97706; } .u-bubble--waiting::after { border-top-color: #d97706; }
.u-bubble--training { border-color: var(--st-training-fg); } .u-bubble--training::after { border-top-color: var(--st-training-fg); }
.u-bubble--rest, .u-bubble--idle { border-color: var(--u-line-strong); color: var(--u-text-2); } .u-bubble--rest::after, .u-bubble--idle::after { border-top-color: var(--u-line-strong); }
.u-bubble__src { display: block; font-size: .78em; font-weight: 600; color: var(--u-orange-700); margin-top: 1px; }

@keyframes u-work { from { transform: translateY(0) scaleY(1); } to { transform: translateY(-1.2%) scaleY(0.985); } }
@keyframes u-nod { 0%, 100% { transform: rotate(0deg); } 30% { transform: rotate(-1.6deg); } 60% { transform: rotate(1.2deg); } }
@keyframes u-sway { from { transform: rotate(-0.9deg); } to { transform: rotate(0.9deg); } }
@keyframes u-walk { from { transform: translateY(0) rotate(-2deg); } to { transform: translateY(-3%) rotate(2deg); } }

/* ---------- Bot card (toggle button, collapsed by default) ---------- */
.u-botcard { background: var(--u-surface); border: 1px solid var(--u-line); border-radius: var(--u-r-md); box-shadow: var(--u-shadow-1); overflow: hidden;
  transition: box-shadow .2s, border-color .2s; }
.u-botcard[data-open="true"] { border-color: #fdc9a8; box-shadow: var(--u-shadow-2); }
.u-botcard.is-flash { animation: u-flash 1.4s ease-out 1; }
.u-botcard__toggle { all: unset; box-sizing: border-box; width: 100%; cursor: pointer; display: grid; grid-template-columns: 44px 1fr auto 18px; gap: 12px; align-items: center; padding: 12px 14px; }
.u-botcard__toggle:hover { background: var(--u-surface-soft); }
.u-botcard__toggle:focus-visible { outline: 3px solid var(--u-orange-ring); outline-offset: -3px; }
.u-botcard__avatar { width: 44px; height: 44px; border-radius: 12px; background: linear-gradient(180deg, var(--u-orange-50), #fff); border: 1px solid var(--u-line); overflow: hidden; }
.u-botcard__avatar img { width: 100%; height: 190%; object-fit: cover; object-position: 50% 0; display: block; }
.u-botcard__name { font-weight: 700; color: var(--u-ink); line-height: 1.2; }
.u-botcard__role { font-size: 12px; color: var(--u-muted); line-height: 1.3; }
.u-botcard__chev { width: 18px; height: 18px; color: var(--u-muted); transition: transform .25s var(--u-ease); }
.u-botcard[data-open="true"] .u-botcard__chev { transform: rotate(180deg); color: var(--u-orange); }
.u-botcard__body { padding: 0 14px 14px; display: grid; gap: 8px; border-top: 1px solid var(--u-line); background: linear-gradient(180deg, var(--u-surface-soft), #fff); }
.u-botcard__row { display: grid; grid-template-columns: 92px 1fr; gap: 8px; font-size: 13px; padding-top: 8px; }
.u-botcard__row dt { color: var(--u-muted); font-weight: 600; }
.u-botcard__row dd { margin: 0; color: var(--u-text); overflow-wrap: anywhere; }
@keyframes u-flash { 0% { box-shadow: 0 0 0 0 rgba(242,101,34,.55); } 100% { box-shadow: 0 0 0 14px rgba(242,101,34,0); } }

@media (max-width: 980px) {
  .u-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .u-nav { display: none; }
}
@media (max-width: 560px) {
  .u-kpis { grid-template-columns: 1fr 1fr; }
  .u-header__right .u-tag:not(.u-keep) { display: none; }
}

/* ---- logout link in header ---- */
.u-logout { text-decoration: none; padding: 5px 11px; }

/* ---- PC health level badge (6 levels) ---- */
.u-level { display: flex; align-items: center; gap: 12px; text-decoration: none; color: var(--u-ink);
  border: 1px solid var(--u-line); border-radius: var(--u-r-md); padding: 10px 14px; background: var(--u-surface);
  box-shadow: var(--u-shadow-1); border-left: 4px solid var(--lv, var(--u-line-strong)); }
a.u-level:hover { border-color: var(--u-orange); border-left-color: var(--lv); box-shadow: var(--u-shadow-2); }
.u-level__emoji { font-size: 20px; line-height: 1; }
.u-level__text { display: flex; flex-direction: column; min-width: 0; }
.u-level__text strong { font-size: var(--u-fs-md); }
.u-level__text small { color: var(--u-muted); font-size: var(--u-fs-xs); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.u-level--lg { padding: 18px 22px; border-left-width: 6px; background: linear-gradient(90deg, var(--lv-bg, var(--u-surface-soft)), var(--u-surface) 70%); }
.u-level--lg .u-level__emoji { font-size: 38px; }
.u-level--lg .u-level__text strong { font-size: var(--u-fs-xl); letter-spacing: .01em; }
.u-level--normal { --lv: #16a34a; --lv-bg: #effaf2; }
.u-level--busy   { --lv: #2563eb; --lv-bg: #eef4ff; }
.u-level--warm   { --lv: #d4a106; --lv-bg: #fffaeb; }
.u-level--risk   { --lv: var(--u-orange); --lv-bg: var(--u-orange-50); }
.u-level--danger { --lv: #dc2626; --lv-bg: #fef2f2; }
.u-level--nodata { --lv: #9ca3af; --lv-bg: var(--u-surface-soft); }

/* ---- SVG charts ---- */
.u-spark { width: 96px; height: 30px; display: block; }
.u-spark__line { fill: none; stroke: var(--u-orange); stroke-width: 1.6; vector-effect: non-scaling-stroke; }
.u-spark__area { fill: var(--u-orange-100); opacity: .7; }
.u-chart { width: 100%; height: 100%; display: block; background: var(--u-surface); }
.u-chart__grid { stroke: var(--u-line); stroke-width: 1; vector-effect: non-scaling-stroke; }
.u-chart__grid--v { stroke-dasharray: 2 4; }
.u-chart__line { fill: none; stroke: var(--u-orange-600); stroke-width: 2; vector-effect: non-scaling-stroke; stroke-linejoin: round; }
.u-chart__area { fill: var(--u-orange-ring); }
