/*
  OS Sonda SaaS — padrão visual reutilizável
  PHP puro + HTML/CSS/JS, layout app no celular e duas colunas no desktop.
*/
:root {
    --app-height: 100vh;
    --app-top: 0px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);

    --green-950: #082f24;
    --green-900: #064e3b;
    --green-800: #066046;
    --green-700: #0f766e;
    --green-600: #0f8f61;
    --green-500: #12a96f;
    --green-100: #dff8ec;
    --green-50: #f0fdf6;

    --gray-950: #0f172a;
    --gray-800: #1f2937;
    --gray-600: #475569;
    --gray-500: #64748b;
    --gray-300: #cbd5e1;
    --gray-200: #e2e8f0;
    --gray-100: #f1f5f9;
    --gray-50: #f8fafc;
    --white: #ffffff;
    --red: #dc2626;
    --red-soft: #fee2e2;
    --amber: #d97706;
    --amber-soft: #fef3c7;

    --radius-xs: 10px;
    --radius-sm: 14px;
    --radius-md: 18px;
    --radius-lg: 24px;
    --radius-xl: 32px;
    --shadow-sm: 0 6px 18px rgba(15, 23, 42, .08);
    --shadow-md: 0 18px 48px rgba(15, 23, 42, .12);
    --shadow-soft: 0 12px 40px rgba(6, 78, 59, .10);
    --border: 1px solid rgba(148, 163, 184, .26);
    --sidebar-w: 390px;
    --topbar-h: 74px;
    --bottom-h: 72px;
}

* { box-sizing: border-box; }
html { height: 100%; }
body {
    min-height: 100%;
    margin: 0;
    font-family: Inter, "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, Arial, sans-serif;
    color: var(--gray-950);
    background:
        radial-gradient(circle at top left, rgba(18,169,111,.18), transparent 34%),
        linear-gradient(135deg, #f8fbfa 0%, #eef7f2 48%, #f6f8fb 100%);
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
img { max-width: 100%; display: block; }

/* Login */
.login-body {
    min-height: var(--app-height);
    display: grid;
    place-items: center;
    padding: calc(22px + var(--safe-top)) calc(18px + var(--safe-right)) calc(22px + var(--safe-bottom)) calc(18px + var(--safe-left));
}
.login-shell { width: min(100%, 460px); }
.login-card {
    background: rgba(255,255,255,.88);
    border: var(--border);
    box-shadow: var(--shadow-md);
    border-radius: var(--radius-xl);
    padding: 30px;
    backdrop-filter: blur(18px);
}
.login-brand, .brand, .user-mini, .sidebar-top, .topbar, .card-head, .content-head, .table-toolbar, .modal-head, .head-actions, .row-actions {
    display: flex;
    align-items: center;
}
.login-brand { gap: 14px; margin-bottom: 26px; }
.login-brand h1 { margin: 0; font-size: 30px; }
.login-brand p { margin: 3px 0 0; color: var(--gray-500); }
.login-hint { color: var(--gray-500); font-size: 14px; margin: 18px 0 0; }
.brand-mark {
    width: 48px;
    height: 48px;
    border-radius: 16px;
    display: grid;
    place-items: center;
    color: white;
    font-weight: 900;
    letter-spacing: -.06em;
    background: linear-gradient(145deg, var(--green-700), var(--green-500));
    box-shadow: 0 12px 24px rgba(15, 143, 97, .25);
    flex: 0 0 auto;
}

/* Shell */
.app-body {
    height: var(--app-height);
    overflow: hidden;
    padding: calc(14px + var(--safe-top)) calc(14px + var(--safe-right)) calc(14px + var(--safe-bottom)) calc(14px + var(--safe-left));
}
.app-shell {
    width: min(1820px, 100%);
    height: 100%;
    margin: 0 auto;
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
    gap: 14px;
}
.sidebar, .main-panel {
    min-height: 0;
    background: rgba(255,255,255,.82);
    border: var(--border);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-soft);
    backdrop-filter: blur(18px);
    overflow: hidden;
}
.sidebar {
    display: flex;
    flex-direction: column;
    padding: 16px;
}
.sidebar-top {
    gap: 12px;
    justify-content: space-between;
    margin-bottom: 14px;
}
.brand { gap: 12px; min-width: 0; }
.brand strong { display: block; font-size: 18px; }
.brand small { color: var(--gray-500); font-size: 12px; }
.user-mini {
    gap: 12px;
    padding: 12px;
    background: linear-gradient(135deg, var(--green-50), #fff);
    border: var(--border);
    border-radius: var(--radius-md);
    margin-bottom: 12px;
}
.user-mini img {
    width: 44px;
    height: 44px;
    object-fit: cover;
    border-radius: 14px;
    background: var(--gray-100);
}
.user-mini strong { display: block; }
.user-mini small { color: var(--gray-500); }

.side-search, .search-inline {
    display: flex;
    align-items: center;
    gap: 8px;
}
.side-search {
    min-height: 48px;
    padding: 0 14px;
    background: var(--gray-50);
    border: var(--border);
    border-radius: 999px;
    margin-bottom: 12px;
}
.side-search input, .search-inline input {
    width: 100%;
    border: 0;
    outline: none;
    background: transparent;
    color: var(--gray-950);
}
.chips {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 10px;
    scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
    white-space: nowrap;
    padding: 9px 12px;
    border-radius: 999px;
    color: var(--gray-600);
    background: var(--white);
    border: var(--border);
    font-size: 13px;
}
.chip.active, .chip:hover {
    color: var(--green-900);
    background: var(--green-100);
    border-color: rgba(15,143,97,.24);
}
.side-nav {
    display: grid;
    gap: 8px;
    padding: 4px 0 12px;
}
.nav-item {
    min-height: 50px;
    display: grid;
    grid-template-columns: 34px 1fr auto;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-md);
    color: var(--gray-600);
}
.nav-item strong { font-size: 14px; }
.nav-item em {
    min-width: 26px;
    height: 26px;
    display: grid;
    place-items: center;
    border-radius: 999px;
    background: var(--gray-100);
    color: var(--gray-500);
    font-style: normal;
    font-size: 12px;
}
.nav-item.active, .nav-item:hover {
    background: linear-gradient(135deg, var(--green-600), var(--green-700));
    color: white;
    box-shadow: 0 14px 24px rgba(15, 143, 97, .22);
}
.nav-item.active em, .nav-item:hover em { background: rgba(255,255,255,.2); color: white; }
.quick-list {
    min-height: 0;
    overflow-y: auto;
    padding-right: 3px;
    display: grid;
    gap: 8px;
}
.section-title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 2px 4px;
    color: var(--gray-500);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .05em;
}
.quick-item {
    display: grid;
    grid-template-columns: 42px 1fr;
    gap: 10px;
    align-items: center;
    padding: 11px;
    border-radius: var(--radius-md);
    background: rgba(248,250,252,.74);
    border: var(--border);
}
.quick-item:hover { background: white; box-shadow: var(--shadow-sm); }
.quick-icon {
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    border-radius: 14px;
    background: var(--green-50);
}
.quick-item strong, .quick-item small {
    display: block;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.quick-item small { color: var(--gray-500); font-size: 12px; margin-top: 2px; }
.sidebar-foot { margin-top: auto; padding-top: 12px; }

.main-panel {
    min-width: 0;
    display: flex;
    flex-direction: column;
}
.topbar {
    height: var(--topbar-h);
    min-height: var(--topbar-h);
    padding: 0 20px;
    justify-content: space-between;
    border-bottom: var(--border);
    background: rgba(255,255,255,.64);
}
.topbar strong { display: block; }
.topbar small { color: var(--gray-500); }
.top-actions { display: flex; gap: 8px; }
.main-scroll {
    width: 100%;
    min-width: 0;
    min-height: 0;
    overflow: auto;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
    padding: 20px;
}

/* Componentes */
.btn, .icon-btn {
    border: 0;
    border-radius: 999px;
    min-height: 42px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-weight: 700;
    transition: .18s ease;
}
.btn { padding: 0 18px; }
.btn.full { width: 100%; }
.btn-primary {
    color: #fff;
    background: linear-gradient(135deg, var(--green-600), var(--green-700));
    box-shadow: 0 14px 28px rgba(15, 143, 97, .24);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 18px 34px rgba(15, 143, 97, .28); }
.btn-soft { color: var(--green-900); background: var(--green-50); border: 1px solid rgba(15, 143, 97, .16); }
.btn-soft:hover { background: var(--green-100); }
.btn:disabled,
.btn[aria-disabled="true"] {
    opacity: .52;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}
.icon-btn {
    width: 42px;
    min-width: 42px;
    height: 42px;
    background: var(--gray-50);
    color: var(--gray-700);
    border: var(--border);
}
.icon-btn:hover { background: white; box-shadow: var(--shadow-sm); }
.icon-btn.danger { color: var(--red); background: var(--red-soft); }
.link { color: var(--green-700); font-weight: 800; }
.muted { color: var(--gray-500); }
.eyebrow {
    margin: 0 0 5px;
    color: var(--green-700);
    font-size: 12px;
    font-weight: 900;
    letter-spacing: .08em;
    text-transform: uppercase;
}
.alert {
    margin: 16px 20px 0;
    padding: 13px 15px;
    border-radius: var(--radius-md);
    font-weight: 700;
    border: var(--border);
}
.login-card .alert { margin: 0 0 14px; }
.alert.success { color: var(--green-900); background: var(--green-100); }
.alert.error { color: #991b1b; background: var(--red-soft); }
.alert.warning { color: #92400e; background: var(--amber-soft); }

.hero-panel, .card, .table-card {
    background: rgba(255,255,255,.86);
    border: var(--border);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-sm);
}
.hero-panel {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 18px;
    padding: 28px;
    margin-bottom: 18px;
    background:
        linear-gradient(135deg, rgba(15,143,97,.12), rgba(255,255,255,.88)),
        radial-gradient(circle at bottom right, rgba(18,169,111,.18), transparent 34%);
}
.hero-panel h1 { margin: 0; font-size: clamp(28px, 4vw, 48px); line-height: 1.02; max-width: 800px; }
.hero-panel p:not(.eyebrow) { color: var(--gray-600); max-width: 720px; }
.dash-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}
.stat-card {
    min-height: 150px;
    padding: 20px;
    border-radius: var(--radius-lg);
    background: var(--white);
    border: var(--border);
    box-shadow: var(--shadow-sm);
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.stat-icon {
    width: 46px;
    height: 46px;
    display: grid;
    place-items: center;
    border-radius: 16px;
    background: var(--green-50);
    margin-bottom: 14px;
}
.stat-card strong { font-size: 34px; line-height: 1; display: block; }
.stat-card p { margin: 8px 0 0; color: var(--gray-500); }
.two-col-content {
    display: grid;
    grid-template-columns: 1.25fr .95fr;
    gap: 14px;
}
.card { padding: 18px; min-width: 0; }
.card-head { justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.card h2 { margin: 0; }
.timeline-list, .device-list { display: grid; gap: 10px; }
.timeline-item {
    display: grid;
    grid-template-columns: 18px 1fr;
    gap: 10px;
    padding: 12px;
    border-radius: var(--radius-md);
    background: var(--gray-50);
}
.timeline-item p { margin: 4px 0; color: var(--gray-600); }
.timeline-item small { color: var(--gray-500); }
.dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--green-600);
    margin-top: 5px;
    box-shadow: 0 0 0 5px var(--green-100);
}
.device-item {
    display: grid;
    grid-template-columns: 48px 1fr auto;
    align-items: center;
    gap: 10px;
    padding: 10px;
    border-radius: var(--radius-md);
    background: var(--gray-50);
}
.device-item img { width: 48px; height: 48px; border-radius: 14px; object-fit: cover; background: white; }
.device-item strong, .device-item small { display: block; }
.device-item small { color: var(--gray-500); }

/* CRUD */
.content-head {
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 16px;
}
.content-head h1 { margin: 0; font-size: clamp(25px, 4vw, 36px); }
.head-actions { gap: 8px; flex-wrap: wrap; }
.table-card {
    min-width: 0;
    max-width: 100%;
    padding: 0;
    overflow: hidden;
}
.table-toolbar {
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 16px;
    border-bottom: var(--border);
    flex-wrap: wrap;
}
.search-inline {
    width: min(100%, 540px);
    min-height: 44px;
    background: var(--gray-50);
    border: var(--border);
    border-radius: 999px;
    padding-left: 14px;
}
.search-hint {
    color: var(--gray-500);
    font-size: 12px;
    line-height: 1.35;
}
.search-hint strong { color: var(--green-800); }
.table-wrap {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    overflow: auto;
    overscroll-behavior: contain;
    scrollbar-gutter: stable both-edges;
    -webkit-overflow-scrolling: touch;
}
.admin-table {
    width: max-content;
    min-width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}
.admin-table th,
.admin-table td {
    min-width: 122px;
    max-width: 320px;
}
.admin-table th:first-child,
.admin-table td:first-child {
    min-width: 112px;
}
.admin-table thead th {
    position: sticky;
    top: 0;
    z-index: 3;
    box-shadow: inset 0 -1px 0 rgba(203, 213, 225, .9);
}
.admin-table th, .admin-table td {
    padding: 14px 16px;
    text-align: left;
    border-bottom: 1px solid rgba(226,232,240,.72);
    vertical-align: middle;
}
.admin-table th {
    font-size: 12px;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: .05em;
    background: var(--gray-50);
}
.admin-table tr:hover td { background: rgba(240,253,246,.5); }
.actions-col {
    width: 116px;
    min-width: 116px !important;
}
.module-servicos .actions-col {
    width: 166px;
    min-width: 166px !important;
}
.row-actions {
    min-width: 116px !important;
    gap: 8px;
}
.module-servicos .row-actions { min-width: 166px !important; }
.admin-table th.actions-col {
    position: sticky;
    right: 0;
    z-index: 5;
    background: var(--gray-50);
    border-left: 1px solid rgba(226,232,240,.9);
}
.admin-table td.row-actions {
    position: sticky;
    right: 0;
    z-index: 2;
    background: rgba(255,255,255,.98);
    border-left: 1px solid rgba(226,232,240,.9);
    box-shadow: -8px 0 14px rgba(15,23,42,.035);
}
.admin-table tr:hover td.row-actions { background: #f7fefb; }
.inline-form { display: inline-flex; margin: 0; }
.empty-cell { text-align: center; color: var(--gray-500); padding: 30px !important; }
.badge {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    padding: 0 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 900;
    background: var(--gray-100);
    color: var(--gray-600);
}
.badge.success { background: var(--green-100); color: var(--green-900); }
.badge.warning { background: var(--amber-soft); color: #92400e; }
.badge.danger { background: var(--red-soft); color: #991b1b; }
.empty-state {
    display: grid;
    place-items: center;
    text-align: center;
    min-height: 280px;
    color: var(--gray-500);
}
.empty-state h2 { color: var(--gray-950); margin-bottom: 4px; }
.empty-state.small { min-height: 120px; }

/* Formulários e modais */
.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}
.stack-form { display: grid; gap: 14px; }
.form-field {
    display: grid;
    gap: 7px;
    min-width: 0;
}
.form-field-wide { grid-column: 1 / -1; }
.form-field span {
    font-weight: 800;
    font-size: 13px;
    color: var(--gray-700);
}
.form-field small { color: var(--gray-500); }
.form-field input, .form-field select, .form-field textarea,
.search-inline input {
    min-height: 46px;
    width: 100%;
    border: var(--border);
    border-radius: 15px;
    padding: 0 14px;
    background: var(--gray-50);
    color: var(--gray-950);
    outline: none;
}
.form-field textarea { padding-top: 12px; resize: vertical; }
.form-field input:focus, .form-field select:focus, .form-field textarea:focus {
    border-color: rgba(15,143,97,.46);
    box-shadow: 0 0 0 4px rgba(15,143,97,.10);
    background: white;
}
.form-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding-top: 8px;
}

/* Rodapé do cadastro sempre visível, inclusive após usar a câmera */
.modal-crud-form {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.modal-crud-form > .app-form {
    flex: 1 1 auto;
    min-height: 0;
    align-content: start;
}
.modal-form-footer {
    flex: 0 0 auto;
    position: relative;
    z-index: 8;
    margin: 0;
    padding: 14px 20px calc(14px + var(--safe-bottom));
    background: rgba(255, 255, 255, .98);
    border-top: var(--border);
    box-shadow: 0 -12px 28px rgba(15, 23, 42, .08);
    backdrop-filter: blur(12px);
}
.save-record-btn {
    min-width: 150px;
    font-size: 14px;
}
.save-record-btn.is-saving {
    opacity: .78;
    pointer-events: none;
}
.modal {
    position: fixed;
    inset: 0;
    z-index: 90;
    display: none;
    place-items: center;
    padding: 18px;
    background: rgba(15,23,42,.42);
    backdrop-filter: blur(8px);
}
.modal.is-open { display: grid; }
.modal-dialog {
    width: min(100%, 880px);
    max-height: min(92vh, 860px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: white;
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-md);
}
.modal-dialog.small { width: min(100%, 520px); }
.modal-head {
    min-height: 72px;
    justify-content: space-between;
    gap: 12px;
    padding: 18px 20px;
    border-bottom: var(--border);
}
.modal-head h2 { margin: 0; }
.app-form, .modal-dialog .stack-form {
    min-width: 0;
    overflow: auto;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
    padding: 20px;
}

/* Rolagem visível e controlada no computador */
.main-scroll,
.table-wrap,
.quick-list,
.app-form,
.modal-dialog .stack-form {
    scrollbar-width: thin;
    scrollbar-color: rgba(15, 143, 97, .68) rgba(226, 232, 240, .72);
}
.main-scroll::-webkit-scrollbar,
.table-wrap::-webkit-scrollbar,
.quick-list::-webkit-scrollbar,
.app-form::-webkit-scrollbar,
.modal-dialog .stack-form::-webkit-scrollbar {
    width: 12px;
    height: 12px;
}
.main-scroll::-webkit-scrollbar-track,
.table-wrap::-webkit-scrollbar-track,
.quick-list::-webkit-scrollbar-track,
.app-form::-webkit-scrollbar-track,
.modal-dialog .stack-form::-webkit-scrollbar-track {
    background: rgba(226, 232, 240, .72);
    border-radius: 999px;
}
.main-scroll::-webkit-scrollbar-thumb,
.table-wrap::-webkit-scrollbar-thumb,
.quick-list::-webkit-scrollbar-thumb,
.app-form::-webkit-scrollbar-thumb,
.modal-dialog .stack-form::-webkit-scrollbar-thumb {
    min-height: 38px;
    background: linear-gradient(180deg, var(--green-500), var(--green-700));
    border: 3px solid rgba(226, 232, 240, .82);
    border-radius: 999px;
}
.main-scroll::-webkit-scrollbar-thumb:hover,
.table-wrap::-webkit-scrollbar-thumb:hover,
.quick-list::-webkit-scrollbar-thumb:hover,
.app-form::-webkit-scrollbar-thumb:hover,
.modal-dialog .stack-form::-webkit-scrollbar-thumb:hover {
    background: var(--green-800);
}
.table-wrap::-webkit-scrollbar-corner,
.main-scroll::-webkit-scrollbar-corner {
    background: var(--gray-100);
}

@media (min-width: 861px) {
    .table-card {
        display: flex;
        flex-direction: column;
        max-height: calc(var(--app-height) - var(--topbar-h) - 150px);
    }
    .table-toolbar {
        flex: 0 0 auto;
    }
    .table-wrap {
        flex: 1 1 auto;
        min-height: 240px;
        max-height: calc(var(--app-height) - var(--topbar-h) - 250px);
    }
    .admin-table th,
    .admin-table td {
        white-space: normal;
        overflow-wrap: anywhere;
    }
}

/* Mobile */
.back-mobile { display: none; }
.mobile-bottom-bar, .fab { display: none; }
.menu-popover {
    position: fixed;
    right: 22px;
    top: 82px;
    z-index: 100;
    display: none;
    min-width: 210px;
    padding: 8px;
    border-radius: var(--radius-md);
    background: white;
    box-shadow: var(--shadow-md);
    border: var(--border);
}
.menu-popover.is-open { display: grid; }
.menu-popover a {
    padding: 12px;
    border-radius: 12px;
    color: var(--gray-700);
    font-weight: 700;
}
.menu-popover a:hover { background: var(--green-50); color: var(--green-900); }

@media (max-width: 1180px) {
    :root { --sidebar-w: 330px; }
    .dash-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .two-col-content { grid-template-columns: 1fr; }
    .hero-panel { align-items: flex-start; flex-direction: column; }
}

@media (max-width: 860px) {
    .admin-table {
        width: 100%;
        min-width: 860px;
        border-collapse: collapse;
    }
    .admin-table th,
    .admin-table td {
        min-width: 0;
        max-width: none;
    }
    .admin-table th.actions-col,
    .admin-table td.row-actions {
        position: static;
        box-shadow: none;
    }
    .app-body {
        padding: 0;
        height: var(--app-height);
        overflow: hidden;
        background: var(--white);
    }
    .app-shell {
        width: 100%;
        height: var(--app-height);
        display: block;
    }
    .sidebar, .main-panel {
        position: fixed;
        inset: 0;
        height: var(--app-height);
        width: 100%;
        border: 0;
        border-radius: 0;
        box-shadow: none;
        background: linear-gradient(180deg, #fbfffd, #f4faf7);
    }
    .sidebar {
        z-index: 10;
        padding: calc(12px + var(--safe-top)) calc(12px + var(--safe-right)) calc(var(--bottom-h) + 12px + var(--safe-bottom)) calc(12px + var(--safe-left));
    }
    .main-panel {
        z-index: 20;
        display: none;
        padding-bottom: calc(var(--bottom-h) + var(--safe-bottom));
    }
    body.chat-open .main-panel { display: flex; }
    body.chat-open .sidebar { display: none; }
    .sidebar-top { margin-bottom: 10px; }
    .brand-mark { width: 44px; height: 44px; border-radius: 14px; }
    .user-mini { margin-bottom: 10px; }
    .side-nav {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
    }
    .nav-item {
        min-height: 58px;
        grid-template-columns: 30px 1fr;
        grid-template-areas: "i t" "i n";
    }
    .nav-item span { grid-area: i; }
    .nav-item strong { grid-area: t; }
    .nav-item em { grid-area: n; width: max-content; min-width: 24px; }
    .quick-list { padding-bottom: 10px; }
    .topbar {
        height: 62px;
        min-height: 62px;
        padding: calc(8px + var(--safe-top)) calc(12px + var(--safe-right)) 8px calc(12px + var(--safe-left));
    }
    .back-mobile {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        min-height: 42px;
        border: 0;
        border-radius: 999px;
        padding: 0 12px;
        background: var(--green-50);
        color: var(--green-900);
        font-weight: 900;
    }
    .main-scroll {
        padding: 14px;
        padding-bottom: 22px;
    }
    .content-head { align-items: flex-start; }
    .content-head .back-mobile { margin-bottom: 8px; }
    .head-actions { justify-content: flex-end; }
    .dash-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
    .stat-card { min-height: 120px; padding: 15px; }
    .stat-card strong { font-size: 27px; }
    .hero-panel { padding: 20px; border-radius: var(--radius-lg); }
    .hero-panel h1 { font-size: 30px; }
    .card { border-radius: var(--radius-lg); padding: 14px; }
    .table-toolbar { padding: 12px; }
    .search-inline { width: 100%; }
    .search-hint { width: 100%; }
    .content-head { flex-direction: column; }
    .content-head, .head-actions { width: 100%; }
    .head-actions .btn { flex: 1; }
    .mobile-bottom-bar {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 60;
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(54px, 1fr));
        gap: 4px;
        height: calc(var(--bottom-h) + var(--safe-bottom));
        padding: 7px calc(8px + var(--safe-right)) calc(7px + var(--safe-bottom)) calc(8px + var(--safe-left));
        background: rgba(255,255,255,.94);
        border-top: var(--border);
        backdrop-filter: blur(18px);
    }
    .mobile-bottom-bar a {
        display: grid;
        place-items: center;
        gap: 2px;
        color: var(--gray-500);
        font-size: 19px;
        border-radius: 16px;
    }
    .mobile-bottom-bar a span { font-size: 10px; font-weight: 800; }
    .mobile-bottom-bar a.active { color: var(--green-800); background: var(--green-50); }
    .fab {
        position: fixed;
        right: calc(16px + var(--safe-right));
        bottom: calc(var(--bottom-h) + 18px + var(--safe-bottom));
        z-index: 70;
        width: 58px;
        height: 58px;
        border: 0;
        border-radius: 50%;
        display: grid;
        place-items: center;
        color: white;
        font-size: 30px;
        font-weight: 900;
        background: linear-gradient(135deg, var(--green-600), var(--green-700));
        box-shadow: 0 18px 40px rgba(15,143,97,.34);
    }
    .modal {
        align-items: stretch;
        padding: 0;
    }
    .modal-dialog, .modal-dialog.small {
        width: 100%;
        height: var(--app-height);
        max-height: none;
        border-radius: 0;
        padding-top: var(--safe-top);
        padding-bottom: var(--safe-bottom);
    }
    .modal-head { min-height: 64px; padding: 12px 14px; }
    .form-grid { grid-template-columns: 1fr; gap: 12px; }
    .modal-form-footer {
        position: relative;
        bottom: auto;
        padding: 12px 14px calc(12px + var(--safe-bottom));
    }
    .modal-form-footer .btn { flex: 1; }
    .save-record-btn { min-width: 0; }
}

@media (max-width: 430px) {
    :root { --bottom-h: 66px; }
    .sidebar { padding-left: calc(10px + var(--safe-left)); padding-right: calc(10px + var(--safe-right)); }
    .login-card { padding: 22px; border-radius: 24px; }
    .login-brand h1 { font-size: 24px; }
    .side-nav { grid-template-columns: 1fr 1fr; }
    .nav-item { min-height: 54px; padding: 9px; }
    .nav-item strong { font-size: 12px; }
    .quick-item { padding: 9px; grid-template-columns: 38px 1fr; }
    .quick-icon { width: 38px; height: 38px; }
    .topbar { height: 58px; min-height: 58px; }
    .topbar small { display: none; }
    .topbar .icon-btn { width: 38px; min-width: 38px; height: 38px; }
    .main-scroll { padding: 12px; }
    .hero-panel h1 { font-size: 26px; }
    .dash-grid { grid-template-columns: 1fr; }
    .stat-card { min-height: auto; }
    .table-card { border-radius: 18px; }
    .btn { min-height: 42px; padding: 0 14px; }
    .content-head h1 { font-size: 25px; }
    .device-item { grid-template-columns: 42px 1fr; }
    .device-item .badge { grid-column: 2; width: fit-content; }
}

@media (max-height: 620px) and (max-width: 860px) {
    :root { --bottom-h: 58px; }
    .sidebar-top, .user-mini, .chips { margin-bottom: 6px; }
    .side-search { min-height: 42px; margin-bottom: 6px; }
    .nav-item { min-height: 48px; padding: 7px 9px; }
    .quick-item { padding: 8px; }
    .topbar { height: 52px; min-height: 52px; }
    .mobile-bottom-bar { padding-top: 4px; }
    .mobile-bottom-bar a span { display: none; }
}

/* Busca local rápida da tabela */
[hidden] { display: none !important; }
.btn-ghost {
    color: var(--gray-600);
    background: transparent;
    border: 1px solid rgba(148, 163, 184, .28);
}
.btn-ghost:hover { background: var(--gray-50); color: var(--gray-950); }
.is-filtered-out { display: none !important; }

.link-badge {
    text-decoration: none;
    background: var(--green-50, #f0fdf4);
    color: var(--green-800, #166534);
    border: 1px solid rgba(20, 184, 116, .22);
    white-space: nowrap;
}
.link-badge:hover { filter: brightness(.97); }
.mt-8 { margin-top: 8px; }
.file-hint { color: var(--gray-500); }

/* Fotos múltiplas das ordens de serviço */
.multi-photo-field {
    align-items: stretch;
}
.multi-photo-drop {
    position: relative;
    min-height: 116px;
    display: grid;
    place-items: center;
    align-content: center;
    gap: 6px;
    padding: 20px;
    text-align: center;
    color: var(--green-800);
    background: linear-gradient(135deg, var(--green-50), rgba(223, 248, 236, .58));
    border: 2px dashed rgba(15, 143, 97, .36);
    border-radius: var(--radius-md);
    overflow: hidden;
    cursor: pointer;
}
.multi-photo-drop:hover {
    border-color: var(--green-600);
    background: var(--green-50);
}
.multi-photo-drop input[type="file"] {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
}
.multi-photo-drop strong {
    font-size: 16px;
}
.multi-photo-drop small {
    color: var(--gray-500);
}
.photo-preview-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(165px, 1fr));
    gap: 12px;
    margin-top: 12px;
}
.photo-preview-card {
    position: relative;
    min-width: 0;
    display: grid;
    grid-template-rows: 138px auto;
    overflow: hidden;
    background: var(--white);
    border: var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-sm);
    transition: .2s ease;
}
.photo-preview-card img {
    width: 100%;
    height: 138px;
    display: block;
    object-fit: cover;
    background: var(--gray-100);
}
.photo-preview-info {
    min-width: 0;
    display: grid;
    gap: 2px;
    padding: 9px 10px;
}
.photo-preview-info strong,
.photo-preview-info small {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.photo-preview-info strong {
    color: var(--gray-800);
    font-size: 12px;
}
.photo-preview-info small {
    color: var(--gray-500);
    font-size: 10px;
}
.existing-photo-area {
    margin-top: 16px;
    padding-top: 14px;
    border-top: 1px solid var(--gray-200);
}
.existing-photo-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.existing-photo-head small {
    color: var(--gray-500);
}
.existing-photo-card {
    cursor: pointer;
}
.photo-remove-option {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 9px 10px;
    color: var(--red);
    font-size: 11px;
    font-weight: 800;
    background: var(--red-soft);
    border-top: 1px solid rgba(220, 38, 38, .12);
}
.photo-remove-option input {
    width: 17px;
    height: 17px;
    accent-color: var(--red);
}
.existing-photo-card.marked-for-removal {
    opacity: .52;
    border-color: rgba(220, 38, 38, .5);
    transform: scale(.98);
}
.existing-photo-card.marked-for-removal img {
    filter: grayscale(1);
}
.photo-count-badge {
    min-width: 52px;
    justify-content: center;
}

/* Página da galeria de fotos */
.gallery-page {
    min-height: 100vh;
    padding: 24px;
    background:
        radial-gradient(circle at top left, rgba(18, 169, 111, .18), transparent 34%),
        linear-gradient(135deg, #f8fbfa 0%, #eef7f2 48%, #f6f8fb 100%);
}
.gallery-shell {
    width: min(1400px, 100%);
    margin: 0 auto;
    padding: 22px;
    background: rgba(255, 255, 255, .92);
    border: var(--border);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-md);
    backdrop-filter: blur(18px);
}
.gallery-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 20px;
}
.gallery-head h1 {
    margin: 4px 0;
    color: var(--gray-950);
}
.gallery-head p {
    margin: 0;
    color: var(--gray-500);
}
.gallery-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}
.os-photo-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 16px;
}
.os-photo-item {
    min-width: 0;
    overflow: hidden;
    background: var(--white);
    border: var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
}
.os-photo-item a {
    display: block;
    color: inherit;
    text-decoration: none;
}
.os-photo-item img {
    width: 100%;
    aspect-ratio: 4 / 3;
    display: block;
    object-fit: cover;
    background: var(--gray-100);
}
.os-photo-caption {
    display: grid;
    gap: 4px;
    padding: 12px;
}
.os-photo-caption strong {
    color: var(--gray-800);
}
.os-photo-caption small {
    color: var(--gray-500);
    overflow-wrap: anywhere;
}

@media (max-width: 700px) {
    .photo-preview-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 9px;
    }
    .photo-preview-card {
        grid-template-rows: 112px auto;
    }
    .photo-preview-card img {
        height: 112px;
    }
    .existing-photo-head,
    .gallery-head {
        align-items: stretch;
        flex-direction: column;
    }
    .gallery-page {
        padding: 0;
    }
    .gallery-shell {
        min-height: 100vh;
        padding: 16px;
        border: 0;
        border-radius: 0;
    }
    .gallery-actions .btn {
        flex: 1;
    }
    .os-photo-gallery {
        grid-template-columns: 1fr;
    }
}

/* Controle de níveis e permissões */
.permissions-page-head {
    align-items: flex-start;
}
.access-info-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 16px;
}
.access-info-card {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    padding: 20px;
}
.access-info-card h2,
.permission-level-head h2 {
    margin: 3px 0 7px;
}
.access-info-card p,
.permission-level-head p {
    margin: 0;
    color: var(--gray-500);
}
.admin-access-card {
    background: linear-gradient(135deg, rgba(6, 78, 59, .98), rgba(15, 143, 97, .92));
    color: var(--white);
}
.admin-access-card .eyebrow,
.admin-access-card p {
    color: rgba(255, 255, 255, .82);
}
.access-level-icon {
    width: 48px;
    height: 48px;
    flex: 0 0 48px;
    display: grid;
    place-items: center;
    border-radius: 16px;
    background: rgba(255, 255, 255, .18);
    font-size: 23px;
}
.permission-levels {
    display: grid;
    gap: 18px;
}
.permission-level-card {
    padding: 0;
    overflow: hidden;
}
.permission-level-head,
.permission-level-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    padding: 18px 20px;
}
.permission-level-head {
    border-bottom: 1px solid var(--gray-200);
}
.permission-level-footer {
    border-top: 1px solid var(--gray-200);
    background: var(--gray-50);
}
.permission-level-footer small {
    color: var(--gray-500);
}
.permission-table-wrap {
    width: 100%;
    max-height: min(58vh, 620px);
    overflow: auto;
    scrollbar-gutter: stable both-edges;
}
.permission-table {
    width: 100%;
    min-width: 920px;
    border-collapse: separate;
    border-spacing: 0;
}
.permission-table th,
.permission-table td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--gray-200);
    text-align: center;
    background: var(--white);
}
.permission-table th {
    position: sticky;
    top: 0;
    z-index: 4;
    color: var(--gray-600);
    background: var(--gray-50);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .04em;
}
.permission-table th:first-child,
.permission-table td:first-child {
    position: sticky;
    left: 0;
    z-index: 3;
    min-width: 220px;
    text-align: left;
    box-shadow: 8px 0 16px rgba(15, 23, 42, .04);
}
.permission-table th:first-child {
    z-index: 5;
    background: var(--gray-50);
}
.permission-table tr:hover td {
    background: #fbfefd;
}
.permission-table tr:hover td:first-child {
    background: #fbfefd;
}
.permission-table thead label {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    cursor: pointer;
}
.permission-table input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--green-600);
    cursor: pointer;
}
.permission-module-name {
    display: inline-flex;
    align-items: center;
    gap: 9px;
}
.permission-module-name > span {
    font-size: 19px;
}
.permission-check {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}
.permission-check span {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}
.permission-locked-row td {
    background: #fffaf0;
}
.permission-locked-row td:first-child {
    background: #fffaf0;
}

@media (max-width: 860px) {
    .access-info-grid {
        grid-template-columns: 1fr;
    }
    .permission-level-head,
    .permission-level-footer {
        align-items: stretch;
        flex-direction: column;
    }
    .permission-level-head .btn,
    .permission-level-footer .btn {
        width: 100%;
    }
    .permission-table-wrap {
        max-height: none;
    }
}

/* Captura direta pela câmera no cadastro de OS */
.photo-source-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}
.photo-source-card {
    position: relative;
    min-height: 118px;
    display: grid;
    place-items: center;
    align-content: center;
    gap: 5px;
    padding: 18px;
    overflow: hidden;
    text-align: center;
    color: var(--green-800);
    background: linear-gradient(135deg, var(--green-50), rgba(223, 248, 236, .58));
    border: 2px dashed rgba(15, 143, 97, .36);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: transform .18s ease, border-color .18s ease, background .18s ease, box-shadow .18s ease;
}
.photo-source-card:hover,
.photo-source-card:focus-within {
    border-color: var(--green-600);
    background: var(--green-50);
    box-shadow: var(--shadow-sm);
    transform: translateY(-1px);
}
.photo-source-card input[type="file"] {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
}
.photo-source-icon {
    font-size: 27px;
    line-height: 1;
}
.photo-source-card strong {
    font-size: 15px;
}
.photo-source-card small {
    max-width: 270px;
    color: var(--gray-500);
    line-height: 1.35;
}
.camera-source {
    color: var(--white);
    background: linear-gradient(135deg, var(--green-800), var(--green-500));
    border-style: solid;
    border-color: transparent;
    box-shadow: 0 12px 28px rgba(15, 143, 97, .22);
}
.camera-source:hover,
.camera-source:focus-within {
    color: var(--white);
    background: linear-gradient(135deg, var(--green-900), var(--green-600));
    border-color: transparent;
}
.camera-source small {
    color: rgba(255, 255, 255, .82);
}
.photo-selection-status {
    margin-top: 10px;
    padding: 9px 11px;
    color: var(--gray-600);
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-xs);
    font-size: 12px;
    font-weight: 700;
}
.photo-selection-status.is-limit {
    color: var(--amber);
    background: var(--amber-soft);
    border-color: rgba(217, 119, 6, .24);
}
.photo-selection-status.is-over-limit {
    color: var(--red);
    background: var(--red-soft);
    border-color: rgba(220, 38, 38, .24);
}
.photo-new-remove {
    position: absolute;
    top: 7px;
    right: 7px;
    z-index: 2;
    width: 31px;
    height: 31px;
    display: grid;
    place-items: center;
    padding: 0;
    color: var(--white);
    background: rgba(15, 23, 42, .78);
    border: 0;
    border-radius: 999px;
    box-shadow: 0 5px 14px rgba(15, 23, 42, .24);
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
}
.photo-new-remove:hover {
    background: var(--red);
}

@media (max-width: 620px) {
    .photo-source-actions {
        grid-template-columns: 1fr;
    }
    .photo-source-card {
        min-height: 104px;
        padding: 15px;
    }
}


/* Correção definitiva do botão Salvar nos celulares */
.modal-head-title {
    min-width: 0;
}
.modal-head-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    flex: 0 0 auto;
}
.mobile-modal-save {
    display: none;
}

@media (max-width: 860px) {
    body.modal-open {
        overflow: hidden !important;
        overscroll-behavior: none;
    }
    body.modal-open .mobile-bottom-bar,
    body.modal-open .fab {
        display: none !important;
    }
    .modal.is-open {
        top: var(--app-top);
        right: 0;
        bottom: auto;
        left: 0;
        width: 100%;
        height: var(--app-height);
        min-height: var(--app-height);
        display: block;
        overflow: hidden;
        padding: 0;
    }
    .modal-dialog,
    .modal-dialog.small {
        width: 100%;
        height: 100%;
        min-height: 0;
        max-height: 100%;
        display: grid;
        grid-template-rows: auto minmax(0, 1fr);
        padding-top: var(--safe-top);
        padding-bottom: 0;
        overflow: hidden;
        border-radius: 0;
    }
    .modal-head {
        position: relative;
        z-index: 120;
        min-height: 64px;
        padding: 10px calc(12px + var(--safe-right)) 10px calc(12px + var(--safe-left));
        background: rgba(255, 255, 255, .99);
        box-shadow: 0 5px 18px rgba(15, 23, 42, .07);
    }
    .modal-head-title {
        flex: 1 1 auto;
        overflow: hidden;
    }
    .modal-head-title h2 {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        font-size: 20px;
    }
    .mobile-modal-save {
        min-height: 40px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        padding: 0 13px;
        border-radius: 13px;
        font-size: 13px;
        white-space: nowrap;
    }
    .mobile-modal-save.is-saving {
        opacity: .75;
        pointer-events: none;
    }
    .modal-crud-form {
        width: 100%;
        height: 100%;
        min-height: 0;
        display: grid;
        grid-template-rows: minmax(0, 1fr) auto;
        overflow: hidden;
    }
    .modal-crud-form > .app-form {
        width: 100%;
        height: auto;
        min-height: 0;
        overflow-x: hidden;
        overflow-y: auto;
        overscroll-behavior: contain;
        -webkit-overflow-scrolling: touch;
        padding: 16px 14px 28px;
        scroll-padding-bottom: 110px;
    }
    .modal-form-footer {
        position: relative;
        bottom: auto;
        z-index: 130;
        min-height: calc(72px + var(--safe-bottom));
        display: flex !important;
        flex: 0 0 auto;
        align-items: center;
        justify-content: stretch;
        gap: 10px;
        visibility: visible !important;
        opacity: 1 !important;
        padding: 10px calc(14px + var(--safe-right)) calc(10px + var(--safe-bottom)) calc(14px + var(--safe-left));
        background: #ffffff;
        border-top: 1px solid var(--gray-200);
        box-shadow: 0 -10px 28px rgba(15, 23, 42, .12);
    }
    .modal-form-footer .btn {
        min-width: 0;
        min-height: 48px;
        display: inline-flex !important;
        flex: 1 1 0;
        align-items: center;
        justify-content: center;
        visibility: visible !important;
    }
    .modal-form-footer .save-record-btn {
        color: #ffffff;
        background: linear-gradient(135deg, var(--green-600), var(--green-700));
    }
}

@media (max-width: 380px) {
    .modal-head .eyebrow {
        display: none;
    }
    .modal-head-title h2 {
        font-size: 18px;
    }
    .mobile-modal-save {
        padding: 0 10px;
        font-size: 12px;
    }
    .modal-form-footer {
        min-height: calc(68px + var(--safe-bottom));
        padding-left: calc(10px + var(--safe-left));
        padding-right: calc(10px + var(--safe-right));
    }
}
