/* ==========================================================================
   LineaSuite CMMS - folha de estilo unica, escrita a mao.
   Sem framework CSS e sem etapa de compilacao: o arquivo vai pronto ao servidor.
   Tema claro e escuro, layout responsivo (mobile first) e contraste conforme
   WCAG 2.2 nivel AA.
   ========================================================================== */

:root {
    --bg: #f5f6f8;
    --surface: #ffffff;
    --surface-2: #eef0f4;
    --border: #d4d8e0;
    --text: #1b1f27;
    --text-muted: #5a616e;
    --primary: #17497a;
    --primary-hover: #10365c;
    --primary-contrast: #ffffff;
    --success: #1c6b3c;
    --success-bg: #e3f3e9;
    --warning: #8a5a00;
    --warning-bg: #fdf1d8;
    --danger: #a02020;
    --danger-bg: #fbe6e6;
    --info: #1a5b78;
    --info-bg: #e2f0f6;
    --radius: 8px;
    --shadow: 0 1px 2px rgba(16, 24, 40, .08), 0 1px 3px rgba(16, 24, 40, .06);
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

[data-theme="dark"] {
    --bg: #12151b;
    --surface: #1a1e26;
    --surface-2: #232935;
    --border: #333b49;
    --text: #e8eaee;
    --text-muted: #a3abb9;
    --primary: #5aa3e0;
    --primary-hover: #7ab6e8;
    --primary-contrast: #0b1017;
    --success: #6bd398;
    --success-bg: #14301f;
    --warning: #f0c060;
    --warning-bg: #33260a;
    --danger: #f08585;
    --danger-bg: #331414;
    --info: #7cc4e0;
    --info-bg: #10262f;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    -webkit-text-size-adjust: 100%;
}

a { color: var(--primary); }
a:hover { color: var(--primary-hover); }

/* Foco sempre visivel: requisito de acessibilidade, nunca remover */
:focus-visible {
    outline: 3px solid var(--primary);
    outline-offset: 2px;
    border-radius: 4px;
}

.skip-link {
    position: absolute;
    left: -9999px;
    background: var(--primary);
    color: var(--primary-contrast);
    padding: .6rem 1rem;
    z-index: 100;
}
.skip-link:focus { left: .5rem; top: .5rem; }

/* ---------------------------------------------------------------- Layout */
.app { display: flex; min-height: 100vh; }

.sidebar {
    width: 244px;
    flex-shrink: 0;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    inset: 0 auto 0 0;
    transform: translateX(-100%);
    transition: transform .18s ease;
    z-index: 40;
}
.sidebar.open { transform: translateX(0); }

.sidebar__brand {
    padding: 1rem;
    border-bottom: 1px solid var(--border);
    font-weight: 700;
    letter-spacing: -.01em;
}
.sidebar__brand small { display: block; font-weight: 400; color: var(--text-muted); font-size: .78rem; }

.sidebar__company {
    padding: .75rem 1rem;
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
    font-size: .85rem;
}
.sidebar__company strong { display: block; }
.sidebar__company a { font-size: .8rem; }

.sidebar__nav { padding: .5rem; overflow-y: auto; flex: 1; }
.sidebar__group { margin-bottom: .75rem; }
.sidebar__group h3 {
    font-size: .7rem;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--text-muted);
    margin: .5rem .5rem .25rem;
}
.sidebar__nav a {
    display: block;
    padding: .5rem .6rem;
    border-radius: var(--radius);
    color: var(--text);
    text-decoration: none;
    font-size: .92rem;
}
.sidebar__nav a:hover { background: var(--surface-2); }
.sidebar__nav a[aria-current="page"] {
    background: var(--primary);
    color: var(--primary-contrast);
    font-weight: 600;
}

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .6rem 1rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 30;
}
.topbar__title {
    font-weight: 600;
    font-size: 1rem;
    margin: 0;
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.content { padding: 1rem; flex: 1; }

@media (min-width: 900px) {
    .sidebar { position: sticky; height: 100vh; transform: none; }
    .sidebar.collapsed { display: none; }
    .content { padding: 1.5rem; }
    .btn-menu { display: none; }
}

/* --------------------------------------------------------------- Cartoes */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1rem;
    margin-bottom: 1rem;
}
.card__title { margin: 0 0 .75rem; font-size: 1rem; font-weight: 600; }

.grid { display: grid; gap: 1rem; grid-template-columns: 1fr; }
@media (min-width: 640px) { .grid.cols-2 { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 900px) {
    .grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
    .grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
}

.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem; }
.stat__label { font-size: .78rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
.stat__value { font-size: 1.9rem; font-weight: 700; line-height: 1.1; margin-top: .2rem; }
.stat__hint { font-size: .8rem; color: var(--text-muted); }

/* --------------------------------------------------------------- Tabelas */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: .6rem .7rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); background: var(--surface-2); }
tbody tr:hover { background: var(--surface-2); }

/* Em telas estreitas a tabela vira lista de cartoes */
@media (max-width: 720px) {
    table.responsive thead { display: none; }
    table.responsive tr { display: block; border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: .6rem; padding: .4rem; }
    table.responsive td { display: flex; justify-content: space-between; gap: 1rem; border: 0; padding: .35rem .4rem; }
    table.responsive td::before {
        content: attr(data-label);
        font-size: .75rem;
        text-transform: uppercase;
        color: var(--text-muted);
        flex-shrink: 0;
    }
}

/* --------------------------------------------------------------- Selos */
/* O status nunca e comunicado so por cor: cada selo traz simbolo + texto. */
.badge {
    display: inline-flex;
    align-items: center;
    gap: .3rem;
    padding: .15rem .5rem;
    border-radius: 999px;
    font-size: .78rem;
    font-weight: 600;
    border: 1px solid transparent;
    white-space: nowrap;
}
.badge--neutral { background: var(--surface-2); color: var(--text-muted); border-color: var(--border); }
.badge--success { background: var(--success-bg); color: var(--success); border-color: currentColor; }
.badge--warning { background: var(--warning-bg); color: var(--warning); border-color: currentColor; }
.badge--danger  { background: var(--danger-bg);  color: var(--danger);  border-color: currentColor; }
.badge--info    { background: var(--info-bg);    color: var(--info);    border-color: currentColor; }

/* --------------------------------------------------------------- Botoes */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .4rem;
    min-height: 44px;               /* alvo de toque adequado em campo */
    padding: .5rem 1rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
}
.btn:hover { background: var(--surface-2); }
.btn--primary { background: var(--primary); border-color: var(--primary); color: var(--primary-contrast); }
.btn--primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); color: var(--primary-contrast); }
.btn--danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn--sm { min-height: 34px; padding: .25rem .6rem; font-size: .85rem; }
.btn-menu { background: transparent; border: 1px solid var(--border); }

.actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: 1rem; }

/* -------------------------------------------------------------- Formulario */
.field { margin-bottom: .9rem; }
.field label { display: block; font-weight: 600; font-size: .88rem; margin-bottom: .25rem; }
.field .hint { font-size: .8rem; color: var(--text-muted); }

input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="date"], input[type="datetime-local"], input[type="search"], select, textarea {
    width: 100%;
    min-height: 44px;
    padding: .5rem .6rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    font: inherit;
}
textarea { min-height: 96px; resize: vertical; }

.field--error input, .field--error select, .field--error textarea { border-color: var(--danger); border-width: 2px; }
.error-text { color: var(--danger); font-size: .82rem; font-weight: 600; margin-top: .2rem; }

.check { display: flex; align-items: center; gap: .5rem; margin-bottom: .5rem; }
.check input { width: 20px; height: 20px; min-height: 0; }

.form-grid { display: grid; gap: 0 1rem; grid-template-columns: 1fr; }
@media (min-width: 720px) { .form-grid.cols-2 { grid-template-columns: 1fr 1fr; } }

/* ---------------------------------------------------------------- Avisos */
.alert {
    padding: .7rem .9rem;
    border-radius: var(--radius);
    border: 1px solid transparent;
    margin-bottom: .8rem;
    font-size: .9rem;
    display: flex;
    gap: .5rem;
    align-items: flex-start;
}
.alert--success { background: var(--success-bg); color: var(--success); border-color: currentColor; }
.alert--error   { background: var(--danger-bg);  color: var(--danger);  border-color: currentColor; }
.alert--info    { background: var(--info-bg);    color: var(--info);    border-color: currentColor; }
.alert--warning { background: var(--warning-bg); color: var(--warning); border-color: currentColor; }

/* ------------------------------------------------------------ Estado vazio */
.empty { text-align: center; padding: 2.5rem 1rem; color: var(--text-muted); }
.empty strong { display: block; color: var(--text); font-size: 1rem; margin-bottom: .25rem; }

/* --------------------------------------------------------------- Diversos */
.filters { display: flex; flex-wrap: wrap; gap: .5rem; align-items: flex-end; margin-bottom: 1rem; }
.filters .field { margin-bottom: 0; flex: 1 1 180px; }

.pagination { display: flex; gap: .35rem; flex-wrap: wrap; margin-top: 1rem; align-items: center; }
.pagination a, .pagination span { padding: .4rem .7rem; border: 1px solid var(--border); border-radius: var(--radius); text-decoration: none; }
.pagination .current { background: var(--primary); color: var(--primary-contrast); border-color: var(--primary); font-weight: 700; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: .6rem 0 .6rem 1rem; border-left: 2px solid var(--border); position: relative; }
.timeline li::before {
    content: "";
    position: absolute;
    left: -5px; top: .95rem;
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--primary);
}
.timeline time { font-size: .8rem; color: var(--text-muted); display: block; }

.dl { display: grid; grid-template-columns: 1fr; gap: .5rem 1rem; margin: 0; }
@media (min-width: 640px) { .dl { grid-template-columns: repeat(2, 1fr); } }
.dl dt { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); }
.dl dd { margin: 0 0 .5rem; }

.muted { color: var(--text-muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.nowrap { white-space: nowrap; }
.text-right { text-align: right; }
.mt-1 { margin-top: .5rem; } .mt-2 { margin-top: 1rem; } .mb-2 { margin-bottom: 1rem; }

/* ------------------------------------------------------ Telas de acesso */
.guest {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: var(--bg);
}
.guest__box { width: 100%; max-width: 420px; }
.guest__brand { text-align: center; margin-bottom: 1.25rem; }
.guest__brand strong { font-size: 1.35rem; display: block; }
.guest__brand span { color: var(--text-muted); font-size: .9rem; }

.secret-key {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 1.05rem;
    letter-spacing: .08em;
    background: var(--surface-2);
    border: 1px dashed var(--border);
    padding: .75rem;
    border-radius: var(--radius);
    word-break: break-all;
    text-align: center;
}
/* --------------------------------------------------------------- Galeria */
.gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: .75rem;
}
.gallery__item {
    margin: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--surface);
}
.gallery__item img {
    display: block;
    width: 100%;
    height: 140px;
    object-fit: cover;
    background: var(--surface-2);
}
.gallery__item figcaption { padding: .5rem; font-size: .78rem; }
.gallery__doc {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: .3rem;
    height: 140px;
    padding: .5rem;
    text-align: center;
    text-decoration: none;
    background: var(--surface-2);
    font-size: .8rem;
}
.gallery__doc span:first-child { font-weight: 700; font-size: 1.1rem; }

input[type="file"] {
    width: 100%;
    padding: .5rem;
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    min-height: 44px;
}

.qr-box {
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 1rem;
    text-align: center;
}
/* O QR precisa de fundo branco mesmo no tema escuro: leitores falham
   com o contraste invertido. */
.qr-box svg { max-width: 100%; height: auto; }

.code-list { display: grid; grid-template-columns: repeat(2, 1fr); gap: .4rem; }
.code-list li {
    list-style: none;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: .4rem;
    text-align: center;
}

@media print {
    .sidebar, .topbar, .actions, .btn { display: none !important; }
    .content { padding: 0; }
    .card { border: 0; box-shadow: none; }
}

/* ------------------------------------------------- Etiquetas QR de ativos */
.label-picker {
    display: grid;
    grid-template-columns: 1fr;
    gap: .15rem;
    max-height: 320px;
    overflow-y: auto;
    padding: .5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
@media (min-width: 720px) { .label-picker { grid-template-columns: 1fr 1fr; } }
.label-picker .check span { display: flex; flex-direction: column; line-height: 1.25; }

.label-sheet {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(var(--etiqueta-largura, 260px), 1fr));
    gap: .5rem;
}
.label-card {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: .5rem;
    background: #ffffff;
    color: #101828;
    border: 1px dashed #98a2b3;
    border-radius: 6px;
    break-inside: avoid;
    page-break-inside: avoid;
}
.label-card__qr { flex: 0 0 auto; line-height: 0; }
.label-card__qr svg { display: block; }
.label-card__text { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.label-card__text strong { font-size: 1rem; }
.label-card__text span { font-size: .78rem; overflow-wrap: break-word; }
.label-card__text .muted { color: #475467; }

@media print {
    .no-print { display: none !important; }
    /* Na folha o numero de colunas e fixo: o que a tela promete no seletor de
       tamanho tem de ser o que sai na impressora. */
    .label-sheet { gap: .35rem; grid-template-columns: repeat(var(--etiqueta-colunas, 3), 1fr); }
    .label-card { border-style: solid; border-color: #d0d5dd; background: #ffffff; }
    body, .app, .main, .content { background: #ffffff; }
}
