/* TESAIoT Remote Flash — Dark Theme (matches Desktop App) */
:root {
    --bg-primary: rgb(23, 26, 41);
    --bg-secondary: rgb(13, 15, 23);
    --bg-card: rgba(255, 255, 255, 0.06);
    --bg-card-hover: rgba(255, 255, 255, 0.08);
    --border: rgba(255, 255, 255, 0.10);
    --text-primary: rgba(255, 255, 255, 0.92);
    --text-secondary: rgba(255, 255, 255, 0.55);
    --text-muted: rgba(255, 255, 255, 0.35);
    --accent: #0071E3;
    --accent-hover: #0077ED;
    --green: #34C759;
    --red: #FF3B30;
    --orange: #FF9F0A;
    --cyan: #64D2FF;
    --radius: 12px;
    --radius-sm: 8px;
    --transition: 0.3s ease;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Helvetica Neue', sans-serif;
    background: linear-gradient(160deg, var(--bg-primary), var(--bg-secondary));
    color: var(--text-primary);
    min-height: 100vh;
    transition: background 1.5s ease-in-out;
}

/* Phase-based background colors (matching ContentView.swift) */
body.phase-idle { background: linear-gradient(160deg, rgb(23,26,41), rgb(13,15,23)); }
body.phase-detecting { background: linear-gradient(160deg, rgb(23,31,51), rgb(13,15,28)); }
body.phase-transferring { background: linear-gradient(160deg, rgb(20,31,56), rgb(13,18,33)); }
body.phase-erasing { background: linear-gradient(160deg, rgb(20,31,56), rgb(13,18,33)); }
body.phase-programming { background: linear-gradient(160deg, rgb(18,33,66), rgb(10,18,38)); }
body.phase-resetting { background: linear-gradient(160deg, rgb(18,41,56), rgb(10,23,28)); }
body.phase-success { background: linear-gradient(160deg, rgb(18,41,36), rgb(10,23,18)); }
body.phase-error { background: linear-gradient(160deg, rgb(51,23,23), rgb(28,13,13)); }

.container {
    max-width: 520px;
    margin: 0 auto;
    padding: 24px 20px;
}

/* Header */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}
.header h1 {
    font-size: 18px;
    font-weight: 600;
    letter-spacing: -0.3px;
}
.header .version {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 500;
}
.server-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    color: var(--text-secondary);
}
.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--red);
    transition: background var(--transition);
}
.status-dot.connected { background: var(--green); }
.status-dot.paired { background: var(--cyan); }
.status-dot.transferring, .status-dot.flashing { background: var(--orange); animation: pulse 1.5s infinite; }
.status-dot.success { background: var(--green); }

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* Cards */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    transition: background var(--transition);
}
.card:hover { background: var(--bg-card-hover); }
.card-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    margin-bottom: 10px;
}

/* Pairing Card */
.pairing-code {
    font-family: 'SF Mono', 'Menlo', monospace;
    font-size: 36px;
    font-weight: 700;
    letter-spacing: 4px;
    text-align: center;
    padding: 16px;
    color: var(--cyan);
}
.pairing-code .dash { color: var(--text-muted); margin: 0 4px; }
.pairing-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}
.pairing-timer {
    text-align: center;
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 8px;
}
.pairing-input {
    display: flex;
    gap: 8px;
    align-items: center;
}
.pairing-input input {
    flex: 1;
    background: rgba(255,255,255,0.06);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    font-family: 'SF Mono', monospace;
    font-size: 18px;
    letter-spacing: 2px;
    text-align: center;
    text-transform: uppercase;
    color: var(--text-primary);
    outline: none;
    transition: border var(--transition);
}
.pairing-input input:focus { border-color: var(--accent); }
.pairing-input input::placeholder { color: var(--text-muted); letter-spacing: 1px; font-size: 14px; }

/* Board Card */
.board-info { display: flex; align-items: center; gap: 12px; }
.board-icon {
    width: 40px; height: 40px;
    background: rgba(255,255,255,0.08);
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 20px;
}
.board-details { flex: 1; }
.board-name { font-size: 14px; font-weight: 600; }
.board-mpn { font-size: 11px; color: var(--text-secondary); margin-top: 2px; }
.board-status {
    display: flex; align-items: center; gap: 6px;
    font-size: 12px; color: var(--text-secondary);
    margin-top: 8px;
}

/* Firmware Card */
.firmware-list {
    max-height: 320px;
    overflow-y: auto;
    /* Hide scrollbar chrome — keep scrollability for many firmware entries. */
    scrollbar-width: none;          /* Firefox */
    -ms-overflow-style: none;        /* IE/legacy Edge */
}
.firmware-list::-webkit-scrollbar { display: none; } /* Chrome / Safari / WebKit */

/* ---- Connection card (merged Session + Board) ---- */
.connection-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
    gap: 12px;
}
.connection-new-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
    transition: background var(--transition), color var(--transition), border-color var(--transition);
}
.connection-new-btn:hover {
    background: var(--bg-card-hover);
    border-color: rgba(255, 255, 255, 0.20);
    color: var(--text-primary);
}
.connection-code-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 5px 10px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 6px;
    width: fit-content;
}
.code-chip-label {
    font-size: 9px;
    font-weight: 600;
    letter-spacing: 0.6px;
    color: var(--text-muted);
}
.code-chip-value {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 1px;
    color: var(--text-primary);
}
.connection-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 1px minmax(0, 1.4fr);
    gap: 18px;
    align-items: stretch;
}
.connection-col {
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-width: 0;
}
.connection-col-label {
    font-size: 10px;
    letter-spacing: 0.6px;
    font-weight: 600;
    color: var(--text-muted);
}
.connection-col-body {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--green);
}
.connection-col-text {
    font-size: 13px;
    font-weight: 600;
}
.connection-divider {
    background: var(--border);
    width: 1px;
    align-self: stretch;
}
/* ---- Firmware list — Variant C: Chip-Badge Card ---- */
#firmwareList {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.firmware-item {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    padding: 14px 16px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: background 120ms ease, border-color 120ms ease;
}
.firmware-item:hover {
    background: var(--bg-card-hover);
    border-color: rgba(255, 255, 255, 0.18);
}
.firmware-item.selected {
    border: 2px solid var(--accent);
    background: rgba(0, 113, 227, 0.08);
    padding: 13px 15px;
}
.firmware-item__icon {
    flex: 0 0 72px;
    width: 72px;
    height: 72px;
    border-radius: 16px;
    background: rgba(0, 113, 227, 0.10);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    line-height: 1;
    align-self: stretch;  /* let the tile match the body's vertical extent */
}
.firmware-item__icon img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 16px;
    display: block;
}
.firmware-item__icon-fallback {
    font-size: 32px;
}
.firmware-item__body {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.firmware-item__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}
.firmware-item__title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.01em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.firmware-item__radio {
    flex: 0 0 16px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 1.5px solid var(--text-muted);
    background: transparent;
    position: relative;
    transition: border-color 120ms ease, background 120ms ease;
}
.firmware-item.selected .firmware-item__radio {
    border-color: var(--accent);
    background: var(--accent);
}
.firmware-item.selected .firmware-item__radio::after {
    content: "";
    position: absolute;
    inset: 3px;
    border-radius: 50%;
    background: var(--bg-secondary);
}
.firmware-item__desc {
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.firmware-item__chips {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 2px;
}
.firmware-item__chip {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 10.5px;
    font-weight: 500;
    color: var(--text-secondary);
    background: var(--bg-card);
    border: 1px solid var(--border);
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    white-space: nowrap;
    line-height: 1.4;
}
.firmware-item__chip--accent {
    color: var(--accent);
    background: rgba(0, 113, 227, 0.12);
    border-color: rgba(0, 113, 227, 0.30);
}
.firmware-upload {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100px;
    border: 2px dashed var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
    margin-top: 8px;
}
.firmware-upload:hover { border-color: var(--accent); background: rgba(0,113,227,0.05); }
.firmware-upload.dragover { border-color: var(--accent); background: rgba(0,113,227,0.1); }
.firmware-upload-text { font-size: 12px; color: var(--text-secondary); }
.firmware-upload-icon { font-size: 24px; margin-bottom: 4px; }

/* Progress Card */
.progress-card { display: none; }
.progress-card.visible { display: block; }
.progress-bar-container {
    width: 100%;
    height: 8px;
    background: rgba(255,255,255,0.08);
    border-radius: 4px;
    overflow: hidden;
    margin: 10px 0;
}
.progress-bar {
    height: 100%;
    width: 0%;
    border-radius: 4px;
    transition: width 0.3s ease, background 0.5s ease;
    background: var(--accent);
}
.progress-bar.transferring { background: var(--cyan); }
.progress-bar.erasing { background: var(--orange); }
.progress-bar.programming { background: var(--accent); }
.progress-bar.success { background: var(--green); }
.progress-bar.error { background: var(--red); }
.progress-text {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
}
.progress-phase { color: var(--text-primary); font-weight: 500; }
.progress-percent { color: var(--text-secondary); }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    font-family: inherit;
}
.btn-primary {
    background: var(--accent);
    color: white;
    width: 100%;
    height: 40px;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); transform: translateY(-1px); }
.btn-primary:disabled { opacity: 0.35; cursor: not-allowed; transform: none; }
.btn-secondary {
    background: rgba(255,255,255,0.08);
    color: var(--text-primary);
    border: 1px solid var(--border);
}
.btn-secondary:hover { background: rgba(255,255,255,0.12); }
.btn-sm { padding: 6px 14px; font-size: 12px; height: auto; }
.btn-danger { background: var(--red); color: white; }
.btn-icon { padding: 6px; width: 32px; height: 32px; }

/* Console */
.console-card { display: none; }
.console-card.visible { display: block; }
.console-toggle {
    display: flex; align-items: center; gap: 6px;
    cursor: pointer; font-size: 12px; color: var(--text-secondary);
    user-select: none; margin-top: 8px;
}
.console-toggle .arrow { transition: transform 0.2s; }
.console-toggle.open .arrow { transform: rotate(90deg); }
.console-body {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
}
.console-body.open { max-height: 200px; }
.console-log {
    height: 180px;
    overflow-y: auto;
    font-family: 'SF Mono', 'Menlo', monospace;
    font-size: 11px;
    line-height: 1.6;
    padding: 8px;
    background: rgba(0,0,0,0.3);
    border-radius: var(--radius-sm);
    margin-top: 8px;
}
.log-info { color: var(--text-secondary); }
.log-command { color: var(--text-primary); }
.log-error { color: var(--red); }
.log-success { color: var(--green); }
.log-time { color: var(--text-muted); margin-right: 6px; }

/* Connection indicator at top */
.connection-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 6px;
    font-size: 11px;
    color: var(--text-secondary);
    background: rgba(0,0,0,0.2);
    border-radius: var(--radius-sm);
    margin-bottom: 12px;
}

/* Hidden file input */
.hidden { display: none; }

/* Scrollbar */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 2px; }

/* Responsive */
@media (max-width: 560px) {
    .container { padding: 16px 12px; }
    .pairing-code { font-size: 28px; }
}
