* { box-sizing: border-box; font-family: "Segoe UI", Arial, sans-serif; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    background: linear-gradient(145deg, #fffaf5 0%, #ffffff 45%, #fff3e8 100%);
    color: #2d2d2d;
    line-height: 1.5;
}
img, canvas, svg { max-width: 100%; height: auto; }
.app { display: flex; min-height: 100vh; }
.sidebar {
    width: 250px;
    flex-shrink: 0;
    background: linear-gradient(180deg, #f57c00 0%, #ff9800 55%, #fb8c00 100%);
    color: #fff;
    padding: 20px;
    box-shadow: 4px 0 18px rgba(245, 124, 0, 0.24);
}
.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 1px solid rgba(255, 255, 255, .35);
}
.sidebar-close {
    display: none;
    background: rgba(255,255,255,.2);
    border: none;
    color: #fff;
    font-size: 1.5rem;
    line-height: 1;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    cursor: pointer;
    padding: 0;
}
.brand {
    font-weight: 700;
    letter-spacing: .3px;
    margin: 0;
}
.sidebar nav { display: flex; flex-direction: column; gap: 10px; }
.sidebar a {
    color: #fff;
    text-decoration: none;
    padding: 10px 12px;
    border-radius: 10px;
    font-weight: 600;
    transition: background .2s ease, transform .2s ease;
}
.sidebar a:hover {
    background: rgba(255,255,255,.20);
    transform: translateX(2px);
}
.main-content { flex: 1; padding: 20px; min-width: 0; }
.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 8px;
}
.topbar-left {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    flex: 1;
}
.sidebar-toggle {
    display: none;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    width: 44px;
    height: 44px;
    padding: 10px;
    background: #fff3e0;
    border: 1px solid #ffd3a5;
    border-radius: 10px;
    cursor: pointer;
    flex-shrink: 0;
}
.sidebar-toggle-bar {
    display: block;
    width: 100%;
    height: 2px;
    background: #a74f00;
    border-radius: 2px;
}
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .45);
    z-index: 999;
}
.cards-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin: 16px 0; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr)); gap: 14px; }
.card {
    background: #fff;
    border-radius: 14px;
    padding: 16px;
    border: 1px solid #ffe1c1;
    box-shadow: 0 8px 18px rgba(242, 122, 24, .10);
}
.card h2, .card h3 { margin-top: 0; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { border-bottom: 1px solid #ffe9d2; padding: 8px; text-align: left; }
th { color: #a74f00; }
form { display: grid; gap: 10px; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.form-grid textarea { min-height: 80px; }
input, select, textarea, button, .btn {
    padding: 10px 12px;
    border: 1px solid #ffd3a5;
    border-radius: 10px;
    background: #fff;
    font-size: 1rem;
    max-width: 100%;
}
form input, form select, form textarea { width: 100%; }
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: #ff9800;
    box-shadow: 0 0 0 3px rgba(255, 152, 0, .20);
}
button, .btn {
    background: linear-gradient(135deg, #ef6c00 0%, #fb8c00 100%);
    color: #fff;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
    border: none;
    font-weight: 600;
}
button:hover, .btn:hover { filter: brightness(1.05); }
.btn-danger { background: #d32f2f; }
.badge { padding: 4px 8px; border-radius: 999px; font-size: 12px; color: #fff; }
.badge-success { background: #2e7d32; }
.badge-warning { background: #f9a825; }
.badge-danger { background: #d32f2f; }
.badge-dark { background: #455a64; }
.badge-neutral { background: #607d8b; }
.alert { padding: 10px; border-radius: 8px; margin: 10px 0; }
.alert-sucesso { background: #e8f5e9; color: #1b5e20; }
.alert-erro { background: #ffebee; color: #b71c1c; }
.alert-aviso { background: #fff8e1; color: #f57f17; }
.login-body {
    display: grid;
    place-items: center;
    min-height: 100vh;
    background: radial-gradient(circle at 10% 10%, #ffcc80 0%, #fb8c00 52%, #ef6c00 100%);
}
.login-card {
    width: min(420px, 92vw);
    background: #fff;
    padding: 22px;
    border-radius: 14px;
    border: 1px solid #ffd7af;
    box-shadow: 0 12px 28px rgba(105, 52, 8, 0.25);
}
.login-card h1 { margin-top: 0; color: #c15f00; }
.login-title { text-align: center; font-size: 2rem; letter-spacing: 0.5px; }
.login-subtitle { color: #7a4a1c; text-align: center; margin-bottom: 20px; }
.login-card p { color: #7a4a1c; }
.login-back {
    text-align: center;
    margin-top: 16px;
    margin-bottom: 0;
    font-size: .9rem;
}
.login-back a {
    color: #a74f00;
    text-decoration: none;
    font-weight: 600;
}
.login-back a:hover { text-decoration: underline; }

/* --- Landing / demonstração rápida --- */
.landing-body {
    min-height: 100vh;
    background: radial-gradient(circle at 10% 10%, #ffcc80 0%, #fb8c00 52%, #ef6c00 100%);
    padding: 24px 16px;
}
.landing-wrap {
    max-width: 1100px;
    margin: 0 auto;
}
.landing-header {
    text-align: center;
    color: #fff;
    margin-bottom: 28px;
}
.landing-title {
    font-size: clamp(2rem, 6vw, 3rem);
    margin: 0 0 8px;
    letter-spacing: 1px;
    text-shadow: 0 2px 8px rgba(0,0,0,.15);
}
.landing-subtitle {
    margin: 0 0 12px;
    font-size: clamp(.95rem, 2.5vw, 1.1rem);
    opacity: .95;
}
.landing-intro {
    max-width: 640px;
    margin: 0 auto;
    font-size: clamp(.9rem, 2.2vw, 1rem);
    opacity: .9;
    line-height: 1.6;
}
.landing-alert { max-width: 640px; margin: 0 auto 16px; }
.profile-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr));
    gap: 16px;
    margin-bottom: 28px;
}
.profile-card {
    background: #fff;
    border-radius: 16px;
    padding: 20px;
    border: 1px solid #ffd7af;
    box-shadow: 0 10px 24px rgba(105, 52, 8, 0.18);
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: 0;
    transition: transform .2s ease, box-shadow .2s ease;
}
.profile-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 14px 32px rgba(105, 52, 8, 0.22);
}
.profile-icon {
    font-size: 2rem;
    line-height: 1;
}
.profile-card h2 {
    margin: 0;
    color: #c15f00;
    font-size: 1.15rem;
}
.profile-card p {
    margin: 0;
    color: #7a4a1c;
    font-size: .9rem;
    flex: 1;
}
.btn-profile { width: 100%; margin-top: 8px; }
.landing-login-section { margin-bottom: 24px; }
.landing-login-card {
    background: rgba(255, 255, 255, .95);
    border-radius: 16px;
    padding: 24px;
    text-align: center;
    border: 1px solid rgba(255, 255, 255, .6);
    box-shadow: 0 8px 20px rgba(0,0,0,.12);
}
.landing-login-card h2 {
    margin: 0 0 8px;
    color: #c15f00;
    font-size: 1.2rem;
}
.landing-login-card p {
    margin: 0 0 16px;
    color: #7a4a1c;
    max-width: 520px;
    margin-left: auto;
    margin-right: auto;
}
.btn-outline {
    background: transparent;
    color: #a74f00;
    border: 2px solid #ff9800;
}
.btn-outline:hover {
    background: #fff3e0;
    filter: none;
}
.landing-footer {
    text-align: center;
    color: rgba(255,255,255,.85);
    font-size: .85rem;
}
.landing-footer p { margin: 0; }

.radio-group { border: 1px solid #ffd3a5; border-radius: 10px; padding: 12px; }
.radio-group legend { font-weight: 600; color: #a74f00; }
.radio-option { display: flex; align-items: center; gap: 8px; margin: 6px 0; }
.ficha-cadastral { background: #fff8f0; border-radius: 10px; padding: 12px; margin: 12px 0; }
.ficha-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 8px; }
.pagination { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 12px; }
.btn-active { filter: brightness(1.15); box-shadow: 0 0 0 2px #1a237e; }
.map-legend { font-size: .9rem; color: #607d8b; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 4px; }
.dot-alerta { background: #d32f2f; }
.dot-ordem { background: #1a237e; }
.semaforo { width: 14px; height: 14px; border-radius: 50%; display: inline-block; margin-right: 6px; }
.semaforo-verde { background: #2e7d32; }
.semaforo-amarelo { background: #f9a825; }
.semaforo-vermelho { background: #d32f2f; }
.inline-form { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.inline-form input, .inline-form select { flex: 1; min-width: 120px; }
.map-box {
    width: 100%;
    height: 280px;
    border-radius: 10px;
    border: 1px solid #ffd3a5;
    margin-bottom: 10px;
}
hr {
    border: none;
    border-top: 1px solid #ffe1c1;
    margin: 16px 0;
}
.section-title { margin: 0 0 8px; color: #a74f00; }
.section-sub { margin: 0 0 14px; color: #7a4a1c; }
.kpi-grid .kpi-card p { margin: 0; }
.kpi-value { font-size: 1.6rem; font-weight: 700; color: #1a237e; }
.kpi-value small { font-size: .9rem; font-weight: 500; }
.kpi-sub { font-size: .85rem; color: #607d8b; margin-top: 4px !important; }
.kpi-danger .kpi-value { color: #c62828; }
.kpi-success .kpi-value { color: #2e7d32; }
.chart-card { margin-top: 14px; }
.chart-container {
    position: relative;
    height: 300px;
    max-width: 100%;
    margin-top: 16px;
    padding: 8px 4px 4px;
    border: 1px solid #ffe1c1;
    border-radius: 10px;
    background: #fffdfa;
}
.chart-container-dashboard {
    height: 260px;
}
.chart-container canvas {
    display: block;
    width: 100% !important;
    height: 100% !important;
}
.row-risco-medio { background: #fff8e1; }
.row-risco-medio:hover { background: #ffecb3; }
.row-risco-alto { background: #ffebee; }
.row-risco-alto:hover { background: #ffcdd2; }
.map-mobile { height: 220px; }
.mobile-ordens-list { display: grid; gap: 10px; margin: 12px 0; }
.mobile-ordem-card {
    background: #fff;
    border: 1px solid #ffe1c1;
    border-radius: 12px;
    padding: 12px;
}
.mobile-ordem-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.mobile-meta { font-size: .9rem; color: #607d8b; margin: 4px 0; }
.mobile-empty { color: #607d8b; font-style: italic; }
.mobile-quick-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-block { width: 100%; text-align: center; margin-top: 8px; }
.user-pill {
    background: #fff3e0;
    border: 1px solid #ffd3a5;
    border-radius: 999px;
    padding: 8px 14px;
    text-align: right;
    font-size: .9rem;
}
.user-pill span { display: block; color: #a74f00; text-transform: capitalize; }
.topbar h1 {
    font-size: clamp(.95rem, 2.5vw, 1.1rem);
    margin: 0;
    color: #a74f00;
    line-height: 1.3;
}

/* --- Responsivo: tablet e mobile --- */
@media (max-width: 900px) {
    .sidebar-toggle { display: flex; }
    .sidebar-close { display: block; }
    .sidebar-overlay:not([hidden]) { display: block; }
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        height: 100dvh;
        width: min(280px, 85vw);
        z-index: 1000;
        transform: translateX(-105%);
        transition: transform .28s ease;
        overflow-y: auto;
        padding-top: max(20px, env(safe-area-inset-top));
        padding-bottom: max(20px, env(safe-area-inset-bottom));
    }
    body.sidebar-open .sidebar { transform: translateX(0); }
    .main-content {
        width: 100%;
        padding: 16px;
        padding-top: max(16px, env(safe-area-inset-top));
    }
    .topbar { flex-direction: column; align-items: stretch; }
    .topbar-left { width: 100%; }
    .user-pill { width: 100%; text-align: left; }
    .chart-container { height: 240px; }
    .chart-container-dashboard { height: 220px; }
    .map-box, .map-mobile { height: 220px; }
    .kpi-value { font-size: 1.35rem; }
    th, td { padding: 6px; font-size: .9rem; }
    .card { padding: 14px; }
    .filters { flex-direction: column; }
    .filters input, .filters select, .filters button, .filters .btn { width: 100%; }
    .inline-form { flex-direction: column; align-items: stretch; }
    .inline-form input, .inline-form select, .inline-form button { width: 100%; }
    .pagination a, .pagination span { min-height: 40px; display: inline-flex; align-items: center; }
}

@media (max-width: 480px) {
    .landing-body { padding: 16px 12px; }
    .profile-card { padding: 16px; }
    .landing-login-card { padding: 18px; }
    .login-card { padding: 18px; }
    .cards-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
    .badge { font-size: 11px; }
    button, .btn { min-height: 44px; }
}

@media (max-width: 360px) {
    .cards-grid { grid-template-columns: 1fr; }
}

@media (max-width: 900px) {
    body.perfil-inspector .sidebar nav a:not([href="dashboard.php"]):not([href="ordens.php"]):not([href="inspeccoes.php"]):not([href="logout.php"]) {
        display: none;
    }
    body.perfil-inspector .grid-2 { grid-template-columns: 1fr; }
    body.perfil-inspector .desktop-table { display: none; }
    body.perfil-inspector .mobile-ordens-panel { display: block; }
}
.mobile-ordens-panel { display: none; }
