:root {
    --bg: #f3f8fb;
    --ink: #102434;
    --muted: #5b7181;
    --line: #cfe0ea;
    --primary: #0072a7;
    --primary-dark: #00547d;
    --panel: #ffffff;
    --warn: #b8571d;
}

* { box-sizing: border-box; }
html {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
}
body {
    margin: 0;
    font-family: Arial, Helvetica, sans-serif;
    color: var(--ink);
    background: var(--bg);
    min-height: 100vh;
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
    touch-action: manipulation;
    -webkit-text-size-adjust: 100%;
}
a { color: var(--primary); text-decoration: none; }
a, button, .button, input, select, textarea, label {
    touch-action: manipulation;
}
.top {
    display: flex;
    align-items: center;
    gap: 16px;
    min-height: 76px;
    padding: 10px 20px;
    border-bottom: 1px solid var(--line);
    background: #fff;
    position: relative;
    z-index: 8;
    width: 100%;
    max-width: 100vw;
    overflow: hidden;
}
.menu-button {
    width: 48px;
    height: 48px;
    border: 1px solid var(--line);
    border-radius: 8px;
    display: inline-grid;
    place-items: center;
    color: var(--primary-dark);
    background: #e8f4fa;
    cursor: pointer;
}
.brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    color: var(--ink);
    white-space: nowrap;
}
.brand img {
    width: 46px;
    height: 46px;
    object-fit: contain;
}
.nav-toggle { display: none; }
.nav-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(16,36,52,.24);
    opacity: 0;
    pointer-events: none;
    z-index: 9;
    transition: opacity .15s ease;
}
.side-nav {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(320px, 86vw);
    background: #fff;
    border-right: 1px solid var(--line);
    box-shadow: 0 18px 60px rgba(16,36,52,.18);
    transform: translateX(-105%);
    transition: transform .18s ease;
    z-index: 10;
    padding: 18px;
}
.nav-toggle:checked ~ .nav-backdrop {
    opacity: 1;
    pointer-events: auto;
}
.nav-toggle:checked ~ .side-nav {
    transform: translateX(0);
}
.side-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 18px;
}
.side-title img {
    width: 42px;
    height: 42px;
    object-fit: contain;
}
.side-title label {
    width: auto;
    color: var(--primary-dark);
    cursor: pointer;
    font-weight: 700;
}
.touch-nav {
    display: grid;
    gap: 10px;
}
.nav-family {
    display: grid;
    gap: 8px;
}
.nav-subtoggle {
    display: none;
}
.nav-summary {
    min-height: 52px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    border-radius: 8px;
    background: #e8f4fa;
    color: var(--primary-dark);
    font-weight: 700;
    cursor: pointer;
    font-size: 16px;
}
.nav-summary::after {
    content: "+";
    font-size: 20px;
    line-height: 1;
}
.nav-subtoggle:checked + .nav-summary::after {
    content: "-";
}
.nav-subitems {
    display: none;
    gap: 8px;
    padding-left: 16px;
}
.nav-subtoggle:checked + .nav-summary + .nav-subitems {
    display: grid;
}
.nav-subitems a {
    min-height: 44px;
    background: #f4fbff;
}
.touch-nav a {
    min-height: 52px;
    display: inline-flex;
    align-items: center;
    justify-content: flex-start;
    padding: 0 16px;
    border-radius: 8px;
    background: #e8f4fa;
    color: var(--primary-dark);
    font-weight: 700;
}
.touch-nav a:hover { background: #d4eaf5; }
.user {
    margin-left: auto;
    color: var(--muted);
    font-size: 13px;
    white-space: nowrap;
}
.wrap {
    max-width: 1320px;
    width: 100%;
    margin: 0 auto;
    padding: 22px 20px 52px;
    overflow-x: hidden;
}
h1 { margin: 0 0 16px; font-size: 26px; }
h2 { margin: 0 0 12px; font-size: 19px; }
.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 14px;
    max-width: 100%;
    overflow-x: auto;
}
.narrow { max-width: 420px; }
.cards {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}
.cards div {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 18px;
}
.cards b { display: block; font-size: 24px; margin-bottom: 6px; }
.cards span { color: var(--muted); }
.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}
.toolbar form { display: flex; gap: 8px; flex-wrap: wrap; }
.filterbar { max-width: 100%; }
.filterbar input, .filterbar select { width: 190px; }
.sticky-tools {
    position: sticky;
    top: 0;
    z-index: 4;
    background: var(--bg);
    padding: 10px 0;
}
input, select, textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 9px 10px;
    font: inherit;
    font-size: 16px;
    background: #fff;
}
textarea { min-height: 84px; resize: vertical; }
label {
    display: grid;
    gap: 6px;
    color: var(--muted);
    font-size: 13px;
}
button, .button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 48px;
    border: 0;
    border-radius: 6px;
    padding: 0 14px;
    background: var(--primary);
    color: #fff;
    font-weight: 700;
    cursor: pointer;
}
.ico {
    width: 19px;
    height: 19px;
    flex: 0 0 auto;
}
.icon-label {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}
.icon-only {
    width: 40px;
    min-width: 40px;
    min-height: 40px;
    padding: 0;
}
.icon-only span {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}
.button.secondary, button.secondary {
    background: #e8f4fa;
    color: var(--primary-dark);
}
.mini-button {
    min-height: 34px;
    border-radius: 6px;
    padding: 0 10px;
    background: #e8efec;
    color: var(--primary-dark);
    font-size: 12px;
    font-weight: 700;
}
.mini-button.danger {
    background: #fff1eb;
    color: #9d3315;
}
.small { min-height: 32px; margin-top: 10px; }
.row-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}
.label-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 10px;
}
table {
    width: 100%;
    max-width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}
th, td {
    padding: 8px 8px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: top;
}
th { color: var(--muted); font-weight: 700; }
.badge {
    display: inline-block;
    border-radius: 999px;
    background: #e8f4fa;
    color: var(--primary-dark);
    padding: 4px 9px;
    font-size: 12px;
}
.gridform {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
}
.wide { grid-column: 1 / -1; }
.detail {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 260px;
    gap: 14px;
}
dl {
    display: grid;
    grid-template-columns: 160px 1fr;
    gap: 10px 16px;
    margin: 0;
}
dt { color: var(--muted); }
dd { margin: 0; }
.qr {
    text-align: center;
    overflow-wrap: anywhere;
}
.qr img { width: 150px; height: 150px; }
.qr hr {
    border: 0;
    border-top: 1px solid var(--line);
    margin: 16px 0;
}
.asset-photo {
    width: 100%;
    max-height: 210px;
    object-fit: cover;
    border-radius: 8px;
    border: 1px solid var(--line);
    margin-bottom: 12px;
}
.photo-placeholder {
    display: grid;
    place-items: center;
    min-height: 150px;
    border: 1px dashed #9aa8af;
    border-radius: 8px;
    color: var(--muted);
    background: #f8fafb;
    margin-bottom: 12px;
}
.photo-form {
    display: grid;
    gap: 10px;
    margin-bottom: 8px;
}
.inline-upload {
    display: grid;
    grid-template-columns: minmax(260px, 1fr) auto;
    gap: 10px;
    align-items: end;
    margin-bottom: 14px;
}
.inline-edit {
    display: grid;
    grid-template-columns: repeat(2, minmax(140px, 1fr)) auto;
    gap: 8px;
    align-items: center;
}
.user-edit {
    grid-template-columns: repeat(4, minmax(130px, 1fr)) auto;
}
.labels-search button {
    align-self: end;
}
.scanner-panel {
    max-width: 720px;
}
.scanner-panel video {
    width: 100%;
    max-height: 420px;
    background: #001824;
    border: 1px solid var(--line);
    border-radius: 8px;
    object-fit: cover;
}
.muted {
    color: var(--muted);
}
.request-photos {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 14px;
}
.request-photos figure {
    margin: 0;
}
.request-photos img {
    width: 100%;
    height: 180px;
    object-fit: cover;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
}
.request-photos figcaption {
    margin-top: 6px;
    color: var(--muted);
    font-size: 13px;
    overflow-wrap: anywhere;
}
.section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 10px;
}
.section-head h2 {
    margin: 0;
}
.attachments-panel table td:last-child {
    width: 52px;
}
.system-panel table td:first-child {
    width: 220px;
    color: var(--muted);
}
.status-dot {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    border-radius: 999px;
    padding: 0 10px;
    font-size: 12px;
    font-weight: 700;
}
.status-dot.ok {
    background: #e7f4ee;
    color: #15513f;
}
.status-dot.bad {
    background: #fff1eb;
    color: var(--warn);
}
.status-chip,
.status-select {
    min-height: 32px;
    border-radius: 999px;
    padding: 4px 12px;
    font-size: 13px;
    font-weight: 700;
    border: 0;
}
.status-form {
    margin: 0;
}
.status-aberto {
    background: #ffe8e8;
    color: #9d1818;
}
.status-andamento {
    background: #fff4c7;
    color: #7a5600;
}
.status-fechado {
    background: #e0f4df;
    color: #17612a;
}
.inline-edit input,
.inline-edit select {
    min-height: 40px;
}
.inline-edit button {
    min-height: 40px;
}
.flash {
    border-radius: 8px;
    padding: 10px 12px;
    margin-bottom: 16px;
    font-weight: 600;
}
.flash-success {
    background: #e7f4ee;
    border: 1px solid #9ed5bb;
    color: #15513f;
}
.flash-error {
    background: #fff1eb;
    border: 1px solid #e59a7a;
    color: #9b2f12;
}
.error {
    background: #fff1eb;
    border: 1px solid #f0c7b3;
    color: var(--warn);
    border-radius: 8px;
    padding: 10px 12px;
    margin-bottom: 16px;
}
.error::before {
    content: "⚠ ";
    font-weight: 700;
}
.app-footer {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    color: var(--muted);
    font-size: 13px;
    padding: 20px;
    border-top: 1px solid var(--line);
    background: #fff;
    max-width: 100vw;
    overflow: hidden;
}
.app-footer img {
    width: 24px;
    height: 24px;
    object-fit: contain;
}
.labels {
    display: grid;
    align-content: start;
}
.labels-a4 {
    grid-template-columns: repeat(3, 63.5mm);
    gap: 0;
}
.labels-roll {
    grid-template-columns: 63.5mm;
    gap: 0;
}
.label {
    width: 63.5mm;
    height: 29.6mm;
    border: 1px dashed #9aa8af;
    background: #fff;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    break-inside: avoid;
}
.label-simple {
    text-align: center;
}
.label-inner {
    width: 100%;
    height: 100%;
    display: grid;
    grid-template-rows: 21mm 4mm;
    place-items: center;
    align-content: center;
    justify-content: center;
    gap: 1mm;
}
.label-simple strong {
    font-size: 9px;
    line-height: 1;
    letter-spacing: 0;
    font-weight: 700;
}
.label-simple img {
    width: 20mm;
    height: 20mm;
    display: block;
}
.label img { width: 20mm; height: 20mm; }
.label strong { font-size: 9px; }
.label span { font-size: 11px; color: var(--muted); }

@media (max-width: 820px) {
    .cards, .gridform, .detail { grid-template-columns: 1fr; }
    .top { padding: 10px 12px; gap: 10px; }
    .user {
        margin-left: auto;
        max-width: 96px;
        overflow: hidden;
        text-overflow: ellipsis;
        font-size: 11px;
    }
    .brand span { font-size: 16px; }
    .brand { min-width: 0; }
    .brand img { width: 40px; height: 40px; }
    .menu-button { width: 42px; height: 42px; }
    .touch-nav a { min-height: 54px; }
    .toolbar, .toolbar form, .filterbar { width: 100%; }
    .filterbar input, .filterbar select, .filterbar button, .filterbar .button { width: 100%; }
    .inline-upload { grid-template-columns: 1fr; }
    .inline-edit, .user-edit { grid-template-columns: 1fr; }
    table {
        width: max-content;
        min-width: 100%;
    }
    .labels { grid-template-columns: 1fr; }
    .app-footer {
        justify-content: flex-start;
        font-size: 11px;
    }
}

@media print {
    body { background: #fff; }
    .top, h1, .printbtn, .flash, nav, .user, .side-nav, .nav-backdrop, .app-footer { display: none !important; }
    .wrap { max-width: none; width: auto; padding: 0; margin: 0; }
    .panel { border: 0; padding: 0; }
    .labels { gap: 0; margin: 0; padding: 0; }
    .labels-a4 {
        display: grid;
        grid-template-columns: repeat(3, 63.5mm);
        grid-auto-rows: 29.6mm;
        width: 190.5mm;
    }
    .labels-roll { grid-template-columns: 63.5mm; }
    .labels-roll .label { page-break-after: always; }
    .label {
        border: 0;
        page-break-inside: avoid;
        break-inside: avoid;
        overflow: hidden;
    }
    .label-inner { transform: none; }
}
