* {
    box-sizing: border-box;
}

body {
    margin: 0;
    overflow-x: hidden;
    font-family: Arial, sans-serif;
    background: #0f172a;
    color: #e2e8f0;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    padding: 20px 24px;
    background: #111827;
    border-bottom: 1px solid #1f2937;
}

header > div {
    min-width: 0;
}

header h1 {
    margin: 0;
    font-size: 24px;
}

header p {
    margin: 0;
    color: #94a3b8;
    overflow-wrap: anywhere;
}

button {
    font: inherit;
}

button {
    border: none;
    border-radius: 8px;
    padding: 10px 14px;
    background: #2563eb;
    color: white;
    cursor: pointer;
}

button:hover {
    background: #1d4ed8;
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.55;
}

button:disabled:hover {
    background: #2563eb;
}

.summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    min-width: 0;
    padding: 16px clamp(12px, 4vw, 24px) 0;
}

.summary-card,
.panel,
.device-item {
    background: #111827;
    border: 1px solid #1f2937;
    border-radius: 12px;
}

.summary-card {
    min-width: 0;
    padding: 16px;
}

.client-version-panel {
    margin: 16px clamp(12px, 4vw, 24px) 0;
}

.client-version-title-row,
.client-version-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
}

.client-version-actions {
    display: flex;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 8px;
}

.client-version-title-row p {
    margin: 4px 0 0;
    color: #94a3b8;
}

.client-version-upload {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 10px;
    margin-bottom: 14px;
}

.client-version-upload label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    color: #cbd5e1;
    font-size: 13px;
}

.client-version-upload input,
.client-version-upload select {
    width: 100%;
    min-width: 0;
    border: 1px solid #334155;
    border-radius: 8px;
    padding: 8px 10px;
    background: #020617;
    color: #e2e8f0;
    font: inherit;
}

.client-version-upload input:focus-visible,
.client-version-upload select:focus-visible {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
}

.client-version-upload select option {
    background: #020617;
    color: #e2e8f0;
}

.client-version-notes-field {
    grid-column: span 2;
}

.client-version-upload-actions {
    display: flex;
    grid-column: 1 / -1;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 8px;
}

.client-version-file,
.artifact-item .device-meta {
    color: #94a3b8;
    overflow-wrap: anywhere;
}

.client-version-file {
    flex: 1 1 360px;
    min-width: 260px;
    max-width: 100%;
}

.client-version-file.has-selection {
    border: 1px solid #1f2937;
    border-radius: 10px;
    padding: 10px;
    background: rgba(2, 6, 23, 0.78);
}

.client-version-selected-summary {
    margin-bottom: 8px;
    color: #cbd5e1;
    font-size: 13px;
}

.client-version-selected-files {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 8px;
    max-height: 260px;
    overflow: auto;
}

.client-version-file-item {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;
    min-width: 0;
    border: 1px solid #1f2937;
    border-radius: 8px;
    padding: 8px 10px;
    background: #020617;
}

.client-version-file-name {
    min-width: 0;
    overflow: hidden;
    color: #e2e8f0;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.client-version-file-item strong {
    flex-shrink: 0;
    color: #cbd5e1;
    font-size: 13px;
    white-space: nowrap;
}

.client-version-file-error strong {
    color: #fca5a5;
}

.artifact-url-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
}

.artifact-url-link {
    color: #93c5fd;
    overflow-wrap: anywhere;
}

.artifact-copy-btn {
    padding: 4px 8px;
}

.client-version-list,
.artifact-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.client-version-item,
.artifact-item {
    border: 1px solid #1f2937;
    border-radius: 10px;
    padding: 12px;
    background: #0b1220;
}

.artifact-item {
    background: #020617;
}

.summary-card span {
    display: block;
    color: #94a3b8;
    margin-bottom: 8px;
}

.summary-card strong {
    font-size: 24px;
}

.layout {
    display: grid;
    grid-template-columns: minmax(300px, 420px) 1fr;
    gap: 16px;
    min-width: 0;
    padding: 16px clamp(12px, 4vw, 24px) 24px;
}

.panel {
    min-width: 0;
    padding: 16px;
}

.panel h2,
.panel h3 {
    margin-top: 0;
}

.device-list-title-row {
    margin-bottom: 12px;
}

.device-list-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 8px;
    min-width: 0;
}

.bulk-update-panel {
    border: 1px solid #1f2937;
    border-radius: 10px;
    padding: 12px;
    margin-bottom: 14px;
    background: #0b1220;
}

.bulk-update-header,
.bulk-update-item-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
}

.bulk-update-actions {
    display: flex;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 8px;
}

.bulk-update-summary {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 10px 0;
    color: #cbd5e1;
    font-size: 13px;
}

.bulk-update-summary span {
    border: 1px solid #334155;
    border-radius: 999px;
    padding: 2px 8px;
    background: #020617;
}

.bulk-update-items {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.bulk-update-item {
    border: 1px solid #1f2937;
    border-radius: 8px;
    padding: 10px;
    background: #020617;
}

.badge.update-running {
    background: rgba(59, 130, 246, 0.15);
    color: #93c5fd;
}

.badge.update-skipped {
    background: rgba(148, 163, 184, 0.15);
    color: #cbd5e1;
}

.device-filters {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 14px;
}

.device-filters label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
    color: #cbd5e1;
    font-size: 13px;
}

.device-filters select,
.device-filters input {
    width: 100%;
    min-width: 0;
    border: 1px solid #334155;
    border-radius: 8px;
    padding: 8px 10px;
    background: #020617;
    color: #e2e8f0;
    font: inherit;
}

.device-keyword-filter {
    grid-column: auto;
}

.device-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-width: 0;
}

.device-item {
    width: 100%;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    text-align: left;
    padding: 14px;
    background: #0b1220;
}

.device-item.selected {
    outline: 2px solid #2563eb;
}

.device-item-main {
    flex: 1;
    min-width: 0;
    border-radius: 8px;
    cursor: pointer;
}

.device-item-main:focus-visible {
    outline: 2px solid #2563eb;
    outline-offset: 3px;
}

.device-item-actions {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    flex-wrap: wrap;
    gap: 8px;
    flex-shrink: 0;
}

.device-delete-btn {
    flex-shrink: 0;
}

.device-delete-btn:disabled:hover {
    background: #dc2626;
}

.device-item-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.device-item-row strong {
    min-width: 0;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.device-item-row .badge {
    flex-shrink: 0;
}

.device-meta {
    margin-top: 6px;
    color: #94a3b8;
    font-size: 13px;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 12px;
    min-width: 52px;
}

.badge.online {
    background: rgba(34, 197, 94, 0.15);
    color: #86efac;
}

.badge.offline {
    background: rgba(239, 68, 68, 0.15);
    color: #fca5a5;
}

.panel-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    min-width: 0;
    margin-bottom: 16px;
}

.panel-title-row h2 {
    margin: 0;
}

.detail-actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
    min-width: 0;
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
    min-width: 0;
}

.detail-grid > div {
    min-width: 0;
}

.detail-grid span {
    display: block;
    font-size: 12px;
    color: #94a3b8;
    margin-bottom: 6px;
}

.detail-grid strong {
    display: block;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.capability-block {
    min-width: 0;
    margin-top: 20px;
}

pre {
    width: 100%;
    max-width: 100%;
    background: #020617;
    color: #e2e8f0;
    border: 1px solid #1f2937;
    border-radius: 8px;
    padding: 12px;
    overflow: auto;
}

.hidden {
    display: none !important;
}

.empty-state {
    color: #94a3b8;
    padding: 16px 0;
}

@media (max-width: 980px) {
    .layout {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 640px) {
    header {
        align-items: center;
        flex-direction: row;
        padding: 12px 16px;
    }

    header h1 {
        font-size: 20px;
    }

    header p {
        font-size: 14px;
    }

    header button {
        width: 100%;
    }

    .summary {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 6px;
    }

    .summary-card {
        padding: 10px 8px;
    }

    .summary-card span {
        margin-bottom: 4px;
        font-size: 11px;
        white-space: nowrap;
    }

    .summary-card strong {
        font-size: 18px;
    }

    .summary-card,
    .panel {
        border-radius: 10px;
    }

    .panel {
        padding: 14px;
    }

    .device-filters {
        grid-template-columns: 1fr;
    }

    .device-keyword-filter {
        grid-column: auto;
    }

    .device-item {
        flex-direction: column;
    }

    .device-delete-btn {
        align-self: flex-start;
    }
}

@media (max-width: 520px) {
    .panel-title-row {
        align-items: flex-start;
        flex-direction: column;
    }

    .device-list-title-row {
        align-items: center;
        flex-direction: row;
        flex-wrap: nowrap;
        gap: 6px;
    }

    .device-list-title-row h2 {
        flex: 0 0 auto;
        font-size: 16px;
        white-space: nowrap;
    }

    .device-list-actions {
        flex: 1 1 auto;
        flex-wrap: nowrap;
        gap: 4px;
        justify-content: flex-end;
        min-width: 0;
    }

    .device-list-actions .btn-sm {
        padding: 4px 5px;
        font-size: 11px;
        white-space: nowrap;
    }

    .device-item-actions {
        flex-wrap: nowrap;
        gap: 4px;
        overflow-x: auto;
        scrollbar-width: none;
    }

    .device-item-actions::-webkit-scrollbar {
        display: none;
    }

    .device-item-actions .btn-sm {
        flex: 1 0 auto;
        padding: 4px 5px;
        font-size: 11px;
        white-space: nowrap;
    }

    #openTerminalBtn,
    #openAndroidRemoteBtn {
        align-self: flex-start;
        width: auto;
        max-width: 100%;
    }

    .detail-actions {
        justify-content: flex-start;
    }

    .client-version-file-item {
        grid-template-columns: 1fr;
    }

    .client-version-file-item strong {
        white-space: normal;
    }
}

@media (max-width: 420px) {
    .device-item-row {
        align-items: flex-start;
        flex-direction: column;
    }

    .detail-grid {
        grid-template-columns: 1fr;
    }
}

/* Terminal */
.terminal-modal {
    position: fixed;
    top: var(--terminal-vv-top, 0);
    right: 0;
    bottom: auto;
    left: 0;
    height: var(--terminal-vv-height, 100vh);
    height: var(--terminal-vv-height, 100dvh);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: rgba(2, 6, 23, 0.72);
}

.terminal-dialog {
    position: relative;
    width: min(1100px, 100%);
    height: min(720px, calc(100vh - 48px));
    height: min(720px, calc(100dvh - 48px));
    min-width: 0;
    display: flex;
    flex-direction: column;
    padding: 16px;
    background: #111827;
    border: 1px solid #334155;
    border-radius: 12px;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
}

.terminal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    min-width: 0;
    margin-bottom: 8px;
}

.terminal-header h3 {
    margin: 0;
}

.terminal-controls {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
    min-width: 0;
}

.terminal-wrapper {
    flex: 1;
    min-height: 0;
    border-radius: 8px;
    overflow: hidden;
    overscroll-behavior: contain;
    border: 1px solid #1f2937;
}

.terminal-wrapper .xterm {
    padding: 8px;
}

.terminal-ai-fab {
    position: absolute;
    right: 28px;
    bottom: 28px;
    z-index: 5;
    width: 48px;
    height: 48px;
    border: 0;
    border-radius: 999px;
    background: linear-gradient(135deg, #2563eb, #7c3aed);
    color: #fff;
    font-weight: 700;
    box-shadow: 0 12px 28px rgba(37, 99, 235, 0.38);
    cursor: pointer;
}

.terminal-ai-panel {
    position: absolute;
    right: 24px;
    bottom: 84px;
    z-index: 6;
    width: min(420px, calc(100% - 48px));
    max-height: min(720px, calc(100% - 112px));
    min-height: 0;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    gap: 10px;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 14px;
    border: 1px solid rgba(148, 163, 184, 0.28);
    border-radius: 14px;
    background: linear-gradient(145deg, rgba(15, 23, 42, 0.78), rgba(2, 6, 23, 0.72));
    color: #e5e7eb;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.42);
    backdrop-filter: blur(14px) saturate(135%);
    -webkit-backdrop-filter: blur(14px) saturate(135%);
}

.terminal-ai-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.terminal-ai-panel-header strong {
    flex: 1 1 auto;
    min-width: 0;
}

.terminal-ai-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex: 0 0 auto;
    gap: 8px;
}

.terminal-ai-confirm-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.terminal-ai-actions .btn-sm {
    flex: 0 0 auto;
    min-width: 0;
}

.terminal-ai-panel textarea {
    min-height: 72px;
    resize: vertical;
    padding: 10px;
    border: 1px solid rgba(148, 163, 184, 0.32);
    border-radius: 10px;
    background: rgba(2, 6, 23, 0.52);
    color: #e5e7eb;
}

.terminal-ai-panel textarea:focus {
    border-color: rgba(147, 197, 253, 0.55);
    outline: none;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.16);
}

.terminal-ai-status {
    padding: 8px 10px;
    border-radius: 10px;
    background: rgba(37, 99, 235, 0.22);
    color: #bfdbfe;
    font-size: 13px;
    border: 1px solid rgba(147, 197, 253, 0.28);
}

.terminal-ai-screenshot {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 10px;
    border-radius: 12px;
    border: 1px solid rgba(96, 165, 250, 0.34);
    background: rgba(2, 6, 23, 0.54);
}

.terminal-ai-screenshot-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    color: #dbeafe;
    font-size: 13px;
}

.terminal-ai-screenshot-meta {
    color: #93c5fd;
    font-size: 12px;
    line-height: 1.45;
}

.terminal-ai-screenshot-frame {
    min-height: 160px;
    max-height: 320px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    border-radius: 10px;
    border: 1px dashed rgba(148, 163, 184, 0.28);
    background: #020617;
}

.terminal-ai-screenshot-frame img {
    display: block;
    max-width: 100%;
    max-height: 320px;
    object-fit: contain;
    cursor: zoom-in;
}

.terminal-ai-log {
    min-height: 0;
    max-height: 260px;
    overflow: auto;
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    gap: 6px;
    font-size: 12px;
    overscroll-behavior: contain;
}

.terminal-ai-log-item,
.terminal-ai-plan {
    margin: 0;
    padding: 8px;
    border-radius: 8px;
    background: rgba(15, 23, 42, 0.64);
    border: 1px solid rgba(148, 163, 184, 0.24);
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    backdrop-filter: blur(8px) saturate(120%);
    -webkit-backdrop-filter: blur(8px) saturate(120%);
}

.terminal-ai-log-command {
    font-family: "Cascadia Mono", "Consolas", monospace;
    color: #93c5fd;
}

.terminal-ai-log-stream {
    position: relative;
    border-left: 3px solid rgba(96, 165, 250, 0.72);
    color: #dbeafe;
}

.terminal-ai-log-stream::after {
    content: '';
    display: inline-block;
    width: 6px;
    height: 1em;
    margin-left: 4px;
    vertical-align: -0.15em;
    border-radius: 999px;
    background: rgba(147, 197, 253, 0.78);
    animation: terminal-ai-caret 1s ease-in-out infinite;
}

.terminal-ai-log-stream-command_preview {
    font-family: "Cascadia Mono", "Consolas", monospace;
    color: #bfdbfe;
    border-left-color: rgba(251, 191, 36, 0.72);
}

.terminal-ai-log-image {
    display: flex;
    flex-direction: column;
    gap: 8px;
    white-space: normal;
}

.terminal-ai-image-meta {
    color: #bfdbfe;
    font-size: 12px;
    line-height: 1.45;
}

.terminal-ai-log-image img {
    display: block;
    max-width: 100%;
    max-height: 320px;
    object-fit: contain;
    border-radius: 8px;
    border: 1px solid rgba(148, 163, 184, 0.28);
    background: #020617;
    cursor: zoom-in;
}

.terminal-ai-image-actions {
    display: flex;
    justify-content: flex-end;
}

.terminal-ai-image-viewer {
    position: fixed;
    inset: 0;
    z-index: 5000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: rgba(2, 6, 23, 0.82);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.terminal-ai-image-viewer-dialog {
    width: min(1080px, 100%);
    max-height: calc(100vh - 48px);
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 14px;
    border-radius: 16px;
    border: 1px solid rgba(148, 163, 184, 0.32);
    background: rgba(15, 23, 42, 0.96);
    color: #e5e7eb;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.58);
}

.terminal-ai-image-viewer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.terminal-ai-image-viewer-header h3 {
    margin: 0;
    font-size: 16px;
}

.terminal-ai-image-viewer-meta {
    color: #93c5fd;
    font-size: 12px;
}

.terminal-ai-image-viewer-body {
    min-height: 0;
    flex: 1 1 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: auto;
    border-radius: 12px;
    background: #020617;
}

.terminal-ai-image-viewer-body img {
    display: block;
    max-width: 100%;
    max-height: calc(100vh - 170px);
    object-fit: contain;
}

@keyframes terminal-ai-caret {
    0%, 100% {
        opacity: 0.25;
    }
    50% {
        opacity: 1;
    }
}

.terminal-ai-log-warning {
    color: #fde68a;
}

.terminal-ai-log-error {
    color: #fecaca;
}

.terminal-ai-log-success {
    color: #bbf7d0;
}

.terminal-ai-confirm {
    position: absolute;
    inset: 0;
    z-index: 8;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: rgba(2, 6, 23, 0.62);
}

.terminal-ai-confirm-dialog {
    width: min(560px, 100%);
    padding: 18px;
    border-radius: 14px;
    border: 1px solid #7f1d1d;
    background: #111827;
    color: #f8fafc;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.terminal-ai-confirm-dialog h4 {
    margin: 0 0 8px;
    color: #fecaca;
}

.terminal-ai-confirm-dialog pre {
    max-height: 180px;
    overflow: auto;
    padding: 10px;
    border-radius: 8px;
    background: #020617;
    color: #fde68a;
    white-space: pre-wrap;
}

.terminal-ai-confirm-dialog ul {
    padding-left: 20px;
}

.terminal-shortcuts {
    display: none;
    grid-template-columns: repeat(8, minmax(44px, 1fr));
    gap: 6px;
    margin-bottom: 8px;
    padding: 8px;
    border: 1px solid #334155;
    border-radius: 10px;
    background: #0f2a2f;
}

.terminal-shortcuts button {
    min-width: 0;
    min-height: 34px;
    padding: 6px 4px;
    border: 1px solid rgba(226, 232, 240, 0.12);
    border-radius: 6px;
    background: rgba(15, 23, 42, 0.35);
    color: #f8fafc;
    font-size: 11px;
    line-height: 1;
}

.terminal-shortcuts button.active {
    background: #2563eb;
}

@media (hover: hover) {
    .terminal-shortcuts button:hover {
        background: #2563eb;
    }
}

/* Status badges */
.status-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 12px;
    min-width: 60px;
}

.status-badge.connected {
    background: rgba(34, 197, 94, 0.15);
    color: #86efac;
}

.status-badge.disconnected {
    background: rgba(148, 163, 184, 0.15);
    color: #cbd5e1;
}

/* Small buttons */
.btn-sm {
    padding: 6px 12px;
    font-size: 13px;
    border-radius: 6px;
}

.btn-connect {
    background: #16a34a;
}

.btn-connect:hover {
    background: #15803d;
}

.btn-disconnect {
    background: #dc2626;
}

.btn-disconnect:hover {
    background: #b91c1c;
}

.btn-secondary {
    background: #475569;
}

.btn-secondary:hover {
    background: #334155;
}

.btn-android {
    background: #7c3aed;
}

.btn-android:hover {
    background: #6d28d9;
}

.toast-container {
    position: fixed;
    top: 50%;
    left: 50%;
    z-index: 3000;
    display: flex;
    max-width: min(420px, calc(100vw - 32px));
    transform: translate(-50%, -50%);
    pointer-events: none;
}

.toast-message {
    min-width: 220px;
    padding: 14px 18px;
    border: 1px solid rgba(148, 163, 184, 0.35);
    border-radius: 12px;
    background: rgba(15, 23, 42, 0.96);
    color: #e2e8f0;
    box-shadow: 0 18px 48px rgba(0, 0, 0, 0.38);
    font-size: 14px;
    line-height: 1.5;
    text-align: center;
    opacity: 0;
    transform: scale(0.96) translateY(8px);
    transition: opacity 0.18s ease, transform 0.18s ease;
    overflow-wrap: anywhere;
}

.toast-message.show {
    opacity: 1;
    transform: scale(1) translateY(0);
}

.toast-success {
    border-color: rgba(34, 197, 94, 0.45);
    background: rgba(20, 83, 45, 0.96);
    color: #dcfce7;
}

.toast-error {
    border-color: rgba(248, 113, 113, 0.5);
    background: rgba(127, 29, 29, 0.96);
    color: #fee2e2;
}

.toast-warning {
    border-color: rgba(251, 191, 36, 0.55);
    background: rgba(113, 63, 18, 0.96);
    color: #fef3c7;
}

.toast-info {
    border-color: rgba(96, 165, 250, 0.45);
    background: rgba(30, 58, 138, 0.96);
    color: #dbeafe;
}

.user-secret-modal {
    position: fixed;
    inset: 0;
    z-index: 4000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: rgba(2, 6, 23, 0.78);
}

.user-secret-dialog {
    width: min(420px, 100%);
    padding: 20px;
    border: 1px solid #334155;
    border-radius: 14px;
    background: #111827;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
    color: #e5e7eb;
}

.user-secret-header h3 {
    margin: 0 0 6px;
    font-size: 18px;
}

.user-secret-header p {
    margin: 0 0 16px;
    color: #94a3b8;
    font-size: 13px;
    line-height: 1.5;
}

.user-secret-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    color: #cbd5e1;
    font-size: 13px;
}

.user-secret-field input {
    width: 100%;
    box-sizing: border-box;
    padding: 10px 12px;
    border: 1px solid #334155;
    border-radius: 10px;
    background: #020617;
    color: #f8fafc;
    outline: none;
}

.user-secret-field input:focus {
    border-color: #38bdf8;
    box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.18);
}

.user-secret-error {
    min-height: 20px;
    margin: 8px 0 0;
    color: #fecaca;
    font-size: 13px;
}

.user-secret-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 16px;
}

/* Android remote control */
.android-remote-modal,
.android-remote-control-modal,
.android-settings-modal,
.android-keys-modal,
.android-input-modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: rgba(2, 6, 23, 0.78);
}

.android-remote-dialog {
    width: min(560px, 100%);
    height: min(900px, calc(100vh - 48px));
    height: min(900px, calc(100dvh - 48px));
    min-width: 0;
    display: flex;
    flex-direction: column;
    padding: 16px;
    background: #111827;
    border: 1px solid #334155;
    border-radius: 12px;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
}

.android-remote-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    min-width: 0;
    margin-bottom: 8px;
}

.android-remote-header h3 {
    margin: 0;
}

.android-remote-controls {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
    min-width: 0;
}

.android-refresh-control {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 30px;
    padding: 3px 8px;
    border: 1px solid #334155;
    border-radius: 6px;
    background: #0b1220;
    color: #e2e8f0;
    font-size: 12px;
    white-space: nowrap;
}

.android-refresh-control input {
    width: 64px;
    border: 1px solid #475569;
    border-radius: 5px;
    padding: 3px 6px;
    background: #020617;
    color: #e2e8f0;
    font: inherit;
    text-align: center;
}

.android-remote-screen {
    position: relative;
    flex: 1;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    border: 1px solid #1f2937;
    border-radius: 8px;
    background: #020617;
    touch-action: none;
    user-select: none;
}

.android-remote-screen img,
.android-remote-screen canvas {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    user-select: none;
}

.android-remote-screen canvas {
    width: auto;
    height: auto;
}

.android-floating-nav {
    position: absolute;
    left: 50%;
    bottom: 18px;
    z-index: 2;
    display: flex;
    align-items: center;
    gap: 16px;
    min-width: 190px;
    padding: 8px 14px;
    border: 1px solid rgba(226, 232, 240, 0.24);
    border-radius: 999px;
    background: rgba(15, 23, 42, 0.22);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
    backdrop-filter: blur(3px);
    transform: translateX(-50%);
    touch-action: none;
    user-select: none;
    cursor: grab;
}

.android-floating-nav:active {
    cursor: grabbing;
}

.android-floating-nav button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 36px;
    padding: 0;
    border-radius: 999px;
    background: rgba(37, 99, 235, 0.16);
    color: rgba(255, 255, 255, 0.92);
    font-size: 28px;
    font-weight: 700;
    line-height: 1;
    text-shadow: 0 1px 8px rgba(0, 0, 0, 0.45);
}

.android-floating-nav button:hover {
    background: rgba(37, 99, 235, 0.34);
}

.android-floating-nav button:disabled,
.android-floating-nav button:disabled:hover {
    background: rgba(148, 163, 184, 0.12);
    color: rgba(226, 232, 240, 0.42);
}

.android-remote-placeholder {
    position: absolute;
    inset: 0;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    padding: 16px;
    background: #020617;
    color: #94a3b8;
    text-align: center;
    font-size: 10px;
}

.android-remote-placeholder::before {
    content: '';
    width: 38px;
    height: 38px;
    border: 3px solid rgba(148, 163, 184, 0.25);
    border-top-color: #60a5fa;
    border-radius: 50%;
    animation: android-remote-spin 0.9s linear infinite;
}

@keyframes android-remote-spin {
    to {
        transform: rotate(360deg);
    }
}

.android-remote-hint {
    margin-top: 8px;
    font-size: 8px;
    color: #6b7280;
    overflow-wrap: anywhere;
}

.android-remote-hint .hint-warn {
    color: #f59e0b;
}

.android-remote-control-dialog {
    width: min(430px, 100%);
    max-height: min(860px, calc(100vh - 48px));
    max-height: min(860px, calc(100dvh - 48px));
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 18px;
    background: linear-gradient(160deg, #111827, #020617);
    border: 1px solid #334155;
    border-radius: 24px;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.48);
}

.android-remote-control-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.android-remote-control-header h3 {
    margin: 0;
}

.android-remote-control-controls {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 8px;
}

.tv-remote-pad {
    display: flex;
    flex-direction: column;
    gap: 14px;
    min-width: 0;
    padding: 14px;
    border: 1px solid rgba(226, 232, 240, 0.14);
    border-radius: 28px;
    background: radial-gradient(circle at top, rgba(59, 130, 246, 0.18), transparent 42%), #0f172a;
    touch-action: none;
    user-select: none;
}

.tv-remote-row {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
}

.tv-remote-row-top {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.tv-remote-dpad {
    display: grid;
    grid-template-columns: repeat(3, minmax(72px, 1fr));
    grid-template-rows: repeat(3, 58px);
    gap: 10px;
    justify-content: center;
}

.tv-remote-dpad .dpad-up {
    grid-column: 2;
    grid-row: 1;
}

.tv-remote-dpad .dpad-left {
    grid-column: 1;
    grid-row: 2;
}

.tv-remote-dpad .dpad-ok {
    grid-column: 2;
    grid-row: 2;
}

.tv-remote-dpad .dpad-right {
    grid-column: 3;
    grid-row: 2;
}

.tv-remote-dpad .dpad-down {
    grid-column: 2;
    grid-row: 3;
}

.tv-remote-number-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
}

.tv-remote-button {
    min-height: 46px;
    padding: 10px 12px;
    border: 1px solid rgba(226, 232, 240, 0.18);
    border-radius: 999px;
    background: rgba(30, 41, 59, 0.94);
    color: rgba(248, 250, 252, 0.95);
    font-size: 14px;
    font-weight: 800;
    line-height: 1;
    text-shadow: 0 1px 8px rgba(0, 0, 0, 0.45);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06), 0 10px 26px rgba(0, 0, 0, 0.22);
}

.tv-remote-button:hover {
    background: rgba(51, 65, 85, 0.98);
}

.tv-remote-button:active {
    transform: translateY(1px) scale(0.98);
}

.tv-remote-button.dpad-ok {
    min-height: 58px;
    background: #2563eb;
    color: #ffffff;
    font-size: 16px;
}

.tv-remote-button.danger {
    background: #b91c1c;
}

.tv-remote-button:disabled,
.tv-remote-button:disabled:hover {
    background: rgba(148, 163, 184, 0.12);
    color: rgba(226, 232, 240, 0.42);
    box-shadow: none;
    transform: none;
}

.android-remote-control-hint {
    font-size: 11px;
    color: #94a3b8;
    line-height: 1.45;
}

.android-remote-control-hint .hint-warn {
    color: #f59e0b;
}

.android-keys-modal,
.android-settings-modal,
.android-input-modal {
    z-index: 1010;
    background: rgba(2, 6, 23, 0.58);
}

.android-keys-modal,
.android-input-modal {
    background: transparent;
}

.android-input-modal {
    align-items: flex-end;
    padding: 16px;
}

.android-keys-dialog,
.android-settings-dialog,
.android-input-dialog {
    width: min(520px, 100%);
    max-height: min(720px, calc(100vh - 48px));
    max-height: min(720px, calc(100dvh - 48px));
    min-width: 0;
    display: flex;
    flex-direction: column;
    padding: 16px;
    background: #111827;
    border: 1px solid #334155;
    border-radius: 12px;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
}

.android-keys-dialog {
    background: rgba(15, 23, 42, 0.22);
    border: 1px solid rgba(226, 232, 240, 0.24);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
    backdrop-filter: blur(3px);
}

.android-input-dialog {
    width: min(560px, 100%);
    padding: 14px;
    background: rgba(15, 23, 42, 0.28);
    border: 1px solid rgba(226, 232, 240, 0.22);
    border-radius: 16px;
    box-shadow: 0 10px 32px rgba(0, 0, 0, 0.26);
    backdrop-filter: blur(5px);
}

.android-settings-dialog {
    width: min(520px, 100%);
}

.android-keys-header,
.android-settings-header,
.android-input-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    min-width: 0;
    margin-bottom: 12px;
}

.android-keys-header h3,
.android-settings-header h3,
.android-input-header h3 {
    margin: 0;
}

.android-keys-header h3,
.android-input-header h3 {
    color: rgba(255, 255, 255, 0.92);
    text-shadow: 0 1px 8px rgba(0, 0, 0, 0.45);
}

.android-settings-body {
    display: flex;
    flex-direction: column;
    gap: 12px;
    overflow: auto;
}

.android-settings-field {
    display: flex;
    flex-direction: column;
    gap: 8px;
    color: #cbd5e1;
    font-size: 13px;
}

.android-settings-field input,
.android-settings-field select {
    width: 100%;
    border: 1px solid #475569;
    border-radius: 8px;
    padding: 10px 12px;
    background: #020617;
    color: #e2e8f0;
    font: inherit;
}

.android-settings-field small {
    color: #94a3b8;
    line-height: 1.45;
}

.android-settings-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.android-settings-row label {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.android-settings-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 14px;
}

.android-input-field {
    display: flex;
    flex-direction: column;
    gap: 8px;
    color: rgba(226, 232, 240, 0.94);
    font-size: 13px;
    text-shadow: 0 1px 8px rgba(0, 0, 0, 0.45);
}

.android-input-field input {
    width: 100%;
    border: 1px solid rgba(226, 232, 240, 0.24);
    border-radius: 12px;
    padding: 12px 14px;
    background: rgba(2, 6, 23, 0.42);
    color: #f8fafc;
    font: inherit;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.android-input-field input::placeholder {
    color: rgba(203, 213, 225, 0.72);
}

.android-input-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-top: 12px;
}

.android-input-actions button {
    min-width: 0;
}

.android-keys-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
    gap: 8px;
    min-width: 0;
    overflow: auto;
    padding-right: 2px;
}

.android-key-button {
    min-height: 36px;
    padding: 8px 10px;
    border: 1px solid rgba(226, 232, 240, 0.24);
    border-radius: 999px;
    background: rgba(37, 99, 235, 0.16);
    color: rgba(255, 255, 255, 0.92);
    font-size: 13px;
    font-weight: 700;
    text-shadow: 0 1px 8px rgba(0, 0, 0, 0.45);
}

.android-key-button:hover {
    background: rgba(37, 99, 235, 0.34);
}

.android-key-button:disabled,
.android-key-button:disabled:hover {
    background: rgba(148, 163, 184, 0.12);
    color: rgba(226, 232, 240, 0.42);
}

@media (max-width: 720px) {
    .terminal-modal,
    .android-remote-modal,
    .android-remote-control-modal,
    .android-settings-modal,
    .android-keys-modal,
    .android-input-modal {
        align-items: stretch;
        justify-content: stretch;
        padding: 0;
    }

    .terminal-dialog,
    .android-remote-dialog,
    .android-remote-control-dialog,
    .android-settings-dialog,
    .android-keys-dialog {
        width: 100%;
        height: 100vh;
        height: 100dvh;
        max-height: none;
        border-radius: 0;
        padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
    }

    .terminal-dialog {
        height: var(--terminal-vv-height, 100vh);
        height: var(--terminal-vv-height, 100dvh);
        max-height: var(--terminal-vv-height, 100vh);
        max-height: var(--terminal-vv-height, 100dvh);
    }

    .android-input-modal {
        align-items: flex-end;
        justify-content: center;
        padding: 12px;
    }

    .android-input-dialog {
        width: 100%;
        height: auto;
        max-height: calc(100vh - 24px);
        max-height: calc(100dvh - 24px);
        border-radius: 16px;
        padding: 12px;
    }

    .terminal-header,
    .android-remote-header,
    .android-remote-control-header,
    .android-settings-header,
    .android-keys-header,
    .android-input-header {
        align-items: flex-start;
        flex-direction: column;
        gap: 8px;
        margin-bottom: 6px;
    }

    .terminal-header h3 {
        display: none;
    }

    .terminal-controls,
    .android-remote-controls,
    .android-remote-control-controls {
        justify-content: flex-start;
        width: 100%;
        gap: 6px;
    }

    .terminal-controls .btn-sm,
    .terminal-controls .status-badge {
        flex: 1 1 auto;
        min-height: 20px;
        padding: 4px 7px;
        font-size: 8px;
    }

    .android-remote-controls .btn-sm,
    .android-remote-controls .status-badge,
    .android-remote-control-controls .btn-sm,
    .android-remote-control-controls .status-badge {
        flex: 1 1 auto;
        min-height: 20px;
        padding: 4px 7px;
        font-size: 8px;
    }

    .terminal-wrapper .xterm {
        padding: 4px;
    }

    .terminal-ai-fab {
        right: 16px;
        bottom: calc(54px + env(safe-area-inset-bottom));
        width: 44px;
        height: 44px;
    }

    .terminal-ai-panel {
        left: 8px;
        right: 8px;
        bottom: calc(64px + env(safe-area-inset-bottom));
        width: auto;
        max-height: min(52vh, calc(100% - 92px));
        max-height: min(52dvh, calc(100% - 92px));
        gap: 7px;
        padding: 10px;
        border-radius: 12px;
    }

    .terminal-ai-panel-header {
        flex: 0 0 auto;
        align-items: center;
        gap: 6px;
    }

    .terminal-ai-panel-header strong {
        min-width: 0;
        font-size: 12px;
    }

    .terminal-ai-actions {
        flex: 0 0 auto;
        justify-content: flex-end;
        gap: 4px;
    }

    .terminal-ai-actions .btn-sm {
        flex: 0 0 auto;
        min-height: 24px;
        padding: 4px 7px;
        font-size: 10px;
    }

    .terminal-ai-panel textarea {
        flex: 0 0 auto;
        min-height: 66px;
        max-height: 118px;
        padding: 8px;
        font-size: 12px;
        resize: none;
    }

    .terminal-ai-status {
        flex: 0 0 auto;
        padding: 6px 8px;
        font-size: 11px;
    }

    .terminal-ai-log {
        min-height: 44px;
        max-height: none;
        font-size: 10px;
    }

    .terminal-ai-log-item,
    .terminal-ai-plan {
        padding: 6px;
    }

    .terminal-ai-confirm {
        padding: 12px;
    }

    .android-remote-hint,
    .android-remote-control-hint {
        margin-top: 6px;
        line-height: 1.35;
    }

    .terminal-shortcuts {
        display: grid;
        grid-template-columns: repeat(8, minmax(0, 1fr));
        gap: 3px;
        margin-bottom: 4px;
        padding: 4px;
    }

    .terminal-shortcuts button {
        min-height: 19px;
        padding: 3px 2px;
        font-size: 6px;
    }

    .terminal-modal.terminal-keyboard-compact .terminal-header {
        gap: 4px;
        margin-bottom: 4px;
    }

    .terminal-modal.terminal-keyboard-compact .terminal-shortcuts {
        gap: 4px;
        margin-bottom: 4px;
        padding: 4px;
    }

    .android-input-actions {
        grid-template-columns: 1fr;
    }

    .android-keys-grid {
        grid-template-columns: repeat(auto-fit, minmax(86px, 1fr));
    }

    .tv-remote-pad {
        flex: 1;
        gap: 8px;
        overflow: auto;
        padding: 8px;
    }

    .tv-remote-row,
    .tv-remote-number-grid,
    .tv-remote-dpad {
        gap: 7px;
    }

    .tv-remote-dpad {
        grid-template-columns: repeat(3, minmax(52px, 1fr));
        grid-template-rows: repeat(3, minmax(42px, 1fr));
    }

    .tv-remote-button {
        min-height: 34px;
        padding: 6px 6px;
        font-size: 11px;
    }

    .tv-remote-button.dpad-ok {
        min-height: 42px;
        font-size: 13px;
    }

    .android-floating-nav {
        min-width: 168px;
        gap: 10px;
        padding: 7px 10px;
    }

    .android-floating-nav button {
        width: 40px;
        height: 34px;
        font-size: 24px;
    }
}

@media (max-height: 480px) {
    .terminal-dialog,
    .android-remote-dialog,
    .android-settings-dialog,
    .android-keys-dialog,
    .android-input-dialog {
        padding-top: 8px;
        padding-bottom: 8px;
    }

    .terminal-header,
    .android-remote-header,
    .android-remote-control-header,
    .android-settings-header,
    .android-keys-header,
    .android-input-header {
        gap: 6px;
        margin-bottom: 6px;
    }

    .terminal-header h3,
    .android-remote-header h3,
    .android-settings-header h3,
    .android-keys-header h3,
    .android-input-header h3 {
        font-size: 16px;
    }

    .terminal-controls,
    .android-remote-controls,
    .android-remote-control-controls {
        gap: 6px;
    }

    .terminal-controls .btn-sm,
    .terminal-controls .status-badge,
    .android-remote-controls .btn-sm,
    .android-remote-controls .status-badge,
    .android-remote-control-controls .btn-sm,
    .android-remote-control-controls .status-badge {
        min-height: 30px;
        padding: 4px 8px;
        font-size: 12px;
    }

    .android-remote-hint,
    .android-remote-control-hint {
        margin-top: 4px;
    }

    .android-key-button {
        min-height: 32px;
        padding: 6px 8px;
        font-size: 12px;
    }

    .android-remote-control-dialog {
        gap: 8px;
    }

    .tv-remote-pad {
        gap: 8px;
        padding: 10px;
    }

    .tv-remote-row,
    .tv-remote-number-grid,
    .tv-remote-dpad {
        gap: 7px;
    }

    .tv-remote-dpad {
        grid-template-rows: repeat(3, 44px);
    }

    .tv-remote-button {
        min-height: 38px;
        padding: 6px;
        font-size: 12px;
    }
}
