/* ============================================================
   Sistema de Frota v2 — Estilos
   Responsivo · Mobile-first · Supabase-powered
   ============================================================ */

/* ===== RESET ===== */
*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}
:root{
  --c-primary:#1a56db;--c-primary-dark:#1341a8;--c-primary-bg:#e8effd;
  --c-bg:#f0f2f5;--c-surface:#fff;--c-text:#1f2937;--c-text2:#6b7280;
  --c-border:#d1d5db;--c-border-light:#e5e7eb;
  --c-danger:#dc2626;--c-danger-bg:#fef2f2;--c-success:#16a34a;--c-warning:#f59e0b;
  --r:8px;--r-lg:12px;--shadow:0 1px 3px rgba(0,0,0,.1);--shadow-lg:0 10px 30px rgba(0,0,0,.15);
  --font:system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif;
}
body{font-family:var(--font);background:var(--c-bg);color:var(--c-text);min-height:100vh;-webkit-tap-highlight-color:transparent;}
img{max-width:100%}
.hidden{display:none!important}

/* ===== SCREENS ===== */
.screen{display:none}
.screen.active{display:flex;flex-direction:column;min-height:100vh}

/* ===== LOGIN ===== */
#screen-login{align-items:center;justify-content:center;position:relative;overflow:hidden}
.login-bg{position:absolute;inset:0;background:linear-gradient(135deg,#0f1b3d 0%,#1a56db 50%,#0f2b4a 100%)}
.login-card{
  position:relative;z-index:1;background:var(--c-surface);
  border-radius:var(--r-lg);padding:36px 28px 28px;width:100%;max-width:400px;
  box-shadow:var(--shadow-lg);margin:16px;
}
.login-header{text-align:center;margin-bottom:24px}
.logo-wrapper{width:80px;height:80px;margin:0 auto 12px;border-radius:var(--r-lg);overflow:hidden;background:var(--c-primary-bg)}
.logo-wrapper img{width:100%;height:100%;object-fit:contain}
.login-header h1{font-size:20px;font-weight:700}
.login-header p{font-size:13px;color:var(--c-text2);margin-top:4px}

.login-form{display:flex;flex-direction:column;gap:14px}
.err-msg{color:var(--c-danger);font-size:13px;text-align:center;min-height:20px}

/* ===== TOPBAR ===== */
.topbar{
  display:flex;align-items:center;justify-content:space-between;
  padding:10px 16px;background:var(--c-surface);border-bottom:1px solid var(--c-border-light);
  box-shadow:var(--shadow);position:sticky;top:0;z-index:100;
}
.topbar-left,.topbar-right{display:flex;align-items:center;gap:8px}
.topbar-logo{width:32px;height:32px;border-radius:6px;object-fit:contain;background:var(--c-primary-bg)}
.topbar-title{font-size:15px;font-weight:700;white-space:nowrap}
.user-tag{font-size:12px;color:var(--c-text2);display:none}

/* ===== MAIN CONTENT ===== */
.main-content{flex:1;padding:24px 16px;max-width:1000px;width:100%;margin:0 auto}
.main-content h2{font-size:20px;margin-bottom:20px}

/* ===== CARD GRID (Dashboard) ===== */
.card-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(170px,1fr));gap:14px}
.dash-card{
  display:flex;flex-direction:column;align-items:center;justify-content:center;gap:10px;
  padding:24px 12px;background:var(--c-surface);border:1px solid var(--c-border-light);
  border-radius:var(--r-lg);cursor:pointer;transition:all .2s;box-shadow:var(--shadow);
  min-height:150px;text-align:center;
}
.dash-card:hover,.dash-card:active{border-color:var(--c-primary);transform:translateY(-2px);box-shadow:0 6px 20px rgba(26,86,219,.15)}
.dash-card svg{color:var(--c-primary);flex-shrink:0}
.dash-card span{font-size:14px;font-weight:600}

/* ===== REPORT GRID ===== */
.report-grid{display:flex;gap:16px;flex-wrap:wrap;justify-content:center;margin-top:20px}
.report-card{
  display:flex;flex-direction:column;align-items:center;justify-content:center;gap:12px;
  padding:32px 24px;background:var(--c-surface);border:2px solid var(--c-border-light);
  border-radius:var(--r-lg);cursor:pointer;transition:all .2s;min-width:200px;min-height:170px;
}
.report-card:hover,.report-card:active{border-color:var(--c-primary);box-shadow:var(--shadow);transform:translateY(-2px)}
.report-card span{font-size:15px;font-weight:600;text-align:center}

/* ===== FILTER BAR ===== */
.filter-bar{
  display:flex;flex-wrap:wrap;gap:10px;align-items:flex-end;
  padding:14px;background:var(--c-surface);border:1px solid var(--c-border-light);
  border-radius:var(--r);margin-bottom:16px;
}
.filter-field{display:flex;flex-direction:column;gap:4px}
.filter-field label{font-size:11px;font-weight:600;color:var(--c-text2);text-transform:uppercase;letter-spacing:.5px}
.filter-field input{padding:7px 10px;border:1px solid var(--c-border);border-radius:6px;font-size:13px}

/* ===== TABLES ===== */
.table-wrap{overflow-x:auto;background:var(--c-surface);border:1px solid var(--c-border-light);border-radius:var(--r)}
.table-wrap table{width:100%;border-collapse:collapse;font-size:13px}
.table-wrap thead{background:var(--c-primary-bg)}
.table-wrap th{padding:10px 10px;text-align:left;font-weight:600;color:var(--c-primary-dark);white-space:nowrap;border-bottom:2px solid var(--c-border-light)}
.table-wrap td{padding:8px 10px;border-bottom:1px solid var(--c-border-light);vertical-align:middle}
.table-wrap tr:hover{background:#f9fafb}
.table-wrap td .btn-sm{margin:1px 2px}
.table-wrap .thumb{cursor:pointer;border-radius:4px;object-fit:cover}
.empty-msg{padding:24px;text-align:center;color:var(--c-text2)}

/* ===== FORMS & FIELDS ===== */
.field{display:flex;flex-direction:column;gap:4px}
.field label{font-size:13px;font-weight:600}
.field-hint{font-size:11px;color:var(--c-text2);margin-bottom:4px}
.field input,.field select{
  padding:9px 12px;border:1px solid var(--c-border);border-radius:var(--r);
  font-size:14px;transition:border-color .2s;width:100%;background:var(--c-surface);
}
.field input:focus,.field select:focus{outline:none;border-color:var(--c-primary);box-shadow:0 0 0 3px rgba(26,86,219,.12)}
.field input::placeholder{color:#9ca3af}
.form-row{display:grid;grid-template-columns:1fr 1fr;gap:12px}
.form-actions{display:flex;gap:8px;flex-wrap:wrap;margin-top:4px}

.file-input{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0,0,0,0)}
hr{border:none;border-top:1px solid var(--c-border-light);margin:16px 0}

/* ===== BUTTONS ===== */
.btn{
  display:inline-flex;align-items:center;justify-content:center;gap:6px;
  padding:9px 18px;border:none;border-radius:var(--r);font-size:14px;font-weight:600;
  cursor:pointer;transition:all .2s;white-space:nowrap;
}
.btn-primary{background:var(--c-primary);color:#fff}
.btn-primary:hover,.btn-primary:active{background:var(--c-primary-dark)}
.btn-outline{background:transparent;border:1px solid var(--c-border);color:var(--c-text)}
.btn-outline:hover,.btn-outline:active{background:var(--c-bg)}
.btn-danger{background:var(--c-danger);color:#fff}
.btn-danger:hover{background:#b91c1c}
.btn-danger-outline{color:var(--c-danger);border-color:var(--c-danger)}
.btn-danger-outline:hover{background:var(--c-danger-bg)}
.btn-warning{background:var(--c-warning);color:#fff}
.btn-warning:hover{background:#d97706}
.btn-sm{padding:5px 10px;font-size:12px}
.btn-ghost{background:transparent;border:none;color:var(--c-text2);padding:6px}
.btn-ghost:hover{background:var(--c-bg);border-radius:6px}
.btn-block{width:100%}
.btn-icon{background:transparent;border:none;color:var(--c-text2);cursor:pointer;padding:6px;border-radius:6px;display:flex;align-items:center;justify-content:center}
.btn-icon:hover{background:var(--c-bg);color:var(--c-text)}

/* ===== MODALS ===== */
.modal-overlay{
  display:none;position:fixed;inset:0;background:rgba(0,0,0,.5);
  align-items:flex-start;justify-content:center;padding:32px 12px;
  z-index:1000;overflow-y:auto;
}
.modal-overlay.active{display:flex}
.modal{background:var(--c-surface);border-radius:var(--r-lg);width:100%;max-width:480px;box-shadow:var(--shadow-lg);margin-bottom:40px}
.modal-lg{max-width:700px}
.modal-photo{max-width:900px}
.carousel-body{display:flex;align-items:center;justify-content:center;position:relative}
.carousel-btn{position:absolute;top:50%;transform:translateY(-50%);width:36px;height:36px;border-radius:50%;border:none;background:rgba(0,0,0,.45);color:#fff;display:flex;align-items:center;justify-content:center;cursor:pointer;transition:background .2s;z-index:2;padding:0}
.carousel-prev{left:4px}
.carousel-next{right:4px}
.carousel-btn:hover:not(:disabled){background:rgba(0,0,0,.7)}
.carousel-btn:disabled{opacity:.35;cursor:default}
.carousel-counter{text-align:center;padding:8px 0 4px;font-size:13px;color:var(--c-text2)}
.modal-head{display:flex;align-items:center;justify-content:space-between;padding:14px 18px;border-bottom:1px solid var(--c-border-light)}
.modal-head h3{font-size:15px;font-weight:700}
.modal-x{background:none;border:none;font-size:24px;cursor:pointer;color:var(--c-text2);padding:0 4px;line-height:1}
.modal-x:hover{color:var(--c-text)}
.modal-body{padding:18px}
.modal-body.center{text-align:center}
.modal-body h4{font-size:13px;color:var(--c-text2);margin-bottom:10px}

/* ===== PHOTOS ===== */
.photo-box{
  border:2px dashed var(--c-border);border-radius:var(--r);padding:16px;
  text-align:center;cursor:pointer;transition:border-color .2s;min-height:100px;
  display:flex;align-items:center;justify-content:center;
}
.photo-box:hover,.photo-box:active{border-color:var(--c-primary)}
.photo-box.has-photo{border-style:solid;border-color:var(--c-success);padding:4px}
.photo-img{max-height:160px;border-radius:6px;object-fit:cover}
.photo-empty{display:flex;flex-direction:column;align-items:center;gap:6px;color:var(--c-text2);font-size:13px}

.photo-grid{display:flex;flex-wrap:wrap;gap:8px}
.photo-slot{
  width:80px;height:80px;border:2px dashed var(--c-border);border-radius:var(--r);
  display:flex;align-items:center;justify-content:center;cursor:pointer;position:relative;
  overflow:hidden;transition:border-color .2s;flex-shrink:0;
}
.photo-slot:hover,.photo-slot:active{border-color:var(--c-primary)}
.photo-slot.has-photo{border-style:solid;border-color:var(--c-success)}
.photo-slot-plus{font-size:30px;color:var(--c-border);font-weight:300;user-select:none}
.photo-slot-img{width:100%;height:100%;object-fit:cover}
.photo-slot-del{
  position:absolute;top:2px;right:2px;width:22px;height:22px;
  background:rgba(220,38,38,.85);color:#fff;border:none;border-radius:50%;
  font-size:14px;cursor:pointer;align-items:center;justify-content:center;line-height:1;
  display:none;
}
.photo-slot:hover .photo-slot-del{display:flex}

/* ===== LOGO PREVIEW ===== */
.logo-preview-box{
  width:120px;height:120px;border:2px dashed var(--c-border);border-radius:var(--r);
  display:flex;align-items:center;justify-content:center;margin-top:8px;overflow:hidden;
  background:var(--c-bg);
}
.logo-preview-box img{width:100%;height:100%;object-fit:contain}
.logo-placeholder{font-size:12px;color:var(--c-text2);text-align:center;padding:8px}

/* ===== TOASTS ===== */
#toasts{position:fixed;bottom:20px;right:20px;z-index:2000;display:flex;flex-direction:column;gap:8px;max-width:360px}
.toast{padding:11px 18px;border-radius:var(--r);color:#fff;font-size:13px;font-weight:500;box-shadow:var(--shadow-lg);animation:slideUp .3s ease}
.toast-success{background:var(--c-success)}
.toast-error{background:var(--c-danger)}
.toast-warn{background:var(--c-warning)}
.toast-info{background:var(--c-primary)}
@keyframes slideUp{from{transform:translateY(20px);opacity:0}to{transform:translateY(0);opacity:1}}

/* ===== RESPONSIVE ===== */
@media(max-width:640px){
  .login-card{padding:24px 16px 20px;margin:10px}
  .topbar{padding:8px 12px}
  .topbar-title{font-size:13px}
  .main-content{padding:16px 12px}
  .card-grid{grid-template-columns:1fr 1fr;gap:10px}
  .dash-card{padding:18px 8px;min-height:130px}
  .dash-card span{font-size:13px}
  .report-grid{flex-direction:column;align-items:center}
  .report-card{min-width:100%;max-width:300px;min-height:140px;padding:24px 16px}
  .form-row{grid-template-columns:1fr}
  .filter-bar{flex-direction:column}
  .photo-slot{width:68px;height:68px}
  .modal-overlay{padding:16px 8px}
  .modal-body{padding:14px}
  .user-tag{display:none!important}
}
@media(min-width:641px){
  .user-tag{display:inline}
}

/* ===== FLEET REPORT COLUMN FILTERS ===== */
.fleet-rpt-filters{margin-bottom:8px}
.frf-row{display:flex;flex-wrap:wrap;gap:6px}
.frf-input{padding:6px 8px;border:1px solid var(--c-border);border-radius:6px;font-size:12px;flex:1;min-width:80px;max-width:130px;background:var(--c-surface)}
.frf-input:focus{outline:none;border-color:var(--c-primary);box-shadow:0 0 0 3px rgba(26,86,219,.12)}

/* ===== TOGGLE SWITCH (Motorista) ===== */
.toggle-row{display:flex;align-items:center;justify-content:space-between;gap:12px}
.toggle-row .toggle-label{font-size:14px;font-weight:600}
.toggle-switch{
  width:52px;height:28px;background:var(--c-border);border-radius:14px;
  cursor:pointer;position:relative;transition:background .25s;flex-shrink:0;
}
.toggle-switch.active{background:var(--c-success)}
.toggle-switch::after{
  content:'';position:absolute;top:3px;left:3px;
  width:22px;height:22px;background:#fff;border-radius:50%;
  transition:transform .25s;box-shadow:0 1px 3px rgba(0,0,0,.2);
}
.toggle-switch.active::after{transform:translateX(24px)}

/* ===== PDF ATTACH ===== */
.pdf-attach-box{
  border:2px dashed var(--c-border);border-radius:var(--r);padding:14px 16px;
  display:flex;align-items:center;justify-content:space-between;gap:10px;
  cursor:pointer;transition:border-color .2s;min-height:48px;
}
.pdf-attach-box:hover,.pdf-attach-box:active{border-color:var(--c-primary)}
.pdf-attach-box.has-file{border-style:solid;border-color:var(--c-success);background:#f0fdf4}
.pdf-attach-name{font-size:13px;color:var(--c-text);font-weight:500;word-break:break-all}
.pdf-attach-placeholder{font-size:13px;color:var(--c-text2)}
.pdf-attach-icon{color:var(--c-primary);flex-shrink:0}
.pdf-attach-del{
  background:none;border:none;color:var(--c-danger);cursor:pointer;font-size:20px;
  padding:0 4px;line-height:1;flex-shrink:0;
}

/* ===== FUELING PHOTOS ===== */
.fuel-photo-row{display:flex;gap:16px;flex-wrap:wrap}
.fuel-photo-slot{
  flex:1;min-width:140px;border:2px dashed var(--c-border);border-radius:var(--r);
  padding:20px;text-align:center;cursor:pointer;transition:all .2s;
  display:flex;flex-direction:column;align-items:center;gap:8px;
}
.fuel-photo-slot:hover,.fuel-photo-slot:active{border-color:var(--c-primary)}
.fuel-photo-slot.has-photo{border-style:solid;border-color:var(--c-success);padding:8px}
.fuel-photo-slot .photo-label{font-size:12px;font-weight:600;color:var(--c-text2)}
.fuel-photo-slot .fuel-photo-img{max-height:160px;border-radius:6px;object-fit:cover}
.fuel-btn-row{display:flex;gap:6px;flex-wrap:wrap;justify-content:center}
.fuel-btn-row .btn{font-size:11px;padding:5px 8px}
.fuel-photo-del{position:absolute;top:4px;right:4px;width:24px;height:24px;background:rgba(220,38,38,.85);color:#fff;border:none;border-radius:50%;font-size:16px;cursor:pointer;z-index:2;display:flex;align-items:center;justify-content:center}
.fuel-photo-slot{position:relative}
.fuel-photo-slot.has-photo .fuel-btn-row{display:none}

/* ===== BADGE ===== */
.badge{display:inline-block;padding:2px 8px;border-radius:10px;font-size:11px;font-weight:600}
.badge-active{background:#dcfce7;color:#166534}
.badge-inactive{background:#fef2f2;color:#991b1b}
.badge-driver{background:#dbeafe;color:#1e40af}
.badge-propria{background:#dcfce7;color:#166534}
.badge-terceiros{background:#fef3c7;color:#92400e}
.badge-alugado{background:#ede9fe;color:#5b21b6}
.badge-fuel{background:#fce7f3;color:#9d174d}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar{width:5px;height:5px}
::-webkit-scrollbar-track{background:transparent}
::-webkit-scrollbar-thumb{background:#ccc;border-radius:3px}

/* ===== DADOS VIVOS (v4) — Summary Cards ===== */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-top: 20px;
  margin-bottom: 8px;
}
.sum-card {
  background: #fff;
  border-radius: 10px;
  padding: 14px;
  text-align: center;
  box-shadow: 0 1px 4px rgba(0,0,0,.08);
  border-left: 4px solid #d1d5db;
}
.sum-card.sum-fleet  { border-left-color: #1a56db; }
.sum-card.sum-fuel   { border-left-color: #f59e0b; }
.sum-card.sum-unload { border-left-color: #10b981; }
.sum-card.sum-drivers{ border-left-color: #8b5cf6; }
.sum-num {
  display: block;
  font-size: 26px;
  font-weight: 700;
  line-height: 1.2;
}
.sum-num small {
  font-size: 14px;
  font-weight: 400;
  color: #6b7280;
}
.sum-label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: #6b7280;
  margin-top: 2px;
}
.sum-sub {
  display: block;
  font-size: 11px;
  color: #9ca3af;
  margin-top: 1px;
}
@media (min-width: 600px) {
  .summary-grid { grid-template-columns: repeat(4, 1fr); }
}

/* ===== LOADING OVERLAY ===== */
.loading-overlay{position:fixed;top:0;left:0;right:0;bottom:0;background:rgba(0,0,0,.55);z-index:999;display:none;align-items:center;justify-content:center;flex-direction:column}
.loading-overlay.active{display:flex}
.loading-spinner{width:48px;height:48px;position:relative}
.loading-spinner .bar{position:absolute;left:50%;top:50%;width:4px;height:12px;margin-left:-2px;margin-top:-6px;border-radius:3px;background:rgba(255,255,255,.2);transform-origin:2px 6px;animation:spin 1.2s linear infinite}
.loading-spinner .bar:nth-child(1){transform:rotate(0deg) translateY(-16px);animation-delay:0s}
.loading-spinner .bar:nth-child(2){transform:rotate(30deg) translateY(-16px);animation-delay:.1s}
.loading-spinner .bar:nth-child(3){transform:rotate(60deg) translateY(-16px);animation-delay:.2s}
.loading-spinner .bar:nth-child(4){transform:rotate(90deg) translateY(-16px);animation-delay:.3s}
.loading-spinner .bar:nth-child(5){transform:rotate(120deg) translateY(-16px);animation-delay:.4s}
.loading-spinner .bar:nth-child(6){transform:rotate(150deg) translateY(-16px);animation-delay:.5s}
.loading-spinner .bar:nth-child(7){transform:rotate(180deg) translateY(-16px);animation-delay:.6s}
.loading-spinner .bar:nth-child(8){transform:rotate(210deg) translateY(-16px);animation-delay:.7s}
.loading-spinner .bar:nth-child(9){transform:rotate(240deg) translateY(-16px);animation-delay:.8s}
.loading-spinner .bar:nth-child(10){transform:rotate(270deg) translateY(-16px);animation-delay:.9s}
.loading-spinner .bar:nth-child(11){transform:rotate(300deg) translateY(-16px);animation-delay:1s}
.loading-spinner .bar:nth-child(12){transform:rotate(330deg) translateY(-16px);animation-delay:1.1s}
@keyframes spin{0%,100%{background:rgba(255,255,255,.2)}50%{background:rgba(255,255,255,.9)}}
.loading-text{color:#fff;font-size:14px;font-weight:500;margin-top:16px;letter-spacing:1px}

/* ===== PRINT HEADER (hidden on screen) ===== */
.print-header, .print-footer { display: none; }

/* ===== PRINT STYLES ===== */
@media print {
  @page { margin: 12mm 10mm 18mm; }
  @page :first { margin-top: 10mm; }

  body { background: #fff; color: #000; font-size: 10px; }
  .screen { display: block !important; min-height: auto; }
  .screen.active { display: block !important; }
  .screen:not(.active) { display: none !important; }
  .topbar, .filter-bar, .fleet-rpt-filters { display: none !important; }
  .main-content { padding: 0 !important; max-width: 100%; margin: 0; }

  /* Report header — só na primeira página */
  .print-header {
    display: block !important;
    padding: 4px 0 8px 0;
    margin-bottom: 12px;
    border-bottom: 2px solid #222;
  }
  .print-header .ph-text { line-height: 1.35; text-align: left; }
  .print-header .ph-name { font-size: 14px; font-weight: 700; color: #000; letter-spacing: .5px; }
  .print-header .ph-legal { font-size: 10px; color: #333; margin-top: 2px; }
  .print-header .ph-reg { font-size: 8px; color: #555; margin-top: 1px; }
  .print-header .ph-reg span + span::before { content: ' | '; }

  /* Report title */
  .print-title {
    font-size: 13px;
    font-weight: 700;
    text-align: center;
    margin-bottom: 10px;
    padding-bottom: 5px;
    border-bottom: 1px solid #888;
  }

  /* Tables */
  .table-wrap { border: 1px solid #888; border-radius: 0; overflow: visible; }
  .table-wrap table { font-size: 9px; width: 100%; }
  .table-wrap th {
    background: #e0e0e0 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
    color: #000 !important;
    border-bottom: 2px solid #666;
    padding: 5px 5px;
    font-size: 9px;
  }
  .table-wrap td { padding: 3px 5px; border-bottom: 1px solid #ccc; }
  .table-wrap tr:hover { background: transparent; }
  .table-wrap .badge {
    background: #e0e0e0 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
    color: #000 !important;
    font-size: 8px;
  }

  /* Page number no rodapé de cada página */
  .print-footer {
    display: block !important;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    text-align: center;
    font-size: 8px;
    color: #888;
    padding: 3px 0;
    border-top: 1px solid #bbb;
  }
  .print-footer::after { content: 'VIABUS EXPRESS  |  Página ' counter(page); }

  /* Hide interactive elements */
  .btn, .btn-sm, .btn-ghost, .btn-primary, .btn-outline, .btn-danger,
  .photo-slot, .fuel-photo-slot, .file-input,
  .modal-overlay, .modal, .toast, #toasts,
  .dash-card, .card-grid, .report-grid, .report-card,
  .summary-grid, .user-tag, input, select, .frf-input { display: none !important; }

  .empty-msg { display: none !important; }
  .table-wrap .thumb { max-width: 24px; max-height: 24px; }
  .table-wrap tr { page-break-inside: avoid; }
}
