:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --sidebar-bg: #0f172a;
  --sidebar-text: #cbd5e1;
  --primary: #0284c7;
  --primary-hover: #0369a1;
  --primary-soft: #e0f2fe;
  --success: #16a34a;
  --success-soft: #dcfce7;
  --warning: #d97706;
  --warning-soft: #fef3c7;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --whatsapp: #16a34a;
  --radius: 12px;
  --shadow: 0 4px 18px rgba(15, 23, 42, 0.06);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

.boot-loader {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-weight: 600;
}

/* Login */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(135deg, #0f172a 0%, #0c4a6e 100%);
}
.login-card {
  background: #fff;
  border-radius: 16px;
  padding: 32px;
  max-width: 420px;
  width: 100%;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.35);
}
.login-card h1 { margin: 0 0 6px; font-size: 1.4rem; }
.login-card p.sub { margin: 0 0 22px; color: var(--text-muted); font-size: 0.9rem; }

/* Layout Principal */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 260px;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.sidebar-brand {
  padding: 18px 20px;
  border-bottom: 1px solid #1e293b;
  display: flex;
  align-items: center;
  gap: 10px;
}
.sidebar-brand img {
  width: 38px; height: 38px; object-fit: contain; border-radius: 8px; background: #fff; padding: 2px;
}
.sidebar-brand .brand-text strong { display: block; color: #fff; font-size: 0.98rem; }
.sidebar-brand .brand-text span { font-size: 0.75rem; color: #38bdf8; }
.nav-list { padding: 12px 10px; flex: 1; }
.nav-section {
  font-size: 0.7rem; text-transform: uppercase; letter-spacing: .08em;
  color: #64748b; padding: 12px 12px 4px; font-weight: 700;
}
.nav-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: transparent;
  border: none;
  color: var(--sidebar-text);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 0.92rem;
  cursor: pointer;
  text-align: left;
  transition: background .15s, color .15s;
}
.nav-btn:hover { background: #1e293b; color: #fff; }
.nav-btn.active { background: var(--primary); color: #fff; font-weight: 600; }
.nav-btn .nav-left { display: flex; align-items: center; gap: 10px; }
.nav-badge {
  background: #ef4444; color: #fff; border-radius: 999px; font-size: 0.72rem;
  padding: 1px 7px; font-weight: 700;
}
.sidebar-footer {
  padding: 14px 16px;
  border-top: 1px solid #1e293b;
  font-size: 0.85rem;
}
.sidebar-footer .user-name { color: #fff; font-weight: 600; display: block; }
.sidebar-footer .user-role { color: #94a3b8; font-size: 0.75rem; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar-title { font-size: 1.15rem; font-weight: 700; margin: 0; }
.topbar-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.mobile-menu-btn { display: none; }
.content { padding: 22px 24px; max-width: 1440px; width: 100%; margin: 0 auto; }

/* Cards & Grids */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
  margin-bottom: 18px;
}
.card-header {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-bottom: 14px; flex-wrap: wrap;
}
.card-title { margin: 0; font-size: 1rem; font-weight: 700; }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(195px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
}
.kpi-label { font-size: 0.8rem; color: var(--text-muted); font-weight: 600; }
.kpi-value { font-size: 1.65rem; font-weight: 800; margin: 4px 0 2px; color: var(--text); }
.kpi-sub { font-size: 0.78rem; color: var(--text-muted); }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }

/* Forms & Inputs */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.form-grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.col-span-2 { grid-column: span 2; }
.col-span-full { grid-column: 1 / -1; }

.field label {
  display: block; font-size: 0.82rem; font-weight: 600; color: #334155; margin-bottom: 4px;
}
.field input, .field select, .field textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  font-size: 0.92rem;
  font-family: inherit;
  background: #fff;
  color: var(--text);
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.14);
}
.input-group { display: flex; gap: 8px; }
.input-group input { flex: 1; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid transparent; border-radius: 8px;
  padding: 8px 14px; font-size: 0.88rem; font-weight: 600; cursor: pointer;
  text-decoration: none; transition: all .15s; background: #e2e8f0; color: var(--text);
}
.btn:hover { filter: brightness(0.96); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-outline { background: #fff; border-color: #cbd5e1; color: var(--text); }
.btn-whatsapp { background: #16a34a; color: #fff; }
.btn-sm { padding: 5px 10px; font-size: 0.8rem; border-radius: 6px; }

/* Badges */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 9px; border-radius: 999px; font-size: 0.75rem; font-weight: 700;
  white-space: nowrap;
}
.badge-open { background: #dbeafe; color: #1d4ed8; }
.badge-progress { background: #dcfce7; color: #15803d; }
.badge-paused { background: #fef3c7; color: #b45309; }
.badge-done { background: #e2e8f0; color: #334155; }
.badge-danger { background: #fee2e2; color: #b91c1c; }
.badge-info { background: #e0f2fe; color: #0369a1; }

.timer-pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-weight: 700; font-size: 0.84rem;
  padding: 3px 9px; border-radius: 6px;
  background: #f1f5f9; border: 1px solid #cbd5e1;
}
.timer-pill.running {
  background: #dcfce7; border-color: #22c55e; color: #14532d;
}
.pulse-dot {
  width: 8px; height: 8px; border-radius: 50%; background: #16a34a;
  animation: pulse 1.3s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.8); }
}

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
th { font-size: 0.76rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); background: var(--surface-alt); }
tr:hover td { background: #f8fafc; }

/* Toolbar / Tabs */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 14px; }
.toolbar input[type=search], .toolbar input[type=text], .toolbar select {
  padding: 8px 11px; border: 1px solid #cbd5e1; border-radius: 8px; font-size: 0.88rem; background: #fff;
}
.tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--border); margin-bottom: 16px; flex-wrap: wrap; }
.tab-btn {
  padding: 9px 14px; border: none; background: transparent; cursor: pointer;
  font-weight: 600; color: var(--text-muted); border-bottom: 2px solid transparent; font-size: 0.9rem;
}
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }

/* Modals */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15, 23, 42, 0.58);
  display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 100;
}
.modal-box {
  background: #fff; border-radius: 14px; max-width: 780px; width: 100%;
  max-height: 92vh; display: flex; flex-direction: column; box-shadow: 0 25px 60px rgba(0, 0, 0, 0.3);
}
.modal-box.wide { max-width: 980px; }
.modal-head {
  padding: 16px 20px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-head h3 { margin: 0; font-size: 1.05rem; }
.modal-body { padding: 18px 20px; overflow-y: auto; }
.modal-foot {
  padding: 14px 20px; border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 10px; background: var(--surface-alt); border-radius: 0 0 14px 14px;
}

/* Signature Canvas */
.sig-pad-wrap {
  border: 1.5px dashed #94a3b8; border-radius: 8px; background: #fff; overflow: hidden;
}
.sig-pad-wrap canvas {
  display: block; width: 100%; height: 140px; touch-action: none; cursor: crosshair;
}

/* Toast */
#toast-root {
  position: fixed; right: 18px; bottom: 18px; z-index: 200;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  background: #0f172a; color: #fff; padding: 11px 16px; border-radius: 10px;
  font-size: 0.88rem; font-weight: 600; box-shadow: 0 10px 25px rgba(0,0,0,0.25);
  max-width: 360px;
}
.toast.ok { border-left: 4px solid #22c55e; }
.toast.err { border-left: 4px solid #ef4444; }

/* Bar Chart */
.bar-row { margin-bottom: 10px; }
.bar-meta { display: flex; justify-content: space-between; font-size: 0.82rem; margin-bottom: 3px; }
.bar-track { height: 9px; background: #e2e8f0; border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--primary); border-radius: 999px; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li {
  position: relative; padding: 0 0 12px 18px; border-left: 2px solid #cbd5e1; margin-left: 6px;
}
.timeline li::before {
  content: ""; position: absolute; left: -6px; top: 4px; width: 10px; height: 10px;
  border-radius: 50%; background: var(--primary);
}
.timeline .tl-time { font-size: 0.75rem; color: var(--text-muted); }

@media (max-width: 900px) {
  .sidebar { position: fixed; left: -270px; z-index: 90; transition: left .2s; }
  .sidebar.open { left: 0; }
  .mobile-menu-btn { display: inline-flex; }
  .grid-2, .grid-3, .form-grid, .form-grid-3 { grid-template-columns: 1fr; }
  .col-span-2 { grid-column: auto; }
  .content { padding: 14px; }
}

/* Autocomplete e Busca Preditiva */
.autocomplete-wrap {
  position: relative;
  width: 100%;
}
.autocomplete-box {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: #ffffff;
  border: 1.5px solid #0284c7;
  border-radius: 8px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.18);
  max-height: 240px;
  overflow-y: auto;
  z-index: 1050;
}
.autocomplete-item {
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid #f1f5f9;
  font-size: 0.9rem;
  line-height: 1.35;
  transition: background 0.15s;
}
.autocomplete-item:last-child {
  border-bottom: none;
}
.autocomplete-item:hover, .autocomplete-item.active {
  background: #e0f2fe;
}
.autocomplete-item-title {
  font-weight: 700;
  color: #0f172a;
}
.autocomplete-item-sub {
  font-size: 0.8rem;
  color: #64748b;
  margin-top: 2px;
}
.autocomplete-selected-tag {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 8px 12px;
  background: #f0fdf4;
  border: 1.5px solid #86efac;
  border-radius: 8px;
  font-size: 0.9rem;
  color: #166534;
  font-weight: 600;
  margin-top: 6px;
}
.autocomplete-clear-btn {
  background: none;
  border: none;
  color: #dc2626;
  font-weight: bold;
  cursor: pointer;
  padding: 2px 6px;
  font-size: 0.9rem;
  line-height: 1;
  border-radius: 4px;
}
.autocomplete-clear-btn:hover {
  background: #fee2e2;
}

.print-only-header {
  display: none;
}

@media print {
  @page {
    size: A4 landscape;
    margin: 10mm 12mm;
  }

  body {
    background: #ffffff !important;
    color: #111827 !important;
    font-size: 11px !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  .sidebar,
  .topbar,
  .no-print,
  .toolbar,
  .tabs,
  .btn,
  .toast-container {
    display: none !important;
  }

  .layout,
  .main,
  .content {
    display: block !important;
    margin: 0 !important;
    padding: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    overflow: visible !important;
  }

  .print-only-header {
    display: flex !important;
    justify-content: space-between;
    align-items: flex-end;
    border-bottom: 2px solid #1e293b;
    padding-bottom: 8px;
    margin-bottom: 12px;
  }

  .print-only-header h2 {
    margin: 0 0 2px 0;
    font-size: 16px;
    color: #0f172a;
  }

  .print-only-header p {
    margin: 0;
    font-size: 11px;
    color: #475569;
  }

  .card {
    box-shadow: none !important;
    border: 1px solid #cbd5e1 !important;
    padding: 10px 12px !important;
    margin-bottom: 10px !important;
    break-inside: avoid;
  }

  .kpi-grid {
    display: grid !important;
    grid-template-columns: repeat(4, 1fr) !important;
    gap: 8px !important;
    margin-bottom: 10px !important;
  }

  .kpi-card {
    box-shadow: none !important;
    border: 1px solid #cbd5e1 !important;
    padding: 8px 10px !important;
  }

  .table-wrap {
    overflow: visible !important;
  }

  table {
    width: 100% !important;
    border-collapse: collapse !important;
    font-size: 10px !important;
  }

  th,
  td {
    padding: 5px 6px !important;
    border-bottom: 1px solid #e2e8f0 !important;
  }

  tr {
    break-inside: avoid;
  }
}
