:root {
  --primary: #4AA9E9;
  --primary-strong: #2B6CB0;
  --primary-light: #E8F4FC;
  --navy: #0B2545;
  --success: #22C55E;
  --success-light: #DCFCE7;
  --warning: #F59E0B;
  --warning-light: #FEF3C7;
  --danger: #EF4444;
  --danger-light: #FEE2E2;
  --purple: #8B5CF6;
  --purple-light: #EDE9FE;
  --ice: #E2E8F0;
  --bg: #E2E8F0;
  --surface: #ffffff;
  --text: #0B2545;
  --muted: #5B6B7C;
  --border: #CBD5E0;
  --header: #ffffff;
  --table-head: #F4F7FA;
  --zebra: #F7FAFC;
  --sidebar: #0B2545;
  --fc-primary: var(--primary);
  --fc-navy: var(--navy);
  --fc-accent: #4AA9E9;
  --fc-ice: var(--ice);
}

html.dark {
  color-scheme: dark;
  --primary: #4AA9E9;
  --primary-strong: #4AA9E9;
  --primary-light: #123A5C;
  --ice: #08182C;
  --bg: #08182C;
  --surface: #0F2C4A;
  --text: #E8EEF7;
  --muted: #94A3B8;
  --border: #1E3A5F;
  --header: #0B2545;
  --table-head: #123A5C;
  --zebra: #0B2545;
  --sidebar: #0B2545;
  --success-light: #14532D;
  --warning-light: #78350F;
  --danger-light: #7F1D1D;
  --purple-light: #3B0764;
}

html, body { font-family: Inter, ui-sans-serif, system-ui, sans-serif; background: var(--bg); color: var(--text); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 10px 28px rgb(11 37 69 / 12%), 0 2px 8px rgb(11 37 69 / 6%);
}
.btn { border-radius: 10px; font-weight: 600; font-size: 14px; padding: 0.55rem 1rem; display: inline-flex; align-items: center; gap: 8px; }
.btn-primary { background: var(--primary); color: #0B2545; border-radius: 10px; font-weight: 700; }
.btn-primary:hover { filter: brightness(1.05); }
.btn-success { background: var(--success); color: #fff; border-radius: 10px; font-weight: 600; }
.btn-danger { background: var(--danger); color: #fff; border-radius: 10px; font-weight: 600; }
.btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 10px; font-weight: 600; }
.badge, .ui-badge { border-radius: 999px; padding: 2px 10px; font-size: 12px; font-weight: 600; }
.ui-badge-success { background: var(--success-light); color: #166534; }
.ui-badge-warning { background: var(--warning-light); color: #92400E; }
.ui-badge-danger { background: var(--danger-light); color: #991B1B; }
.ui-badge-info { background: var(--primary-light); color: #2B6CB0; }
.ui-badge-purple { background: var(--purple-light); color: #6D28D9; }
.ui-badge-muted { background: var(--table-head); color: var(--muted); }
html.dark .ui-badge-success { color: #86EFAC; }
html.dark .ui-badge-warning { color: #FDE68A; }
html.dark .ui-badge-danger { color: #FCA5A5; }
html.dark .ui-badge-info { color: #7DD3FC; }
html.dark .ui-badge-purple { color: #C4B5FD; }
html.dark .btn-primary { color: #0B2545; }
.input { border: 1px solid var(--border); border-radius: 10px; padding: 0.6rem 0.8rem; width: 100%; background: var(--surface); color: var(--text); }
.input:focus { outline: 2px solid color-mix(in srgb, var(--primary) 45%, white); border-color: var(--primary); }

.shell-navy { background: var(--sidebar); color: #fff; }
.sidebar-link { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 10px; color: rgba(255,255,255,.88); font-size: 14px; }
.sidebar-link:hover { background: rgba(74,169,233,.18); color: #fff; }
.sidebar-link.active { background: var(--primary); color: #0B2545; font-weight: 700; }
.sidebar-search { width: 100%; border: 1px solid rgba(203,213,224,.35); background: rgba(255,255,255,.08); color: #fff; border-radius: 10px; padding: 0.5rem 0.75rem; font-size: 13px; }
.sidebar-search::placeholder { color: rgba(255,255,255,.55); }
.sidebar-search:focus { outline: 2px solid var(--primary); border-color: var(--primary); }
.nav-group-btn { width: 100%; display: flex; align-items: center; justify-content: space-between; padding: 8px 12px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: rgba(255,255,255,.65); }
.nav-group-btn:hover { color: #fff; }
.theme-toggle { display: flex; width: 100%; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 10px; color: rgba(255,255,255,.88); font-size: 13px; font-weight: 600; border: 1px solid rgba(203,213,224,.25); }
.theme-toggle:hover { background: rgba(74,169,233,.18); color: #fff; }
[x-cloak] { display: none !important; }

.table-zebra tbody tr:nth-child(even) { background: var(--zebra); }
.ui-table { width: 100%; font-size: 14px; }
.ui-table thead { background: var(--table-head); color: var(--muted); text-align: left; }
.ui-table th, .ui-table td { padding: 0.75rem 1rem; }
.ui-table tbody tr { border-top: 1px solid var(--border); }
.ui-table tbody tr:hover { background: var(--table-head); }

.metric-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.1rem 1.2rem;
  box-shadow: 0 10px 28px rgb(11 37 69 / 12%), 0 2px 8px rgb(11 37 69 / 6%);
}
.metric-card .label { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
.metric-card .value { font-size: 1.6rem; font-weight: 800; margin-top: 0.35rem; }
.metric-card .hint { font-size: 12px; color: var(--muted); margin-top: 0.25rem; }

.page-header { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; }
.page-header h1 { font-size: 1.5rem; font-weight: 800; }
.page-header p { color: var(--muted); font-size: 14px; margin-top: 2px; }

.empty-state { text-align: center; padding: 3rem 1.5rem; color: var(--muted); border: 1px dashed var(--border); border-radius: 14px; background: var(--surface); box-shadow: 0 10px 28px rgb(11 37 69 / 12%), 0 2px 8px rgb(11 37 69 / 6%); }
.empty-state .icon { width: 48px; height: 48px; margin: 0 auto 12px; color: #94A3B8; }

.ui-tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.ui-tab { padding: 0.4rem 0.85rem; border-radius: 999px; font-size: 13px; font-weight: 600; color: var(--muted); background: var(--surface); border: 1px solid var(--border); }
.ui-tab.active { background: var(--primary-light); color: var(--primary-strong); border-color: var(--primary); }

.drawer-overlay { position: fixed; inset: 0; background: rgb(11 37 69 / 45%); z-index: 50; }
.drawer-panel { position: fixed; top: 0; right: 0; height: 100%; width: min(420px, 100%); background: var(--surface); z-index: 51; overflow-y: auto; border-left: 1px solid var(--border); box-shadow: -8px 0 24px rgb(11 37 69 / 12%); }

.app-header { background: var(--header); border-color: var(--border); box-shadow: 0 4px 16px rgb(11 37 69 / 6%); }
.app-main { background: var(--bg); }

html.dark .card, html.dark .metric-card { box-shadow: 0 12px 28px rgb(0 0 0 / 35%); }

html.dark .bg-white { background-color: var(--surface); }
html.dark .bg-slate-50, html.dark .bg-slate-100 { background-color: var(--table-head); }
html.dark .text-slate-900 { color: var(--text); }
html.dark .text-slate-600, html.dark .text-slate-500, html.dark .text-slate-400 { color: var(--muted); }
html.dark .border-slate-200, html.dark .border-slate-100, html.dark .border-b, html.dark .border-t { border-color: var(--border); }
html.dark .hover\:bg-slate-50:hover, html.dark .dark-hover:hover { background-color: rgba(255,255,255,.06); }
html.dark .bg-blue-100 { background-color: #123A5C; }
html.dark .text-blue-700, html.dark .text-blue-600 { color: #7DD3FC; }

.header-actions:empty { display: none; }

.app-popover-panel {
  position: fixed;
  left: 0.75rem;
  right: 0.75rem;
  top: 4.25rem;
  z-index: 35;
  max-height: 70vh;
  overflow-y: auto;
  width: auto;
}
.app-popover-panel--narrow { max-width: 18rem; margin-left: auto; }
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

@media (min-width: 640px) {
  .app-popover-panel {
    position: absolute;
    left: auto;
    right: 0;
    top: 100%;
    width: 20rem;
    margin-top: 0.5rem;
    max-height: 24rem;
  }
  .app-popover-panel--narrow { width: 14rem; max-width: 14rem; }
}

@media (max-width: 767px) {
  .page-header {
    flex-direction: column;
    align-items: stretch;
  }
  .page-header h1 { font-size: 1.25rem; }
  .page-header form,
  .page-header .input,
  .page-header select { width: 100%; max-width: 100%; }
  .page-header .input,
  .page-header select { width: 100% !important; }

  .form-toolbar {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
  }
  .form-toolbar > .input,
  .form-toolbar > select,
  .form-toolbar > button,
  .form-toolbar > a,
  .form-toolbar > .btn-primary,
  .form-toolbar > .btn-secondary {
    width: 100% !important;
    max-width: 100%;
  }

  .ui-table:not(.no-stack) thead,
  table.app-stack-table:not(.no-stack) thead { display: none; }

  .ui-table:not(.no-stack),
  .ui-table:not(.no-stack) tbody,
  table.app-stack-table:not(.no-stack),
  table.app-stack-table:not(.no-stack) tbody {
    display: block;
    width: 100%;
  }

  .ui-table:not(.no-stack) tbody tr,
  table.app-stack-table:not(.no-stack) tbody tr {
    display: block;
    padding: 0.85rem 1rem;
    border-top: none;
    border-bottom: 1px solid var(--border);
  }

  .ui-table:not(.no-stack) td,
  table.app-stack-table:not(.no-stack) td {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    padding: 0.28rem 0;
    text-align: right;
    word-break: break-word;
  }

  .ui-table:not(.no-stack) td::before,
  table.app-stack-table:not(.no-stack) td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--muted);
    text-align: left;
    flex: 0 1 42%;
  }

  .ui-table:not(.no-stack) td:not([data-label])::before,
  table.app-stack-table:not(.no-stack) td:not([data-label])::before { content: none; }

  .ui-table:not(.no-stack) td[colspan],
  table.app-stack-table:not(.no-stack) td[colspan] {
    display: block;
    text-align: left;
  }
  .ui-table:not(.no-stack) td[colspan]::before,
  table.app-stack-table:not(.no-stack) td[colspan]::before { content: none; }
}

@keyframes mind-pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.18); opacity: 0.72; }
}
.mind-nav-icon { animation: mind-pulse 2.4s ease-in-out infinite; transform-origin: center; }
html.mind-open .mind-nav-icon { animation-duration: 0.7s; color: #4AA9E9; }
.mind-widget {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 30;
  width: min(22rem, calc(100vw - 1.5rem));
}
.mind-widget-panel {
  height: min(32rem, calc(100vh - 6rem));
  box-shadow: 0 12px 40px rgba(11, 37, 69, 0.18);
}
@media (max-width: 767px) {
  .mind-widget { right: 0.75rem; left: 0.75rem; width: auto; bottom: calc(4.75rem + env(safe-area-inset-bottom)); }
  .mind-widget-panel { height: min(32rem, calc(100vh - 10rem)); }
}

/* Barra inferior do celular: Chamados · Abrir · OS · Menu */
.mobile-tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 35;
  display: flex;
  align-items: stretch;
  justify-content: space-around;
  gap: 0.25rem;
  padding: 0.25rem 0.5rem calc(0.25rem + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, 0.97);
  border-top: 1px solid #e2e8f0;
  box-shadow: 0 -6px 20px rgba(11, 37, 69, 0.08);
  backdrop-filter: blur(8px);
}
.dark .mobile-tabbar { background: rgba(15, 23, 42, 0.97); border-top-color: #1e293b; }
.mobile-tab {
  flex: 1 1 0;
  min-height: 3.25rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  border-radius: 0.75rem;
  font-size: 0.7rem;
  font-weight: 600;
  color: #64748b;
  -webkit-tap-highlight-color: transparent;
}
.mobile-tab.active { color: var(--fc-primary, #2563eb); background: rgba(37, 99, 235, 0.08); }
.dark .mobile-tab { color: #94a3b8; }
.dark .mobile-tab.active { color: #93c5fd; background: rgba(59, 130, 246, 0.15); }
.mobile-tab__fab {
  width: 2.75rem;
  height: 2.75rem;
  margin-top: -1.1rem;
  border-radius: 9999px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  background: var(--fc-primary, #2563eb);
  box-shadow: 0 6px 16px rgba(37, 99, 235, 0.35);
}
.mobile-tab--primary.active { background: transparent; }
@media (max-width: 767px) {
  .has-mobile-tabbar { padding-bottom: calc(5.5rem + env(safe-area-inset-bottom)) !important; }
}

/* Chips de filtro com rolagem horizontal */
.chip-row { display: flex; gap: 0.5rem; overflow-x: auto; padding-bottom: 0.25rem; scrollbar-width: none; }
.chip-row::-webkit-scrollbar { display: none; }
.chip {
  flex-shrink: 0;
  padding: 0.45rem 0.9rem;
  border-radius: 9999px;
  border: 1px solid #e2e8f0;
  font-size: 0.8rem;
  font-weight: 600;
  color: #475569;
  background: #fff;
  white-space: nowrap;
}
.chip.active { color: #fff; background: var(--fc-primary, #2563eb); border-color: transparent; }
.dark .chip { background: #0f172a; border-color: #334155; color: #cbd5e1; }
.dark .chip.active { color: #fff; background: var(--fc-primary, #2563eb); }

/* Seletor de fotos: câmera e galeria no toque; um único "Escolher fotos" com mouse */
.photo-picker__desktop { display: none; }
@media (hover: hover) and (pointer: fine) {
  .photo-picker__camera, .photo-picker__touch { display: none !important; }
  .photo-picker__desktop { display: inline; }
  .photo-picker__buttons { grid-template-columns: minmax(0, 1fr); }
}
