/* =========================================================
   RESET & VARIABLES
   ========================================================= */

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --bg:           #ffffff;
    --card-bg:      #0f1623;
    --card-border:  #1e2a3a;
    --input-bg:     #0a0f1a;

    --text:         #1e293b;
    --muted:        #7a8fa8;
    --dim:          #4a5a6e;

    --blue:         #3b82f6;
    --blue-hover:   #2563eb;
    --blue-glow:    rgba(59,130,246,0.25);

    --purple:       #8b5cf6;
    --purple-glow:  rgba(139,92,246,0.25);

    --green-glow:   rgba(16,185,129,0.15);

    --red-bg:       rgba(239,68,68,0.1);
    --red-border:   rgba(239,68,68,0.25);

    --radius:       10px;
    --font:         'Inter', system-ui, sans-serif;
    --mono:         'JetBrains Mono', Consolas, monospace;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* =========================================================
   APP WRAPPER
   ========================================================= */

.app {
    width: 100%;
    max-width: 1400px;
    margin: 0 auto;
    padding: 24px 24px 0;
}

/* =========================================================
   HEADER
   ========================================================= */

.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 22px;
    padding-bottom: 18px;
    border-bottom: 1px solid var(--card-border);
}

.brand {
    display: flex;
    align-items: center;
    gap: 14px;
}

.brand-icon {
    width: 42px;
    height: 42px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--blue), var(--purple));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
    box-shadow: 0 4px 14px var(--blue-glow);
}

.header h1 {
    font-size: 19px;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.header p {
    font-size: 12px;
    color: var(--muted);
    margin-top: 2px;
}

/* Badge */
.badge {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 14px;
    border-radius: 99px;
    font-size: 12px;
    font-weight: 600;
    border: 1px solid var(--card-border);
    white-space: nowrap;
}

.dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--dim);
}

.badge.online {
    color: #34d399;
    background: var(--green-glow);
    border-color: rgba(16,185,129,0.3);
}

.badge.online .dot {
    background: #34d399;
    box-shadow: 0 0 6px #34d399;
}

/* =========================================================
   BODY LAYOUT — LEFT + RIGHT SIDE BY SIDE
   ========================================================= */

.body-layout {
    display: grid;
    grid-template-columns: 360px 1fr;
    gap: 18px;
    align-items: start;
}

/* Left: stacked cards */
.left-panel {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

/* Right: terminal fills full height */
.right-panel {
    position: sticky;
    top: 16px;
}

.right-panel .console-card {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 120px);
    min-height: 480px;
}

.right-panel .console {
    flex: 1;
    min-height: 0;
}

/* =========================================================
   CARDS
   ========================================================= */

.card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--radius);
    padding: 16px;
}

.card-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 600;
    color: #f1f5f9;
    margin-bottom: 14px;
}

/* =========================================================
   DEVICE INFO
   ========================================================= */

.device-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.info-box {
    background: var(--input-bg);
    border: 1px solid var(--card-border);
    border-radius: 8px;
    padding: 9px 11px;
}

.info-label {
    display: block;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--dim);
    margin-bottom: 3px;
}

.info-value {
    font-family: var(--mono);
    font-size: 12px;
    color: #f1f5f9;
    word-break: break-all;
}

/* =========================================================
   BUTTONS
   ========================================================= */

.button-row,
.flash-buttons {
    display: flex;
    gap: 8px;
    margin-top: 14px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 14px;
    border: none;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 600;
    font-family: var(--font);
    cursor: pointer;
    transition: transform 0.15s, opacity 0.15s, background 0.15s;
}

.btn:hover:not(:disabled) { transform: translateY(-1px); }
.btn:active:not(:disabled) { transform: none; }
.btn:disabled { opacity: 0.35; cursor: not-allowed; }

.primary {
    background: var(--blue);
    color: #fff;
    box-shadow: 0 3px 10px var(--blue-glow);
}
.primary:hover:not(:disabled) { background: var(--blue-hover); }

.secondary {
    background: rgba(255,255,255,0.05);
    color: #f1f5f9;
    border: 1px solid var(--card-border);
}
.secondary:hover:not(:disabled) { background: rgba(255,255,255,0.09); }

.danger {
    background: var(--red-bg);
    color: #fca5a5;
    border: 1px solid var(--red-border);
}
.danger:hover:not(:disabled) { background: rgba(239,68,68,0.18); }

.flash {
    flex: 1;
    background: linear-gradient(135deg, var(--blue), var(--purple));
    color: #fff;
    font-size: 13px;
    box-shadow: 0 3px 12px var(--purple-glow);
}

/* =========================================================
   FIRMWARE FILES (CORRIGIDO)
   ========================================================= */

.firmware-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 88px; /* Impede estouro de layout */
    gap: 8px;
    margin-bottom: 10px;
}

.firmware-row:last-child { margin-bottom: 0; }

.firmware-info {
    min-width: 0; /* Permite encolhimento correto dentro de layouts flex/grid */
}

label {
    display: block;
    font-size: 11px;
    font-weight: 500;
    color: var(--muted);
    margin-bottom: 5px;
}

.file-box {
    display: flex;
    align-items: center;
    height: 34px;
    background: var(--input-bg);
    border: 1px solid var(--card-border);
    border-radius: 8px;
    overflow: hidden;
    min-width: 0; /* Impede estouro em flexbox */
}

.file-box span {
    flex: 1;
    min-width: 0; /* Garante que o texto possa encolher */
    padding: 0 10px;
    font-size: 11px;
    color: var(--dim);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis; /* Corta o nome longo com '...' */
}

.file-box input[type="file"] { display: none; }

.file-button {
    height: 100%;
    display: flex;
    align-items: center;
    padding: 0 11px;
    font-size: 11px;
    font-weight: 500;
    color: var(--muted);
    background: rgba(255,255,255,0.04);
    border-left: 1px solid var(--card-border);
    cursor: pointer;
    margin-bottom: 0;
    transition: background 0.15s, color 0.15s;
    white-space: nowrap;
    flex-shrink: 0; /* Impede o botão Browse de espremer */
}

.file-button:hover {
    background: rgba(255,255,255,0.09);
    color: #f1f5f9;
}

.address input {
    width: 100%;
    height: 34px;
    padding: 0 10px;
    background: var(--input-bg);
    border: 1px solid var(--card-border);
    border-radius: 8px;
    color: #f1f5f9;
    font-family: var(--mono);
    font-size: 12px;
    outline: none;
    transition: border-color 0.2s;
}

.address input:focus { border-color: var(--blue); }

/* =========================================================
   PROGRESS
   ========================================================= */

.progress-wrapper { margin-bottom: 14px; }

.progress-info {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: var(--muted);
    margin-bottom: 6px;
}

.progress-container {
    height: 8px;
    background: var(--input-bg);
    border: 1px solid var(--card-border);
    border-radius: 99px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--blue), var(--purple));
    border-radius: 99px;
    transition: width 0.3s ease;
}

.sr-only { display: none; }

/* =========================================================
   CONSOLE / TERMINAL
   ========================================================= */

.card-title .clear-button {
    margin-left: auto;
    background: transparent;
    border: none;
    color: var(--dim);
    font-size: 11px;
    font-family: var(--font);
    cursor: pointer;
    padding: 3px 8px;
    border-radius: 5px;
    transition: color 0.15s, background 0.15s;
}

.card-title .clear-button:hover {
    color: #f1f5f9;
    background: rgba(255,255,255,0.06);
}

.console {
    background: #03050a;
    border: 1px solid var(--card-border);
    border-radius: 8px;
    padding: 14px;
    height: 220px;
    overflow-y: auto;
    font-family: var(--mono);
    font-size: 11.5px;
    line-height: 1.7;
}

.console::-webkit-scrollbar { width: 5px; }
.console::-webkit-scrollbar-track { background: transparent; }
.console::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 3px; }

.console-line          { color: #7a90a8; white-space: pre-wrap; word-break: break-all; }
.console-line.system   { color: #60a5fa; }
.console-line.success  { color: #34d399; }
.console-line.error    { color: #f87171; }
.console-line.warning  { color: #fbbf24; }

/* =========================================================
   FOOTER
   ========================================================= */

footer {
    display: flex;
    justify-content: space-between;
    padding: 14px 2px 16px;
    margin-top: 16px;
    color: var(--dim);
    font-size: 11px;
}

footer strong { color: var(--muted); }

/* =========================================================
   RESPONSIVE
   ========================================================= */

@media (max-width: 860px) {
    .body-layout {
        grid-template-columns: 1fr;
    }
    .right-panel {
        position: static;
    }
    .right-panel .console-card {
        height: auto;
    }
    .right-panel .console {
        height: 280px;
        flex: none;
    }
}

@media (max-width: 520px) {
    .app { padding: 14px 12px 0; }
    .header { flex-direction: column; align-items: flex-start; gap: 12px; }
    .device-grid { grid-template-columns: 1fr; }
    .firmware-row { grid-template-columns: 1fr; }
    .button-row, .flash-buttons { flex-direction: column; }
    .btn { width: 100%; }
}
