/* ══════════════════════════════════════════════════════════════
   UV Studio shell and navigation.
   Loads after core.css and the two strictly scoped feature sheets.
══════════════════════════════════════════════════════════════ */

/* Application frame */
body {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    height: 100vh;
    margin: 0;
    padding: 0;
    overflow: hidden;
}

/* ── Top bar ── */
.topbar {
    flex: 0 0 auto;
    display: flex; align-items: center; justify-content: space-between; gap: 16px;
    height: 58px; padding: 0 18px;
    background: var(--surface); border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-header); z-index: 40;
}
.sb-brand { display: flex; align-items: center; gap: 11px; min-width: 0; }
.logo-mark {
    display: grid; place-items: center; width: 34px; height: 34px; border-radius: 9px;
    background: linear-gradient(150deg, #3b82f6, #2563eb); color: #fff; flex: 0 0 auto;
    box-shadow: 0 2px 8px rgba(37,99,235,0.4), inset 0 1px 0 rgba(255,255,255,0.25);
}
.logo-mark svg { width: 24px; height: 24px; }
.sb-title { display: flex; flex-direction: column; line-height: 1.15; }
.sb-name { font-size: 16px; font-weight: 700; letter-spacing: -0.01em; color: var(--text); }
.sb-name b { color: var(--accent); }
.sb-sub { font-size: 11px; color: var(--text-muted); }
.topbar-divider { width: 1px; height: 26px; background: var(--border); margin: 0 4px; }
.section-name { font-size: 14px; font-weight: 600; color: var(--text-secondary); white-space: nowrap; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.studio-serial-status {
    display: inline-flex; align-items: center; gap: 7px;
    min-width: 0; max-width: 230px; padding: 6px 10px;
    border: 1px solid var(--border); border-radius: 999px;
    background: color-mix(in oklab, var(--text-muted) 7%, var(--surface));
    color: var(--text-secondary); font-size: 11.5px; font-weight: 650;
    transition: color 0.16s, border-color 0.16s, background 0.16s;
}
.studio-serial-dot {
    width: 7px; height: 7px; flex: 0 0 auto; border-radius: 50%;
    background: var(--text-muted); box-shadow: 0 0 0 3px color-mix(in oklab, var(--text-muted) 14%, transparent);
}
.studio-serial-text {
    min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.studio-serial-status[data-state="connecting"],
.studio-serial-status[data-state="reconnecting"] {
    color: #a16207; border-color: color-mix(in oklab, #f59e0b 38%, var(--border));
    background: color-mix(in oklab, #f59e0b 10%, var(--surface));
}
.studio-serial-status[data-state="connecting"] .studio-serial-dot,
.studio-serial-status[data-state="reconnecting"] .studio-serial-dot {
    background: #f59e0b; box-shadow: 0 0 0 3px color-mix(in oklab, #f59e0b 18%, transparent);
    animation: serialPulse 1.25s ease-in-out infinite;
}
.studio-serial-status[data-state="connected"] {
    color: #15803d; border-color: color-mix(in oklab, #22c55e 36%, var(--border));
    background: color-mix(in oklab, #22c55e 9%, var(--surface));
}
.studio-serial-status[data-state="connected"] .studio-serial-dot {
    background: #22c55e; box-shadow: 0 0 0 3px color-mix(in oklab, #22c55e 18%, transparent);
}
.studio-serial-status[data-operation="true"] {
    color: var(--accent-hover); border-color: color-mix(in oklab, var(--accent) 38%, var(--border));
    background: color-mix(in oklab, var(--accent) 10%, var(--surface));
}
.studio-serial-status[data-operation="true"] .studio-serial-dot {
    background: var(--accent); box-shadow: 0 0 0 3px color-mix(in oklab, var(--accent) 18%, transparent);
    animation: serialPulse 1.1s ease-in-out infinite;
}
.studio-serial-status[data-critical="true"] {
    color: #b45309; border-color: color-mix(in oklab, #f59e0b 42%, var(--border));
    background: color-mix(in oklab, #f59e0b 12%, var(--surface));
}
.studio-serial-status[data-critical="true"] .studio-serial-dot { background: #f59e0b; }
@keyframes serialPulse { 50% { opacity: 0.45; transform: scale(0.78); } }
[data-theme="dark"] .studio-serial-status[data-state="connecting"],
[data-theme="dark"] .studio-serial-status[data-state="reconnecting"],
[data-theme="dark"] .studio-serial-status[data-critical="true"] { color: #fbbf24; }
[data-theme="dark"] .studio-serial-status[data-state="connected"] { color: #4ade80; }
.btn.icon { width: 36px; padding: 0; font-size: 15px; }
.theme-toggle .theme-icon {
    width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8;
    stroke-linecap: round; stroke-linejoin: round;
}

@media (max-width: 820px) {
    .studio-serial-status { width: 31px; height: 31px; padding: 0; justify-content: center; }
    .studio-serial-text { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
}
.theme-icon-moon { display: none; }
[data-theme="dark"] .theme-icon-sun { display: none; }
[data-theme="dark"] .theme-icon-moon { display: block; }

/* ── Shell ── */
.shell { flex: 1 1 auto; display: flex; min-height: 0; }
.sidebar {
    flex: 0 0 264px; display: flex; flex-direction: column; gap: 4px;
    padding: 16px 12px; background: var(--surface); border-right: 1px solid var(--border);
    overflow-y: auto; z-index: 30;
}
.nav-group { margin-bottom: 14px; }
.nav-group-studio { margin-top: auto; margin-bottom: 8px; }
.nav-label {
    padding: 0 12px 6px; font-size: 10.5px; font-weight: 700; letter-spacing: 0.08em;
    text-transform: uppercase; color: var(--text-muted);
}
.nav-item {
    display: flex; align-items: center; gap: 11px; width: 100%;
    padding: 9px 12px; margin-bottom: 2px; border: none; border-radius: 9px;
    background: transparent; color: var(--text-secondary);
    font-size: 13.5px; font-weight: 600; text-align: left; cursor: pointer;
    transition: background 0.13s, color 0.13s;
}
.nav-item svg { width: 18px; height: 18px; flex: 0 0 auto; opacity: 0.85; }
.nav-item-label { min-width: 0; white-space: nowrap; }
.nav-item .tag {
    margin-left: auto; font-size: 9.5px; font-weight: 700; letter-spacing: 0.04em;
    padding: 2px 6px; border-radius: 5px;
    background: color-mix(in oklab, var(--accent) 14%, transparent); color: var(--accent-hover);
}
.nav-item:hover { background: color-mix(in oklab, var(--text) 6%, transparent); color: var(--text); }
.nav-item:disabled {
    cursor: not-allowed;
    opacity: 0.55;
}
.nav-item.active:disabled { opacity: 0.82; }
.nav-item.active {
    background: linear-gradient(160deg, #3b82f6 0%, #2563eb 100%); color: #fff;
    box-shadow: 0 2px 8px rgba(37,99,235,0.35), inset 0 1px 0 rgba(255,255,255,0.2);
}
.nav-item.active .tag { background: rgba(255,255,255,0.22); color: #fff; }
[data-theme="dark"] .nav-item.active { background: linear-gradient(135deg, #2563eb, #3b82f6); }
.sidebar-foot {
    margin-top: 0; padding: 12px 12px 4px; border-top: 1px solid var(--border);
    font-size: 11px; color: var(--text-muted);
}

/* ── Stage & panes ── */
.stage { flex: 1 1 auto; overflow-y: auto; background: var(--bg); min-width: 0; }
.pane { display: none; }
.pane.active { display: block; animation: fade 0.18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } }

/* Viewer pane: contextual action bar (status + connect/keypad/help).
   Transparent so it reads as a toolbar over the stage, not a second header. */
.viewer-bar {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    flex-wrap: wrap; padding: 14px 24px 6px; background: transparent;
}
.viewer-bar .actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
#pane-viewer .main { padding: 14px 24px 28px; }

/* k5viewer toasts: move to bottom-right so they don't cover the action bar */
.notifications { top: auto; bottom: 20px; }

/* Viewer sub-views: Live Viewer (screen + keypad) vs RF Log */
.viewer-sub { display: none; }
.viewer-sub.active { display: block; }

/* RF Log as its own full view — card + generous width instead of a strip
   crammed under the keyboard. */
.rflog-wrap {
    width: calc(100% - 44px);
    max-width: 1024px;
    margin: 18px auto 40px;
    padding: 18px 20px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: var(--shadow);
}
#view-rflog #rfLogPanel { border-top: none; margin-top: 0; padding-top: 0; width: 100%; }
#view-rflog .rf-log-header {
    margin-bottom: 10px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
}
#view-rflog .rf-log-title {
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
    font-size: 13px;
    font-weight: 750;
    letter-spacing: -0.01em;
}
#view-rflog .rf-log-header-actions { gap: 10px; }
#view-rflog .rf-log-view-switch { padding: 3px; }
#view-rflog .rf-log-state { margin-left: 2px; }
/* Standalone RF Log view has room: show many more log rows than the
   ~8-row strip that lived under the keyboard (k5viewer caps it at 190px). */
#view-rflog #rfLogTableView {
    --rf-log-head-bg: #f4f6f8;
    --rf-log-head-ink: #536070;
}
#view-rflog .rf-log-scroll {
    max-height: none !important;
    min-height: 0;
    margin-right: 0;
    padding-right: 0;
    overflow: hidden;
    border-top: 0;
}
[data-theme="dark"] #view-rflog #rfLogTableView {
    --rf-log-head-bg: #1c2738;
    --rf-log-head-ink: #a7b2c3;
}
#view-rflog .rf-log-table {
    display: block;
    width: 100%;
    table-layout: auto;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 11px;
}
#view-rflog .rf-log-table thead {
    display: block;
    overflow: hidden;
    background: var(--rf-log-head-bg);
    border-radius: 7px 7px 0 0;
}
#view-rflog .rf-log-table tbody {
    display: block;
    max-height: calc(100vh - 270px);
    min-height: 320px;
    overflow-x: hidden;
    overflow-y: scroll;
    scrollbar-gutter: stable;
    scrollbar-width: thin;
    scrollbar-color: rgba(107,114,128,0.38) transparent;
}
#view-rflog .rf-log-table tbody::-webkit-scrollbar { width: 8px; }
#view-rflog .rf-log-table tbody::-webkit-scrollbar-track { background: transparent; }
#view-rflog .rf-log-table tbody::-webkit-scrollbar-thumb {
    background: rgba(107,114,128,0.38);
    background-clip: padding-box;
    border: 2px solid transparent;
    border-radius: 999px;
}
#view-rflog .rf-log-table thead tr,
#view-rflog .rf-log-table tbody tr {
    display: grid;
    grid-template-columns: 11fr 19fr 22fr 15fr 20fr 13fr;
    width: 100%;
}
#view-rflog .rf-log-table th,
#view-rflog .rf-log-table td {
    width: auto !important;
    min-width: 0;
    text-align: left;
}
#view-rflog .rf-log-table td { padding: 7px 10px; }
#view-rflog .rf-log-table th {
    position: static;
    height: 36px;
    padding: 0 10px;
    line-height: 35px;
    color: var(--rf-log-head-ink);
    background: var(--rf-log-head-bg);
    border: 0;
    border-bottom: 1px solid var(--border);
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: 0.01em;
    text-transform: none;
}
#view-rflog .rf-log-empty td,
#view-rflog .rf-log-session td { grid-column: 1 / -1; }
#view-rflog .rf-log-empty td { text-align: center; }
#view-rflog .rf-log-session td {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    text-align: left;
    color: var(--text-secondary);
    background: color-mix(in oklab, var(--accent) 7%, var(--surface));
    border-bottom: 1px solid color-mix(in oklab, var(--accent) 18%, var(--border));
    font-size: 9.5px;
    font-weight: 750;
    letter-spacing: 0.055em;
    opacity: 1;
}
#view-rflog .rf-log-session-icon {
    width: 15px;
    height: 15px;
    flex: 0 0 auto;
    color: var(--accent);
}
#view-rflog .rf-log-table tbody tr:not(.rf-log-session):not(.rf-log-empty) td {
    transition: background-color 0.12s ease;
}
#view-rflog .rf-log-table tbody tr:not(.rf-log-session):not(.rf-log-empty):not(.rf-log-live):hover td {
    background: color-mix(in oklab, var(--accent) 5%, var(--surface));
}
#view-rflog .rf-log-table tbody tr:not(.rf-log-session):not(.rf-log-empty) td:first-child {
    padding-left: 3px;
}
#view-rflog .rf-direction-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 2px 6px;
    border: 1px solid currentColor;
    border-radius: 5px;
    font-size: 9px;
    font-weight: 800;
    line-height: 1;
    letter-spacing: 0.045em;
}
#view-rflog .rf-direction-badge.rx {
    color: var(--rf-rx);
    background: color-mix(in oklab, var(--rf-rx) 9%, transparent);
}
#view-rflog .rf-direction-badge.tx {
    color: var(--rf-tx);
    background: color-mix(in oklab, var(--rf-tx) 9%, transparent);
}
#view-rflog .rf-log-table th:nth-child(1),
#view-rflog .rf-log-table td:nth-child(1) { width: 11%; }
#view-rflog .rf-log-table th:nth-child(2),
#view-rflog .rf-log-table td:nth-child(2) { width: 19%; }
#view-rflog .rf-log-table th:nth-child(3),
#view-rflog .rf-log-table td:nth-child(3) { width: 22%; }
#view-rflog .rf-log-table th:nth-child(4),
#view-rflog .rf-log-table td:nth-child(4) { width: 15%; }
#view-rflog .rf-log-table th:nth-child(5),
#view-rflog .rf-log-table td:nth-child(5) { width: 20%; }
#view-rflog .rf-log-table th:nth-child(6),
#view-rflog .rf-log-table td:nth-child(6) { width: 13%; }

.rflog-placeholder {
    display: flex; flex-direction: column; align-items: center; gap: 12px;
    padding: 54px 20px; text-align: center; color: var(--text-muted);
}
.rflog-placeholder svg { width: 40px; height: 40px; opacity: 0.65; }
.rflog-placeholder p { font-size: 13.5px; line-height: 1.6; }
/* hide the placeholder as soon as the live RF Log panel has data */
#view-rflog:has(#rfLogPanel:not([hidden])) .rflog-placeholder { display: none; }

/* Tools pane */
#pane-tools { padding: 26px 22px; }
#pane-tools .container { margin: 0 auto; }

/* About pane */
#pane-about { padding: 26px 22px; }
.about-card {
    width: 100%; max-width: 1024px; margin: 0 auto; padding: 42px;
    display: grid; grid-template-columns: 70px minmax(0, 1fr); gap: 24px 26px;
    background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
    box-shadow: var(--shadow-lg);
}
.about-mark {
    display: grid; place-items: center; width: 64px; height: 64px; border-radius: 18px;
    color: #fff; background: linear-gradient(150deg, #3b82f6, #2563eb);
    box-shadow: 0 8px 22px rgba(37,99,235,0.28), inset 0 1px 0 rgba(255,255,255,0.24);
}
.about-mark svg { width: 34px; height: 34px; }
.about-heading { align-self: center; min-width: 0; }
.about-kicker {
    margin-bottom: 3px; color: var(--accent); font-size: 11px; font-weight: 800;
    letter-spacing: 0.11em; text-transform: uppercase;
}
.about-heading h1 { color: var(--text); font-size: 25px; line-height: 1.2; letter-spacing: -0.025em; }
.about-intro { margin-top: 7px; color: var(--text-secondary); font-size: 14px; line-height: 1.55; }
.about-details {
    grid-column: 1 / -1; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
    border: 1px solid var(--border); border-radius: 12px; overflow: hidden;
}
.about-details > div { padding: 15px 18px; background: var(--bg); }
.about-details > div:nth-child(2) { border-left: 1px solid var(--border); }
.about-details .about-detail-wide { grid-column: 1 / -1; border-top: 1px solid var(--border); }
.about-details dt {
    margin-bottom: 3px; color: var(--text-muted); font-size: 10px; font-weight: 800;
    letter-spacing: 0.08em; text-transform: uppercase;
}
.about-details dd { color: var(--text); font-size: 13px; font-weight: 650; }
.about-copy {
    grid-column: 1 / -1; max-width: 760px; color: var(--text-secondary);
    font-size: 13.5px; line-height: 1.7;
}
.about-links { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 9px; }
.about-links a {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 92px; height: 34px; padding: 0 14px; border: 1px solid var(--border);
    border-radius: 8px; color: var(--text-secondary); background: var(--bg);
    font-size: 12px; font-weight: 750; text-decoration: none; transition: 0.15s ease;
}
.about-links a:hover {
    color: var(--accent-hover); border-color: var(--accent); background: var(--surface);
    transform: translateY(-1px);
}

/* ── Responsive ── */
@media (max-width: 860px) {
    body { overflow: auto; height: auto; }
    .topbar { flex-wrap: wrap; height: auto; padding: 10px 14px; }
    .section-name, .topbar-divider { display: none; }
    .shell { flex-direction: column; }
    .sidebar {
        flex: 0 0 auto; flex-direction: row; flex-wrap: wrap; gap: 6px;
        border-right: none; border-bottom: 1px solid var(--border); padding: 10px;
    }
    .nav-group { margin-bottom: 0; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
    .nav-group-studio { margin-top: 0; }
    .nav-label, .sidebar-foot, .nav-item .tag { display: none; }
    .nav-item { width: auto; padding: 8px 12px; }
    .rflog-wrap {
        width: calc(100% - 24px);
        margin: 12px auto 24px;
        padding: 14px 12px;
    }
    #view-rflog .rf-log-scroll { overflow-x: auto; }
    #view-rflog .rf-log-table { min-width: 720px; }
    #view-rflog .rf-log-table tbody { max-height: 60vh; }
    #pane-about { padding: 18px 12px; }
    .about-card { padding: 28px 24px; }
}

@media (max-width: 560px) {
    .about-card { grid-template-columns: 1fr; gap: 18px; padding: 24px 20px; }
    .about-mark { width: 54px; height: 54px; border-radius: 15px; }
    .about-mark svg { width: 29px; height: 29px; }
    .about-details { grid-template-columns: 1fr; }
    .about-details > div:nth-child(2) { border-left: none; border-top: 1px solid var(--border); }
    .about-details .about-detail-wide { grid-column: auto; }
    #view-rflog .rf-log-header {
        align-items: flex-start;
        flex-direction: column;
    }
    #view-rflog .rf-log-header-actions {
        width: 100%;
        align-items: center;
        flex-direction: row;
        justify-content: space-between;
    }
}
