/* ===================================================================
   TMG · Rastreabilidade — stylesheet
   -------------------------------------------------------------------
   Linguagem visual alinhada de propósito com o Production Hub (Hyline):
   fundo claro, cartões brancos arredondados com sombra suave, azul
   petróleo como cor de marca, Inter como tipografia, Font Awesome
   para ícones. Reaproveita os mesmos tokens/nomes de classe onde
   possível, para que a demo pareça a mesma família de produto.
   =================================================================== */

:root {
    --brand:        #0a2647;
    --brand-2:      #153a63;
    --danger:       #d93025;
    --accent:       #3498db;
    --accent-dark:  #2c80b4;
    --ok:           #27ae60;
    --warn:         #f39c12;
    --bg:           #f4f7f6;
    --card:         #ffffff;
    --border:       #f0f2f5;
    --border-soft:  #f5f5f5;
    --text:         #333333;
    --text-muted:   #888888;
    --text-faint:   #aaaaaa;

    --radius-sm: 12px;
    --radius-md: 20px;
    --radius-lg: 30px;

    --shadow-sm: 0 2px 15px rgba(0,0,0,.05);
    --shadow-md: 0 10px 30px rgba(0,0,0,.03);
    --shadow-lg: 0 20px 60px rgba(0,0,0,.08);
}

* , *::before, *::after { box-sizing: border-box; }

body {
    font-family: 'Inter', -apple-system, Segoe UI, Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    margin: 0;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--brand); }

/* ---------------- NAVBAR ---------------- */
.navbar {
    background: var(--card);
    padding: 15px 40px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 0;
    z-index: 1000;
}
.logo-container { display: inline-flex; align-items: center; gap: 0; text-decoration: none; }
.logo-badge {
    width: 40px; height: 40px;
    border-radius: 50%;
    background: var(--brand);
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
}
.logo-divider { display: inline-block; width: 1px; height: 38px; background: rgba(10,38,71,.18); margin: 0 14px; flex-shrink: 0; }
.logo-text { display: flex; flex-direction: column; justify-content: center; line-height: 1.1; }
.logo-text h1 { font-size: 18px; color: var(--brand); font-weight: 800; letter-spacing: -.5px; }
.logo-text span { font-size: 10px; color: var(--text-faint); text-transform: uppercase; font-weight: 700; display: block; }

.nav-actions { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.user-info {
    font-size: 11px; font-weight: 700; color: var(--text-muted);
    text-transform: uppercase; display: flex; align-items: center; gap: 8px;
}
.nav-link { font-size: 11px; font-weight: 700; text-transform: uppercase; color: #666; display: flex; align-items: center; gap: 6px; }
.nav-link:hover { color: var(--brand); }

.btn-circle {
    width: 35px; height: 35px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    text-decoration: none; transition: .3s; font-size: 14px;
}
.btn-sair { background: #fff1f0; color: var(--danger); border: 1px solid #ffd8d6; }
.btn-sair:hover { background: var(--danger); color: #fff; }

/* ---------------- LAYOUT ---------------- */
.main-layout { max-width: 900px; margin: 40px auto; padding: 0 20px; }
.main-layout.wide { max-width: 1200px; }

.card {
    background: var(--card);
    padding: 30px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    position: relative;
    margin-bottom: 20px;
}
.card h2.section-title {
    font-weight: 800; text-transform: uppercase; letter-spacing: 1px;
    font-size: 13px; color: var(--brand);
    border-bottom: 1px solid var(--border-soft);
    padding-bottom: 15px; margin-bottom: 20px;
}
.subtitle { color: var(--text-muted); font-size: 13px; margin: 6px 0 0; }

/* ---------------- STEP TRACK ---------------- */
.step-track { display: flex; gap: 24px; flex-wrap: wrap; }
.step { display: flex; align-items: center; gap: 10px; font-size: 12px; font-weight: 700; color: var(--text-faint); text-transform: uppercase; }
.step .dot {
    width: 26px; height: 26px; border-radius: 50%;
    background: var(--border); color: var(--text-faint);
    display: flex; align-items: center; justify-content: center; font-size: 12px;
}
.step.active { color: var(--brand); }
.step.active .dot { background: var(--accent); color: #fff; }
.step.done { color: var(--ok); }
.step.done .dot { background: var(--ok); color: #fff; }

/* ---------------- FORMS ---------------- */
label {
    display: block; font-size: 10px; color: var(--text-faint);
    text-transform: uppercase; font-weight: 700; margin-bottom: 8px; margin-left: 5px;
}
select, input[type=text], input[type=password], textarea {
    width: 100%; padding: 15px; border: 2px solid var(--border);
    margin-bottom: 15px; font-size: 14px; border-radius: var(--radius-md);
    font-family: 'Inter', sans-serif; outline: none; background: #fdfdfd;
    transition: border-color .2s, background .2s;
}
textarea { resize: vertical; }
select:focus, input:focus, textarea:focus { border-color: var(--accent); background: #fff; }
input[disabled] { opacity: .6; }

/* Botões lado a lado (ex.: Registar defeito + Trocar material) */
.btn-row { display: flex; gap: 12px; margin-bottom: 15px; }
.btn-row > * { flex: 1; margin-bottom: 0; }

/* Cartão do topo do posto de leitura: step-track + botão "Defeito", que
   fica sempre visível independentemente do passo em que o operador está. */
.step-track-row { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; }
.btn-defeito-topo { width: auto; padding: 12px 22px; flex: 0 0 auto; }

/* Barra de filtros (ex.: página de Defeitos) */
.filtro-row { display: flex; gap: 16px; flex-wrap: wrap; align-items: flex-end; }
.filtro-row > div { flex: 1; min-width: 200px; }
.filtro-row select { margin-bottom: 0; }
.filtro-acoes { display: flex; gap: 10px; flex: 0 0 auto; }
.filtro-acoes .btn-submit, .filtro-acoes .btn-secondary { width: auto; padding: 15px 20px; white-space: nowrap; }

.btn-submit, button.btn-submit {
    width: 100%; padding: 18px; background: var(--brand); color: #fff; border: none;
    cursor: pointer; font-weight: 700; text-transform: uppercase;
    border-radius: var(--radius-md); transition: .3s; letter-spacing: 1px; font-size: 13px;
}
.btn-submit:hover { background: var(--accent); transform: translateY(-2px); }
.btn-submit:disabled { opacity: .5; cursor: not-allowed; transform: none; }

.btn-secondary {
    width: 100%; padding: 14px; background: #fff; color: var(--text-muted);
    border: 2px solid var(--border); cursor: pointer; font-weight: 700;
    text-transform: uppercase; border-radius: var(--radius-md); font-size: 12px; letter-spacing: .5px;
}
.btn-secondary:hover { border-color: var(--accent); color: var(--brand); }

.btn-finish {
    background: var(--danger); color: #fff; border: none; padding: 16px 20px;
    cursor: pointer; font-size: 13px; font-weight: 800; letter-spacing: .5px;
    text-transform: uppercase; border-radius: var(--radius-md); width: 100%;
}
.btn-start {
    background: var(--ok); color: #fff; border: none; padding: 16px 20px;
    cursor: pointer; font-size: 13px; font-weight: 800; letter-spacing: .5px;
    text-transform: uppercase; border-radius: var(--radius-md); width: 100%;
}

/* ---------------- MESSAGES ---------------- */
.erro-msg, .msg.error {
    background: #fff0f0; color: var(--danger); padding: 14px 16px; border-radius: var(--radius-sm);
    font-size: 13px; font-weight: 600; margin-bottom: 16px; border: 1px solid #ffdada;
    display: flex; align-items: center; gap: 10px;
}
.ok-msg, .msg.ok {
    background: #eafbf1; color: var(--ok); padding: 14px 16px; border-radius: var(--radius-sm);
    font-size: 13px; font-weight: 600; margin-bottom: 16px; border: 1px solid #c8f0da;
    display: flex; align-items: center; gap: 10px;
}
.msg.warn {
    background: #fff8ec; color: var(--warn); padding: 14px 16px; border-radius: var(--radius-sm);
    font-size: 13px; font-weight: 600; margin-bottom: 16px; border: 1px solid #ffe6bd;
}

/* ---------------- LOGIN ---------------- */
body.login-body { height: 100vh; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.login-card {
    background: var(--card); padding: 50px 40px; border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg); width: 100%; max-width: 400px; text-align: center;
    border: 1px solid rgba(0,0,0,.05);
}
.login-card .logo-badge { margin: 0 auto 20px; }
.login-card h1 { font-size: 20px; color: var(--brand); font-weight: 800; margin-bottom: 6px; }
.login-card .input-group { margin-bottom: 18px; text-align: left; }
.login-card .input-wrapper { position: relative; display: flex; align-items: center; }
.login-card .input-wrapper i { position: absolute; left: 15px; color: #ccc; font-size: 14px; }
.login-card input { padding-left: 45px; border-radius: var(--radius-sm); margin-bottom: 0; }
.btn-login {
    width: 100%; padding: 18px; background: var(--brand); color: #fff; border: none;
    border-radius: var(--radius-sm); font-weight: 700; font-size: 14px; text-transform: uppercase;
    cursor: pointer; transition: all .3s ease; margin-top: 20px; letter-spacing: 1px;
}
.btn-login:hover { background: var(--brand-2); transform: translateY(-2px); box-shadow: 0 10px 20px rgba(10,38,71,.2); }
.footer-info { font-size: 10px; color: #ccc; margin-top: 30px; font-weight: 600; letter-spacing: .5px; }

/* ---------------- INFO / KPI ---------------- */
.info-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 20px; margin: 16px 0; font-size: 14px; }
.info-grid div span { display: block; color: var(--text-faint); font-size: 10px; text-transform: uppercase; font-weight: 700; margin-bottom: 2px; }

.kpi-row { display: flex; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.kpi { flex: 1; min-width: 140px; background: var(--card); border-radius: var(--radius-md); box-shadow: var(--shadow-md); padding: 20px; }
.kpi .value { font-size: 26px; font-weight: 800; color: var(--brand); }
.kpi .label { color: var(--text-faint); font-size: 10px; text-transform: uppercase; font-weight: 700; margin-top: 4px; }

/* ---------------- TABLE ---------------- */
table.tmg-table { width: 100%; border-collapse: collapse; font-size: 13px; background: var(--card); border-radius: var(--radius-sm); overflow: hidden; }
table.tmg-table th, table.tmg-table td { padding: 10px 14px; border-bottom: 1px solid var(--border); text-align: left; }
table.tmg-table th { background: #fafbfc; color: var(--text-muted); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; }
table.tmg-table tr:last-child td { border-bottom: none; }

/* ---------------- PILLS ---------------- */
.pill { display: inline-block; padding: 5px 12px; border-radius: 999px; font-size: 11px; font-weight: 700; text-transform: uppercase; background: var(--border); color: var(--text-muted); }
.pill.ok   { background: #eafbf1; color: var(--ok); }
.pill.warn { background: #fff8ec; color: var(--warn); }
.pill.danger { background: #fff0f0; color: var(--danger); }

/* ---------------- BARCODE LABELS ---------------- */
.barcode-block { text-align: center; padding: 20px; background: #fff; border: 1px solid var(--border); border-radius: var(--radius-md); }
.barcode-block .label { color: var(--brand); font-weight: 700; margin-top: 8px; font-size: 13px; }
.barcode-block .sub { color: var(--text-faint); font-size: 11px; text-transform: uppercase; font-weight: 700; }

/* ---------------- UTIL ---------------- */
.text-muted { color: var(--text-muted); }
.text-red { color: var(--danger); }
.text-ok { color: var(--ok); }
.mono { font-family: ui-monospace, Consolas, monospace; }
.slide-container { animation: slideIn .4s ease forwards; }
@keyframes slideIn { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: translateY(0); } }

/* ---------------- MAPA DA FÁBRICA (planta arquitetónica) ---------------- */
/* overflow-y tem de ficar "visible" explícito: ao definir só overflow-x,
   as regras de CSS emparelham overflow-y para "auto", o que cortava a
   planta em baixo/à direita sempre que a altura calculada do SVG não
   coincidia exatamente com a área visível. aspect-ratio fixo no SVG evita
   depender do cálculo de "height:auto" para saber a proporção correta. */
.planta-wrap { width: 100%; overflow-x: auto; overflow-y: visible; }
.planta-svg { width: 100%; min-width: 720px; aspect-ratio: 1400 / 700; height: auto; display: block; }
.planta-svg .pin circle:first-child { transition: stroke .2s; }
.planta-svg .pin:hover circle:first-child { stroke: var(--accent); }
.planta-svg .pulse-svg {
    animation: pulse-svg-anim 1.8s infinite;
    transform-origin: center;
}
@keyframes pulse-svg-anim {
    0%   { opacity: 1; }
    50%  { opacity: .55; }
    100% { opacity: 1; }
}

#painel-maquina .status-dot-row { margin-bottom: 16px; }

/* (mantido para compatibilidade — já não usado pelo mapa, que agora é uma
   planta SVG, mas útil se quiseres voltar a uma vista em grelha) */
.planta {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 20px;
}

.zona {
    background: #fbfcfd;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
}
.zona-titulo {
    display: flex; align-items: center; gap: 10px;
    font-size: 13px; font-weight: 800; text-transform: uppercase; letter-spacing: .5px;
    color: var(--brand); margin-bottom: 16px;
}
.zona-titulo .icon-badge {
    width: 30px; height: 30px; border-radius: 50%;
    background: var(--brand); color: #fff;
    display: flex; align-items: center; justify-content: center; font-size: 13px;
}

.maquina-box {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 16px;
    margin-bottom: 14px;
    box-shadow: var(--shadow-sm);
}
.maquina-box:last-child { margin-bottom: 0; }
.maquina-box .maquina-nome { font-weight: 700; font-size: 14px; color: var(--text); margin-bottom: 6px; }

.status-dot-row { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.status-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--text-faint); flex-shrink: 0; }
.status-dot.livre { background: #cfd8dc; }
.status-dot.producao { background: var(--ok); box-shadow: 0 0 0 0 rgba(39,174,96,.5); animation: pulse-dot 1.8s infinite; }
@keyframes pulse-dot {
    0%   { box-shadow: 0 0 0 0 rgba(39,174,96,.5); }
    70%  { box-shadow: 0 0 0 6px rgba(39,174,96,0); }
    100% { box-shadow: 0 0 0 0 rgba(39,174,96,0); }
}
.status-label { font-size: 11px; font-weight: 700; text-transform: uppercase; color: var(--text-muted); }
.status-label.producao { color: var(--ok); }

.maquina-box select {
    margin-bottom: 12px; padding: 10px 12px; font-size: 12px; border-radius: var(--radius-sm);
}
.maquina-box select:disabled { color: var(--text-faint); background: #f9f9f9; }

.btn-detalhe {
    display: block; width: 100%; text-align: center;
    padding: 10px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px;
    background: var(--border); color: var(--brand); border-radius: var(--radius-sm);
}
.btn-detalhe:hover { background: var(--brand); color: #fff; }

@media (max-width: 900px) {
    .navbar { padding: 15px 20px; }
    .info-grid { grid-template-columns: 1fr; }
}
@media (max-width: 520px) {
    .navbar { flex-direction: column; gap: 10px; padding: 12px 16px; }
    .card { padding: 20px; border-radius: var(--radius-md); }
}