/* =========================================================================
   Screens area: All Screens, screen detail, groups, tags, reports, account
   and the shared screen dialogs (pair, edit, device info, timeline,
   screenshot, assign content).
   Tokens from theme.css only — no raw colors, no new shadows.
   Page primitives (cards, tables, tabs, badges, modal, empty…) live in app.css.
   ========================================================================= */

/* ----------------------------------------------------- shared helpers --- */
.pg { min-width: 0; }
.wrap { flex-wrap: wrap; }
.maxw { max-width: 240px; }
.ok-text { color: var(--status-success); }
.danger-text { color: var(--status-danger); }
.rot-180 { transform: rotate(180deg); }
.select-sm { height: var(--control-h-sm) !important; width: auto !important; padding: 0 28px 0 8px !important; font-size: var(--fs-sm); background-position: right 6px center; background-size: 14px; }
.sec-h { font-size: var(--fs-xs); font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); margin: var(--space-5) 0 var(--space-3); }
.sec-h:first-child { margin-top: var(--space-1); }
.readonly { height: var(--control-h); display: flex; align-items: center; padding: 0 12px; border: 1px dashed var(--border-strong); border-radius: var(--radius-md); color: var(--text-secondary); background: var(--bg-surface-subtle); font-size: var(--fs-md); }
.modal-foot .foot-note { margin-right: auto; align-self: center; min-width: 0; }
.icon-btn.bordered { border: 1px solid var(--border-strong); background: var(--bg-surface); box-shadow: var(--shadow-xs); }
.icon-btn.bordered:hover { background: var(--bg-surface-hover); }
.badge-xs { height: 18px; font-size: 11px; padding: 0 var(--space-2); margin-top: var(--space-1); }
a.badge:hover { text-decoration: none; background: var(--status-danger-border); }
.empty.small { padding: var(--space-6) var(--space-4); }
.empty-ic.ok { background: var(--status-success-soft); border-color: var(--status-success-border); color: var(--status-success); }
.card > .empty { padding: var(--space-8) var(--space-5); }
.form-note { margin: 0; }
.page-note { margin-top: var(--space-4); }

/* sync + orientation indicators (rendered by ui-kit: syncIcon, orientIcon) */
.orient { display: inline-flex; align-items: center; gap: var(--space-2); color: var(--text-secondary); font-size: var(--fs-xs); white-space: nowrap; }
.orient i { display: inline-block; width: 18px; height: 12px; border: 2px solid var(--text-muted); border-bottom-width: 4px; border-radius: var(--radius-xs); }
.orient.portrait i { width: 12px; height: 18px; }
.orient.inverted i { border-bottom-width: 2px; border-top-width: 4px; }
.playing-cell { display: flex; align-items: center; gap: var(--space-3); min-width: 150px; max-width: 260px; }
.sync { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: var(--radius-md); flex: none; }
.sync .ic { width: 15px; height: 15px; }
.sync.ok { color: var(--status-success); background: var(--status-success-soft); }
.sync.bad { color: var(--status-warning); background: var(--status-warning-soft); }


/* --------------------------------------------------- toolbars (mobile) --- */
.toolbar select { height: var(--control-h); }
@media (max-width: 640px) {
  .pg .toolbar .search { width: 100%; }
  .pg .toolbar > select { flex: 1 1 calc(50% - 5px); width: auto; min-width: 0; }
  .pg .toolbar > .grow { display: none; }
  .pg .toolbar > .btn-primary { flex: 1 1 100%; }
  .pg .toolbar > .toolbar-actions { flex: 1 1 100%; }
  .toolbar-actions .btn { flex: 1 1 0; }
  .pg .bulkbar { flex-wrap: nowrap; gap: var(--space-2); padding: var(--space-2) var(--space-3); }
  .pg .bulkbar > .grow { display: none; }
  .pg .bulkbar > b { flex: 1 1 auto; min-width: 0; white-space: nowrap; }
  .pg .bulkbar .btn { padding: 0 var(--space-3); }
  .bulkbar .btn span { display: none; }
  .kv { grid-template-columns: 110px minmax(0, 1fr); }
  .modal-foot { flex-wrap: wrap; }
  .modal-foot .foot-note { flex-basis: 100%; }
}
.bulkbar { flex-wrap: wrap; }
dl.kv { margin: 0; }
.switch input { flex: none; }
.table-foot { flex-wrap: wrap; gap: var(--space-2); }
.pager { gap: var(--space-3); flex-wrap: wrap; }

/* -------------------------------------- stacked table on phones (m-stack) --
   Opt-in: <table class="table m-stack">; first cell gets .m-head (title),
   .m-full spans the row, other cells carry data-label="…". */
@media (max-width: 760px) {
  .m-stack thead { display: none; }
  .m-stack, .m-stack tbody { display: block; }
  .m-stack tr { position: relative; display: block; padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--border-subtle); }
  .m-stack tr:last-child { border-bottom: 0; }
  .m-stack td { display: block; padding: var(--space-1) 0; border: 0; background: none !important; text-align: left; min-width: 0; }
  .m-stack td[data-label] { display: grid; grid-template-columns: 88px minmax(0, 1fr); column-gap: var(--space-3); align-items: start; }
  .m-stack td[data-label]::before { content: attr(data-label); grid-column: 1; grid-row: 1; padding-top: 2px; font-size: var(--fs-xs); color: var(--text-muted); }
  .m-stack td[data-label] > * { grid-column: 2; min-width: 0; justify-self: start; }
  .m-stack td[data-label] > div:not(.chips) { justify-self: stretch; }
  .m-stack td.m-head { display: block; padding: 0 44px var(--space-2) 0; }
  .m-stack td.m-full { display: block; padding: 0 0 var(--space-1); }
  .m-stack td.w-act { position: absolute; top: var(--space-2); right: var(--space-2); width: auto; padding: 0; }
  .m-stack td .playing-cell { max-width: none; min-width: 0; }
}
.td-break { word-break: break-word; }

/* ============================================================ ALL SCREENS === */
.list-tabs { padding: 0 var(--space-5); margin-bottom: 0; }
.screens-table td { vertical-align: middle; }
.screens-table .screen-cell { min-width: 220px; }
.screens-table .screen-cell .cell-title { display: block; }
.screens-table .td-groups .chips { flex-wrap: nowrap; }
.screens-table .td-groups .chip { max-width: 140px; }
.screens-table .td-groups .chip .ellipsis { min-width: 0; }
.screens-table .td-ver { color: var(--text-secondary); }
.screens-table .td-err a.badge { gap: 4px; }
.onboarding-empty .howto { text-align: left; max-width: 460px; margin: 0 auto var(--space-5); padding: 0; list-style: none; counter-reset: step; display: flex; flex-direction: column; gap: var(--space-2); }
.onboarding-empty .howto li { counter-increment: step; display: flex; gap: var(--space-3); align-items: flex-start; border: 1px solid var(--border-default); border-radius: var(--radius-lg); padding: var(--space-3) var(--space-3); background: var(--bg-surface-subtle); color: var(--text-secondary); line-height: 1.45; word-break: break-word; }
.onboarding-empty .howto li::before { content: counter(step); flex: none; width: 22px; height: 22px; border-radius: 50%; background: var(--accent-primary); color: var(--text-on-accent); font-weight: 600; font-size: var(--fs-xs); display: grid; place-items: center; }

@media (max-width: 1100px) {
  .screens-table .th-ver, .screens-table .td-ver { display: none; }
}
@media (min-width: 761px) and (max-width: 1000px) {
  .screens-table .th-groups, .screens-table .td-groups { display: none; }
}
@media (max-width: 760px) {
  .list-tabs { padding: 0 var(--space-4); }
  .screens-table thead { display: none; }
  .screens-table, .screens-table tbody { display: block; }
  .screens-table tr { display: grid; grid-template-columns: 20px minmax(0, 1fr) auto; gap: var(--space-2) var(--space-3); align-items: center; padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--border-subtle); }
  .screens-table tr:last-child { border-bottom: 0; }
  .screens-table tr.selected { background: var(--accent-primary-soft); }
  .screens-table td { display: block; padding: 0; border: 0; background: none !important; min-width: 0; }
  .screens-table td.td-check { grid-column: 1; grid-row: 1; width: auto; }
  .screens-table td.td-screen { grid-column: 2; grid-row: 1; }
  .screens-table td.td-act { grid-column: 3; grid-row: 1; width: auto; }
  .screens-table td.td-status { grid-column: 2; grid-row: 2; justify-self: start; }
  .screens-table td.td-err { grid-column: 3; grid-row: 2; justify-self: end; }
  .screens-table td.td-np { grid-column: 2 / -1; grid-row: 3; }
  .screens-table td.td-groups { grid-column: 2 / -1; grid-row: 4; }
  .screens-table td.td-groups.is-empty, .screens-table td.td-err.is-empty, .screens-table td.td-ver { display: none; }
  .screens-table .screen-cell { min-width: 0; }
  .screens-table .playing-cell { max-width: none; min-width: 0; }
  .screens-table td.td-act .icon-btn { width: 32px; height: 32px; }
}

/* =========================================================== SCREEN DETAIL === */
.sd-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-4); flex-wrap: wrap; margin-bottom: var(--space-4); }
.sd-id { display: flex; align-items: center; flex-wrap: wrap; gap: var(--space-2) var(--space-3); min-width: 0; flex: 1 1 320px; }
.sd-meta { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; color: var(--text-muted); font-size: var(--fs-sm); }
.sd-meta li + li::before { content: '·'; margin: 0 var(--space-2); color: var(--text-faint); }
.head-actions { gap: var(--space-2); }
@media (max-width: 640px) { .sd-head, .head-actions { width: 100%; } .head-actions .btn { flex: 1 1 auto; } }
.sd-slot > .card { height: 100%; }
.sd-stack { display: flex; flex-direction: column; gap: var(--space-4); }
.sd-alert { margin-bottom: var(--space-3); }
.sd-action { margin-top: var(--space-3); }
.np-now, .np-off { display: flex; gap: var(--space-3); align-items: center; padding: var(--space-3); border-radius: var(--radius-lg); background: var(--bg-surface-subtle); border: 1px solid var(--border-default); }
.np-now { background: var(--status-success-soft); border-color: var(--status-success-border); }
.np-now .ic-chip { background: var(--bg-surface); }
.np-now > .grow, .np-off > div { min-width: 0; }
.src-chip { display: inline-flex; align-items: center; gap: var(--space-1); height: 22px; padding: 0 var(--space-3); border-radius: var(--radius-full); font-size: var(--fs-xs); font-weight: 500; background: var(--bg-surface-muted); color: var(--text-secondary); }
.src-schedule, .src-screen { background: var(--accent-primary-soft); color: var(--accent-primary-text); }
.src-group { background: var(--status-info-soft); color: var(--status-info-strong); }
.src-fallback { background: var(--status-warning-soft); color: var(--status-warning-strong); }
.src-none { background: var(--status-neutral-soft); color: var(--status-neutral-strong); }
.chip .ic { width: 12px; height: 12px; }
.seg-list { list-style: none; margin: 0; padding: 0; }
.seg { position: relative; display: flex; gap: var(--space-3); padding: 0 0 var(--space-4); }
.seg:not(:last-child)::before { content: ''; position: absolute; left: 5px; top: 18px; bottom: 0; width: 2px; background: var(--border-default); }
.seg-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--border-strong); margin-top: 4px; flex: none; }
.seg.now .seg-dot { background: var(--status-success-fill); box-shadow: 0 0 0 4px var(--status-success-soft); }
.seg-when { font-size: var(--fs-xs); font-weight: 600; color: var(--text-muted); margin-bottom: var(--space-1); }
.seg-names { font-size: var(--fs-sm); margin-top: var(--space-1); }
.seg .small.muted { margin-top: 2px; }
.seg-items { border-top: 1px solid var(--border-subtle); padding-top: var(--space-3); }
.seg-items summary { cursor: pointer; font-size: var(--fs-sm); font-weight: 600; color: var(--text-secondary); }
.seg-items ol { margin: var(--space-2) 0 0; padding-left: 20px; max-height: 220px; overflow: auto; }
.seg-items li { display: list-item; padding: 3px 0; font-size: var(--fs-sm); }
.seg-items li > span.grow { display: inline-block; max-width: 60%; vertical-align: bottom; }
.seg-items li > span.muted { float: right; }
.table tr.resolved td { color: var(--text-muted); }
.table td.msg { min-width: 240px; }
@media (max-width: 760px) { .m-stack td.msg { min-width: 0; } .m-stack td.msg::before { padding-top: 0; } }
.screenshot { display: block; width: 100%; height: auto; border-radius: var(--radius-md); border: 1px solid var(--border-default); background: var(--bg-media); }
.shot-meta { margin-top: var(--space-2); }
.ss-body { min-height: 120px; }
.ss-note { margin-bottom: var(--space-3); }

/* ======================================================== GROUPS / TAGS === */
.groups-table td { vertical-align: middle; }
.t-toolbar, .r-toolbar { margin-top: var(--space-4); }
.t-gap { margin-top: var(--space-4); }
.tag-groups { display: flex; flex-direction: column; gap: var(--space-4); }
.tag-group { display: grid; grid-template-columns: 160px minmax(0, 1fr); gap: var(--space-3); align-items: start; }
.tag-name { display: flex; align-items: center; gap: var(--space-2); min-width: 0; padding-top: var(--space-1); font-size: var(--fs-sm); font-weight: 600; color: var(--text-secondary); }
.tag-name .ic { width: 14px; height: 14px; color: var(--text-muted); }
.tag-chip { height: 28px; padding: 0 var(--space-3); font-size: var(--fs-sm); border-color: var(--border-default); background: var(--bg-surface); }
.tag-chip:hover { background: var(--bg-surface-hover); border-color: var(--border-strong); }
.tag-chip.on { background: var(--accent-primary-soft); border-color: var(--accent-primary-border); }
.tag-chip .muted { font-size: var(--fs-xs); font-variant-numeric: tabular-nums; }
@media (max-width: 640px) { .tag-group { grid-template-columns: minmax(0, 1fr); gap: var(--space-2); } .tag-name { padding-top: 0; } }

/* ======================================================= REPORTS / ACCOUNT === */
.rep-kpis { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.rep-kpis .kpi-of { font-size: var(--fs-xl); font-weight: 500; color: var(--text-muted); letter-spacing: 0; }
@media (max-width: 1320px) { .rep-kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 760px) { .rep-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } .rep-kpis .kpi:first-child { grid-column: auto; } }
.who-sm { width: 28px; height: 28px; border-radius: 50%; background: var(--accent-primary-soft); color: var(--accent-primary-text); display: inline-grid; place-items: center; font-weight: 600; font-size: var(--fs-xs); flex: none; }
.who-sm.screen { background: var(--status-info-soft); color: var(--status-info-strong); }
.who-sm.system { background: var(--status-neutral-soft); color: var(--status-neutral-strong); }
.avatar-lg { width: 48px; height: 48px; font-size: var(--fs-2xl); cursor: default; }
.profile-id { gap: var(--space-3); }
.profile-name { font-size: var(--fs-lg); font-weight: 600; }
dl.acc-kv { margin-top: var(--space-5); padding-top: var(--space-5); border-top: 1px solid var(--border-subtle); }
.sec-list { display: flex; flex-direction: column; gap: var(--space-4); }
.sec-list .btn { align-self: flex-start; }
.sec-item { display: flex; gap: var(--space-3); align-items: flex-start; }
.sec-item b { display: block; font-size: var(--fs-sm); font-weight: 600; }
.sec-item span:not(.ic-chip) { display: block; font-size: var(--fs-xs); color: var(--text-muted); margin-top: 2px; line-height: 1.5; }
.strength { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--space-1); margin-top: var(--space-2); }
.strength i { height: 4px; border-radius: var(--radius-xs); background: var(--border-default); }
.strength.s1 i:nth-child(-n+1) { background: var(--status-danger-fill); }
.strength.s2 i:nth-child(-n+2) { background: var(--status-warning-fill); }
.strength.s3 i:nth-child(-n+3) { background: var(--status-success-fill); }
.strength.s4 i { background: var(--status-success); }

/* ============================================================== DIALOGS === */
/* pair */
.pair-grid { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: var(--space-6); align-items: start; }
@media (max-width: 720px) { .pair-grid { grid-template-columns: minmax(0, 1fr); gap: var(--space-4); } }
.code-input::placeholder { color: var(--border-strong); letter-spacing: 0.35em; }
.help-panel { background: var(--bg-surface-subtle); border: 1px solid var(--border-default); border-radius: var(--radius-lg); padding: var(--space-4); font-size: var(--fs-sm); color: var(--text-secondary); }
.help-panel h3 { font-size: var(--fs-md); display: flex; align-items: center; gap: var(--space-3); color: var(--text-primary); margin-bottom: var(--space-3); }
.help-panel h3 .ic-chip { width: 28px; height: 28px; }
.help-panel h3 .ic-chip .ic { width: 15px; height: 15px; }
.help-panel ol { padding-left: var(--space-5); margin: 0; display: flex; flex-direction: column; gap: var(--space-3); line-height: 1.5; }
.help-panel ol li::marker { color: var(--text-muted); font-weight: 600; }
.help-panel .copybox { margin-top: var(--space-2); background: var(--bg-surface); }
.help-panel .copybox .icon-btn { width: 30px; height: 30px; }
.help-foot { margin-top: var(--space-4); padding-top: var(--space-3); border-top: 1px solid var(--border-default); font-size: var(--fs-xs); color: var(--text-muted); line-height: 1.5; }
.help-panel a .ic { width: 13px; height: 13px; vertical-align: -2px; }

/* edit screen */
.cf-rows { display: flex; flex-direction: column; gap: var(--space-2); margin-top: var(--space-2); }
.cf-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 36px; gap: var(--space-2); align-items: center; }

/* timeline */
.tl-head { margin-bottom: var(--space-1); flex-wrap: wrap; }
.tl-count { margin: var(--space-2) 0; }
.tl-filters { margin-bottom: var(--space-3); }
.timeline-list { max-height: 420px; overflow: auto; border: 1px solid var(--border-default); border-radius: var(--radius-lg); }
.timeline-list li { padding: var(--space-3) var(--space-3); }

/* assign content */
.assign-sub { margin: 0 0 var(--space-3); }
.assign-top { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); margin-bottom: var(--space-3); }
.assign-top .search { min-width: 180px; }
.tabs button .ic { width: 15px; height: 15px; }
.pick.on { background: var(--accent-primary-soft); }
.pick.disabled { opacity: 0.55; cursor: not-allowed; }
.pick .grow { min-width: 0; }
.pick .cell-title, .pick .cell-sub { display: block; }
.pick .order { min-width: 18px; text-align: center; }
.pick-ic { width: 40px; height: 28px; border-radius: var(--radius-sm); background: var(--accent-primary-soft); color: var(--accent-primary); display: inline-grid; place-items: center; flex: none; }
.pick-ic .ic { width: 16px; height: 16px; }
.row-ellipsis { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.weblink-form { margin-bottom: var(--space-3); background: var(--bg-surface-subtle); box-shadow: none; }
.weblink-form .row-between { margin-bottom: var(--space-3); }
.weblink-actions { justify-content: flex-end; margin-top: var(--space-3); }
.small-h { font-size: var(--fs-md); }

/* ============================================================== TV LOGIN === */
.empty-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: var(--space-2); }
.onboarding-tv { margin: var(--space-4) 0 0; }
.tvl-lead { margin: 0; color: var(--text-secondary); font-size: var(--fs-sm); line-height: 1.5; }
.hint.tvl-lead { font-size: var(--fs-xs); color: var(--text-muted); }
.tvl-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-4); }
.tvl-section { border-top: 1px solid var(--border-subtle); padding-top: var(--space-4); }
.tvl-section .sec-h { margin-bottom: var(--space-1); }
.tvl-section .tvl-lead { margin-bottom: var(--space-4); }
input.mono { font-family: var(--font-mono); }
.choice-set { border: 0; margin-inline: 0; margin-bottom: 0; padding: 0; min-width: 0; }
.choice-set > legend { padding: 0; }
.choice { display: flex; align-items: flex-start; gap: var(--space-3); padding: var(--space-3); border: 1px solid var(--border-default); border-radius: var(--radius-lg); background: var(--bg-surface); cursor: pointer; }
.choice + .choice { margin-top: var(--space-2); }
.choice:hover { background: var(--bg-surface-hover); }
.choice:has(input:checked) { border-color: var(--accent-primary-border); background: var(--accent-primary-soft); }
.choice:has(input:focus-visible) { box-shadow: 0 0 0 3px var(--focus-ring); }
.choice input { flex: none; margin: 3px 0 0; }
.choice b { display: block; font-size: var(--fs-sm); font-weight: 600; }
.choice small { display: block; margin-top: 2px; font-size: var(--fs-xs); color: var(--text-muted); line-height: 1.45; }
.tvl-pw { margin-top: var(--space-2); }
.tvl-pw[hidden] { display: none; }
.cred-box { padding: var(--space-2) var(--space-2) var(--space-2) var(--space-4); }
.cred-value { min-width: 0; font-size: var(--fs-xl); font-weight: 600; letter-spacing: 0.04em; overflow-wrap: anywhere; user-select: all; color: var(--text-primary); }
.cred-box .btn { flex: none; }
