/* StreamScope Overlay v2 - Design Stack Compliant */

/* ========== RESET & BASE ========== */

body {
    margin: 0;
    font-family: var(--font-secondary);
    background: rgba(0, 0, 0, 0);
    overflow: hidden;
    color: var(--text-primary);
}

/* ========== TOPBAR ========== */

#topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 44px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 var(--space-4);
    background: rgba(0, 0, 0, 0.95);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border-bottom: var(--border-width) solid var(--bg-card);
    z-index: 9999;
}

#topbar .left {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    font-family: var(--font-primary);
    font-size: var(--text-caption);
}

#topbar .right {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

#topbar .muted {
    opacity: 0.6;
    margin-left: var(--space-2);
    font-size: var(--text-caption);
}

.topbar-dashboard-link {
    color: var(--accent-primary);
    text-decoration: none;
    font-weight: var(--weight-bold);
    margin-right: var(--space-3);
    transition: color var(--duration-fast) var(--ease-out);
}

.topbar-dashboard-link:hover {
    color: var(--accent-hover);
}

.topbar-title {
    color: var(--accent-primary);
}

#topbar button {
    margin-left: var(--space-1);
    padding: 6px var(--space-3);
    border-radius: var(--radius-sm);
    border: var(--border-width) solid var(--border-default);
    cursor: pointer;
    background: var(--bg-elevated);
    color: var(--text-primary);
    font-family: var(--font-primary);
    font-size: var(--text-caption);
    transition: all var(--duration-fast) var(--ease-out);
}

#topbar button:hover {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
}

#topbar button#addScreenBtn {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    color: var(--text-primary);
}

#topbar button#addScreenBtn:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
    box-shadow: var(--shadow-red-glow-strong);
}

#topbar button:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

/* ========== EDIT HINT ========== */

.edit-hint {
    position: fixed;
    top: 54px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9998;
    padding: 8px 12px;
    border: var(--border-width) solid rgba(220, 20, 60, 0.35);
    background: rgba(10, 10, 10, 0.94);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-family: var(--font-primary);
    font-size: var(--text-caption);
    letter-spacing: 0.02em;
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
}

.edit-hint b {
    color: var(--accent-primary);
}

.edit-hint button {
    border: var(--border-width) solid var(--border-default);
    background: transparent;
    color: var(--text-muted);
    border-radius: var(--radius-sm);
    width: 22px;
    height: 22px;
    cursor: pointer;
    font-family: var(--font-primary);
    font-size: 12px;
    line-height: 1;
}

.edit-hint button:hover {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
}

.save-notice {
    top: auto;
    bottom: 16px;
}

.save-notice a {
    color: var(--accent-primary);
}

/* ========== CANVAS & SCREENS ========== */

#canvas {
    position: absolute;
    top: 44px;
    left: 0;
    right: 0;
    bottom: 0;
}

.screen {
    position: absolute;
    box-sizing: border-box;
    min-width: 160px;
    min-height: 120px;
    background: rgba(0, 0, 0, 0.85);
    border: var(--border-width) solid var(--bg-card);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-card);
}

.screen.edit {
    outline: 1px dashed var(--accent-primary);
    outline-offset: 2px;
}

.screen.selected {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
    box-shadow: var(--shadow-red-glow);
}

.screen-body {
    height: calc(100% - 38px);
    overflow: hidden;
}

/* Prevent accidental text selection while dragging */
.screen,
.screen * {
    -webkit-user-drag: none;
}

/* Screen header (drag handle) */
.screen-header {
    cursor: move;
    user-select: none;
    -webkit-user-select: none;
    padding: 10px var(--space-3);
    border-bottom: var(--border-width) solid var(--bg-card);
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-family: var(--font-primary);
    font-weight: var(--weight-bold);
    font-size: var(--text-caption);
    background: rgba(10, 10, 10, 0.8);
}

.screen-header .title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--accent-primary);
}

.screen-header .badge {
    font-size: 10px;
    font-weight: var(--weight-regular);
    opacity: 0.7;
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius-sm);
    border: var(--border-width) solid var(--border-default);
    font-family: var(--font-primary);
}

.screen-header .badge.hint {
    color: var(--text-muted);
    border-color: rgba(220, 20, 60, 0.35);
}

.screen-dim-badge {
    position: absolute;
    right: 8px;
    top: 42px;
    z-index: 12;
    background: rgba(0, 0, 0, 0.92);
    border: var(--border-width) solid rgba(220, 20, 60, 0.35);
    border-radius: var(--radius-sm);
    padding: 2px 6px;
    font-family: var(--font-primary);
    font-size: 10px;
    color: var(--accent-primary);
    pointer-events: none;
}

.resize-handle {
    position: absolute;
    z-index: 15;
    width: 12px;
    height: 12px;
    border: 1px solid rgba(220, 20, 60, 0.55);
    background: rgba(220, 20, 60, 0.22);
    border-radius: 2px;
    opacity: 0.8;
}

.resize-handle.edge {
    width: 16px;
    height: 8px;
}

.resize-handle.corner {
    width: 12px;
    height: 12px;
}

.resize-handle.n { top: -6px; left: calc(50% - 8px); cursor: ns-resize; }
.resize-handle.s { bottom: -6px; left: calc(50% - 8px); cursor: ns-resize; }
.resize-handle.e { right: -6px; top: calc(50% - 4px); width: 8px; height: 16px; cursor: ew-resize; }
.resize-handle.w { left: -6px; top: calc(50% - 4px); width: 8px; height: 16px; cursor: ew-resize; }
.resize-handle.nw { top: -6px; left: -6px; cursor: nwse-resize; }
.resize-handle.ne { top: -6px; right: -6px; cursor: nesw-resize; }
.resize-handle.sw { bottom: -6px; left: -6px; cursor: nesw-resize; }
.resize-handle.se { bottom: -6px; right: -6px; cursor: nwse-resize; }

.screen:not(.edit) .resize-handle {
    display: none;
}

.screen.edit .resize-handle:hover,
.screen.edit .resize-handle.active {
    opacity: 1;
    box-shadow: 0 0 8px rgba(220, 20, 60, 0.45);
}

.canvas-empty-state {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: min(520px, calc(100vw - 48px));
    padding: var(--space-6);
    border: var(--border-width) dashed rgba(220, 20, 60, 0.45);
    border-radius: var(--radius-md);
    background: rgba(10, 10, 10, 0.86);
    color: var(--text-muted);
    text-align: center;
    font-family: var(--font-secondary);
}

.canvas-empty-state h3 {
    margin: 0 0 var(--space-2) 0;
    font-family: var(--font-primary);
    color: var(--accent-primary);
    font-size: var(--text-body-lg);
}

.canvas-empty-state p {
    margin: 0;
    font-size: var(--text-small);
}

.screenHeader {
    font-family: var(--font-primary);
    font-weight: var(--weight-bold);
    font-size: var(--text-caption);
    margin-bottom: var(--space-2);
    opacity: 0.9;
    color: var(--accent-primary);
}

/* ========== MESSAGES ========== */

.messages {
    padding: var(--space-2) var(--space-3);
    font-size: var(--text-small);
    line-height: 1.5;
    font-family: var(--font-secondary);
}

.msg {
    margin-bottom: var(--space-2);
    opacity: 0.7;
    padding: var(--space-1) var(--space-2);
    padding-left: var(--space-2);
    border-left: 2px solid var(--accent-primary);
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: var(--space-1);
    transition: opacity var(--duration-standard) var(--ease-out);
}

.msg--newest {
    opacity: 1;
}

.msg--recent {
    opacity: 0.85;
}

.msg-username {
    margin-right: var(--space-1);
    color: var(--accent-primary);
    font-family: var(--font-primary);
    font-size: var(--text-caption);
    font-weight: var(--weight-bold);
    white-space: nowrap;
}

.msg-text {
    font-family: var(--font-secondary);
    font-size: var(--text-small);
    line-height: 1.5;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* Tag badge on messages */
.tag-badge {
    display: inline-block;
    font-family: var(--font-primary);
    font-size: 10px;
    font-weight: var(--weight-regular);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--accent-primary);
    background: var(--bg-elevated);
    border: var(--border-width) solid var(--accent-primary);
    border-radius: var(--radius-sm);
    padding: 1px 6px;
    white-space: nowrap;
    line-height: 1.4;
}

/* Fallback (ML) indicator */
.msg-fallback {
    display: inline-block;
    font-family: var(--font-primary);
    font-size: 10px;
    font-weight: var(--weight-bold);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--accent-primary);
    background: rgba(220, 20, 60, 0.15);
    border: var(--border-width) solid var(--accent-primary);
    border-radius: var(--radius-sm);
    padding: 1px 6px;
    cursor: help;
    white-space: nowrap;
    line-height: 1.4;
}

/* Empty state */
.msg-empty {
    font-family: var(--font-secondary);
    font-size: var(--text-small);
    font-style: italic;
    color: var(--text-muted);
    padding: var(--space-2) 0;
}

/* ========== PANELS ========== */

.panel {
    position: fixed;
    top: 54px;
    right: 10px;
    width: 320px;
    max-height: calc(100vh - 64px);
    background: rgba(0, 0, 0, 0.95);
    border: var(--border-width) solid var(--bg-card);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-card);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.panelHeader {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-3) var(--space-4);
    border-bottom: var(--border-width) solid var(--bg-card);
    font-family: var(--font-primary);
    font-size: var(--text-caption);
    flex-shrink: 0;
}

.panelHeader b {
    color: var(--accent-primary);
}

.panelHeader button {
    background: transparent;
    border: var(--border-width) solid var(--border-default);
    color: var(--text-muted);
    width: 28px;
    height: 28px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: var(--text-small);
    transition: all var(--duration-fast) var(--ease-out);
}

.panelHeader button:hover {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
}

.panelBody {
    padding: var(--space-4);
    display: grid;
    gap: var(--space-3);
    overflow-y: auto;
    overflow-x: hidden;
    flex: 1;
    min-height: 0;
}

/* Custom scrollbar for panel body */
.panelBody::-webkit-scrollbar {
    width: 8px;
}

.panelBody::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

.panelBody::-webkit-scrollbar-thumb {
    background: var(--border-default);
    border-radius: var(--radius-sm);
}

.panelBody::-webkit-scrollbar-thumb:hover {
    background: var(--accent-primary);
}

.panelBody label {
    display: grid;
    gap: 6px;
    font-family: var(--font-primary);
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.panelBody input,
.panelBody select,
.panelBody textarea {
    padding: 10px var(--space-3);
    border-radius: var(--radius-sm);
    border: var(--border-width) solid var(--border-default);
    background: var(--bg-elevated);
    color: var(--text-primary);
    font-family: var(--font-primary);
    font-size: var(--text-caption);
    transition: all var(--duration-fast) var(--ease-out);
}

.panelBody input:focus,
.panelBody select:focus,
.panelBody textarea:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px rgba(220, 20, 60, 0.2);
}

.panelBody button {
    padding: 10px var(--space-4);
    border-radius: var(--radius-sm);
    border: var(--border-width) solid var(--border-default);
    background: var(--bg-elevated);
    color: var(--text-primary);
    font-family: var(--font-primary);
    font-size: var(--text-caption);
    cursor: pointer;
    transition: all var(--duration-fast) var(--ease-out);
}

.panelBody button:hover {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
}

.panel-row-actions {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: var(--space-2);
}

.panel-group {
    display: grid;
    gap: var(--space-2);
}

.panel-group-title {
    color: var(--accent-primary);
    font-family: var(--font-primary);
    font-size: var(--text-caption);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.panel-note {
    color: var(--text-muted);
    font-family: var(--font-secondary);
    font-size: var(--text-caption);
    line-height: 1.4;
}

.style-preset-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-2);
}

.style-preset-card {
    border: var(--border-width) solid var(--border-default);
    border-radius: var(--radius-sm);
    background: var(--bg-elevated);
    padding: var(--space-2);
    cursor: pointer;
    transition: all var(--duration-fast) var(--ease-out);
    display: grid;
    gap: 4px;
}

.style-preset-card:hover {
    border-color: rgba(220, 20, 60, 0.65);
}

.style-preset-card.active {
    border-color: var(--accent-primary);
    box-shadow: 0 0 10px rgba(220, 20, 60, 0.2);
}

.style-preset-preview {
    height: 28px;
    border: var(--border-width) solid rgba(255, 255, 255, 0.16);
    border-radius: var(--radius-sm);
}

.style-preset-name {
    font-family: var(--font-primary);
    font-size: var(--text-caption);
    color: var(--text-primary);
}

.style-preset-desc {
    font-family: var(--font-secondary);
    font-size: 11px;
    color: var(--text-muted);
    line-height: 1.3;
}

.advanced-style {
    border: var(--border-width) solid var(--bg-card);
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.01);
    overflow: hidden;
}

.advanced-style > summary {
    cursor: pointer;
    padding: var(--space-2) var(--space-3);
    font-family: var(--font-primary);
    color: var(--text-muted);
    font-size: var(--text-caption);
    list-style: none;
}

.advanced-style > summary::-webkit-details-marker {
    display: none;
}

.advanced-style > summary::after {
    content: "+";
    float: right;
    color: var(--accent-primary);
}

.advanced-style[open] > summary::after {
    content: "-";
}

.advanced-style-body {
    padding: var(--space-3);
    display: grid;
    gap: var(--space-3);
}

/* Manage Tags link styled as button */
.manage-tags-wrapper {
    margin-top: var(--space-1);
}

.btn-manage-tags {
    display: inline-block;
    padding: 10px var(--space-4);
    border-radius: var(--radius-sm);
    background: var(--bg-elevated);
    border: var(--border-width) solid var(--border-default);
    color: var(--accent-primary);
    text-decoration: none;
    font-family: var(--font-primary);
    font-size: var(--text-caption);
    transition: all var(--duration-fast) var(--ease-out);
}

.btn-manage-tags:hover {
    border-color: var(--accent-primary);
    box-shadow: 0 0 10px rgba(220, 20, 60, 0.2);
}

/* Tag checkbox container (properties panel) */
.tag-checkbox-container {
    margin-top: 0;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.tag-filter-heading {
    display: none;
}

.tag-filter-rows {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.tag-filter-row-group {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-3);
}

.tag-filter-row {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    cursor: pointer;
    font-family: var(--font-primary);
    font-size: var(--text-caption);
    color: var(--text-muted);
    text-transform: none;
    letter-spacing: 0;
}

/* ========== AUTH CONTROLS ========== */

#authControls {
    font-family: var(--font-primary);
    font-size: var(--text-caption);
    margin-right: var(--space-4);
}

#authControls a {
    color: var(--accent-primary);
    text-decoration: none;
    transition: color var(--duration-fast) var(--ease-out);
}

#authControls a:hover {
    color: var(--accent-hover);
}

.btn-auth {
    padding: var(--space-1) 10px;
    border-radius: var(--radius-sm);
    background: transparent;
    font-family: var(--font-primary);
    font-size: var(--text-caption);
    cursor: pointer;
    transition: all var(--duration-fast) var(--ease-out);
}

.btn-auth--accent {
    border: var(--border-width) solid rgba(220, 20, 60, 0.3);
    color: var(--accent-primary);
    margin-right: 10px;
}

.btn-auth--accent:hover {
    border-color: var(--accent-primary);
    color: var(--accent-hover);
    box-shadow: 0 0 10px rgba(220, 20, 60, 0.2);
}

.btn-auth--muted {
    border: var(--border-width) solid rgba(255, 255, 255, 0.15);
    color: var(--text-muted);
    margin-left: 10px;
}

.btn-auth--muted:hover {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
}

.auth-greeting {
    color: var(--text-muted);
    font-family: var(--font-primary);
    font-size: var(--text-caption);
}

.auth-greeting__name {
    color: var(--text-primary);
}

.link-dashboard {
    color: var(--accent-primary);
    text-decoration: none;
    font-family: var(--font-primary);
    font-size: var(--text-caption);
    transition: color var(--duration-fast) var(--ease-out);
}

.link-dashboard:hover {
    color: var(--accent-hover);
}

/* ========== PREFERENCES ========== */

#preferencesPanel {
    right: 340px;
}

#shortcutsPanel {
    right: 340px;
}

.shortcut-list {
    margin: 0;
    padding: 0;
    list-style: none;
    display: grid;
    gap: var(--space-2);
}

.shortcut-list li {
    color: var(--text-muted);
    font-family: var(--font-secondary);
    font-size: var(--text-caption);
    line-height: 1.5;
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.shortcut-list kbd {
    border: var(--border-width) solid var(--border-default);
    border-radius: var(--radius-sm);
    background: var(--bg-elevated);
    color: var(--accent-primary);
    font-family: var(--font-primary);
    font-size: 10px;
    padding: 2px 6px;
    white-space: nowrap;
}

.prefs-description {
    font-size: var(--text-caption);
    color: var(--text-muted);
    margin-bottom: var(--space-3);
    font-family: var(--font-secondary);
}

.prefs-tag-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.prefs-checkbox-label {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    cursor: pointer;
    padding: var(--space-2) var(--space-3);
    background: var(--bg-elevated);
    border: var(--border-width) solid var(--bg-card);
    border-radius: var(--radius-sm);
    font-family: var(--font-primary);
    font-size: var(--text-caption);
    color: var(--text-muted);
    text-transform: none;
    letter-spacing: 0;
    transition: all var(--duration-fast) var(--ease-out);
}

.prefs-checkbox-label:hover {
    border-color: var(--border-default);
}

.prefs-checkbox {
    accent-color: var(--accent-primary);
    width: var(--space-4);
    height: var(--space-4);
}

.prefs-tag-name {
    color: var(--text-muted);
}

.prefs-tag-name--active {
    color: var(--text-primary);
}

#savePrefsBtn {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    color: var(--text-primary);
}

#savePrefsBtn:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
    box-shadow: var(--shadow-red-glow-strong);
}

.prefs-save-status {
    margin-left: 10px;
    font-size: var(--text-caption);
    color: var(--color-success);
    display: none;
}

.prefs-save-status.visible {
    display: inline;
}

/* ========== UTILITIES ========== */

.hidden {
    display: none !important;
}

.danger-zone {
    border-top: var(--border-width) dashed rgba(220, 20, 60, 0.35);
    padding-top: var(--space-3);
}

.danger {
    background: var(--accent-primary) !important;
    border-color: var(--accent-primary) !important;
    color: var(--text-primary) !important;
}

.danger:hover {
    background: var(--accent-hover) !important;
    border-color: var(--accent-hover) !important;
    box-shadow: var(--shadow-red-glow-strong) !important;
}

/* ========== FOCUS STATES ========== */

#topbar button:focus-visible,
.panelHeader button:focus-visible,
.panelBody button:focus-visible,
.panelBody input:focus-visible,
.btn-auth:focus-visible,
.btn-manage-tags:focus-visible,
.link-dashboard:focus-visible,
.topbar-dashboard-link:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
}
