/* ═══════════════════════════════════════════════════════
   DomosAI — app.css
   Tokens extraídos dos arquivos reais da identidade visual
   PHP 8.3 · PWA · Mobile-first · Dark mode nativo
   ═══════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

/* ── 1. DESIGN TOKENS ─────────────────────────────────── */
:root {
  /* Marca — medido pixel a pixel nos arquivos reais */
  --clr-primary:        #0060C8;
  --clr-primary-hover:  #004FA8;
  --clr-primary-mid:    #0090F0;
  --clr-primary-light:  #00A8F0;
  --clr-accent:         #00E0F0;
  --clr-accent-light:   #00E8F8;

  /* Gradiente oficial do símbolo (diagonal 135°) */
  --gradient-brand: linear-gradient(
    135deg,
    #0060C8 0%,
    #0090F0 30%,
    #00A8F0 55%,
    #00E0F0 80%,
    #00E8F8 100%
  );

  /* Fundos — modo claro */
  --clr-bg:          #EFF3F8;
  --clr-surface:     #FFFFFF;
  --clr-surface-2:   #E4EBF3;
  --clr-border:      #C8D8E8;
  --clr-border-soft: #DDE8F2;

  /* Texto — modo claro */
  --clr-text:        #0D1B2A;
  --clr-text-muted:  #4A6080;
  --clr-text-hint:   #7A96B0;
  --clr-text-inv:    #FFFFFF;

  /* Fundos escuros (usados no sidebar dark e modo dark) */
  --clr-dark:        #09192E;
  --clr-dark-card:   #0D2137;
  --clr-dark-2:      #122840;
  --clr-dark-border: #1A3550;

  /* Estados de dispositivo */
  --clr-device-on:    #00A8F0;
  --clr-device-off:   #8AAABB;
  --clr-device-error: #E53935;

  /* Semânticas */
  --clr-success:      #00C853;
  --clr-success-bg:   #E8FAF0;
  --clr-warning:      #FFB300;
  --clr-warning-bg:   #FFF8E1;
  --clr-danger:       #E53935;
  --clr-danger-bg:    #FFEBEE;
  --clr-info:         #0060C8;
  --clr-info-bg:      #E8F0FB;

  /* Status do tenant */
  --clr-status-ativo:     #00C853;
  --clr-status-suspenso:  #FFB300;
  --clr-status-inativo:   #8AAABB;
  --clr-status-excluido:  #E53935;

  /* Layout */
  --sidebar-width:    220px;
  --sidebar-collapsed: 64px;
  --header-height:    60px;
  --nav-bottom:       64px;
  --content-max:      1280px;

  /* Espaçamento */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-8: 32px;
  --sp-10: 40px;

  /* Bordas */
  --radius-sm:  6px;
  --radius-md:  10px;
  --radius-lg:  16px;
  --radius-xl:  24px;
  --radius-full: 9999px;

  /* Sombras */
  --shadow-sm:  0 1px 3px rgba(0,96,200,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md:  0 4px 12px rgba(0,96,200,.10), 0 2px 4px rgba(0,0,0,.06);
  --shadow-lg:  0 8px 24px rgba(0,96,200,.12), 0 4px 8px rgba(0,0,0,.08);

  /* Transições */
  --transition: 150ms ease;
  --transition-md: 250ms ease;

  /* Tipografia */
  --font-main: 'Inter', 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Courier New', monospace;

  /* PWA */
  --pwa-theme: #0060C8;
  --pwa-bg:    #09192E;
}

/* Modo escuro automático (sistema) */
@media (prefers-color-scheme: dark) {
  :root {
    --clr-bg:          #09192E;
    --clr-surface:     #0D2137;
    --clr-surface-2:   #122840;
    --clr-border:      #1A3550;
    --clr-border-soft: #152A45;
    --clr-text:        #E8F0FE;
    --clr-text-muted:  #7B9AB0;
    --clr-text-hint:   #4A6880;
    --shadow-sm: 0 1px 3px rgba(0,0,0,.3);
    --shadow-md: 0 4px 12px rgba(0,0,0,.4);
    --shadow-lg: 0 8px 24px rgba(0,0,0,.5);
  }
}

/* Modo escuro manual (toggle pelo usuário) */
[data-theme="dark"] {
  --clr-bg:          #09192E;
  --clr-surface:     #0D2137;
  --clr-surface-2:   #122840;
  --clr-border:      #1A3550;
  --clr-border-soft: #152A45;
  --clr-text:        #E8F0FE;
  --clr-text-muted:  #7B9AB0;
  --clr-text-hint:   #4A6880;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,.4);
  --shadow-lg: 0 8px 24px rgba(0,0,0,.5);
}

/* ── 2. RESET ──────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-main);
  font-size: 0.9375rem; /* 15px */
  line-height: 1.6;
  color: var(--clr-text);
  background-color: var(--clr-bg);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

img, video, svg { display: block; max-width: 100%; }
a { color: var(--clr-primary); text-decoration: none; }
a:hover { color: var(--clr-primary-hover); }
button, input, select, textarea { font: inherit; }
ul, ol { list-style: none; }
h1, h2, h3, h4, h5, h6 { font-weight: 600; line-height: 1.3; color: var(--clr-text); }

/* ── 3. LAYOUT PRINCIPAL ───────────────────────────────── */

/* Wrapper raiz */
.app-layout {
  display: flex;
  min-height: 100vh;
}

/* ── SIDEBAR ── */
.sidebar {
  width: var(--sidebar-width);
  background: var(--clr-dark);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  z-index: 100;
  transition: transform var(--transition-md), width var(--transition-md);
  overflow: hidden;
}

.sidebar-logo {
  height: var(--header-height);
  display: flex;
  align-items: center;
  padding: 0 var(--sp-5);
  border-bottom: 1px solid var(--clr-dark-border);
  flex-shrink: 0;
}

.sidebar-logo img {
  height: 32px;
  width: auto;
}

.sidebar-logo .logo-text {
  font-size: 1rem;
  font-weight: 700;
  color: #FFFFFF;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.sidebar-logo .logo-text span {
  color: var(--clr-accent);
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: var(--sp-4) 0;
  scrollbar-width: thin;
  scrollbar-color: var(--clr-dark-border) transparent;
}

.nav-section-label {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--clr-text-hint);
  padding: var(--sp-4) var(--sp-5) var(--sp-2);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-5);
  color: rgba(255,255,255,.6);
  font-size: 0.875rem;
  font-weight: 500;
  transition: background var(--transition), color var(--transition);
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  text-decoration: none;
  border-radius: 0;
  position: relative;
}

.nav-item:hover {
  background: rgba(255,255,255,.06);
  color: rgba(255,255,255,.9);
}

.nav-item.active {
  background: rgba(0,168,240,.15);
  color: var(--clr-accent);
}

.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--gradient-brand);
  border-radius: 0 2px 2px 0;
}

.nav-item .nav-icon {
  font-size: 1.125rem;
  flex-shrink: 0;
  width: 20px;
  text-align: center;
}

.sidebar-footer {
  padding: var(--sp-4) var(--sp-5);
  border-top: 1px solid var(--clr-dark-border);
  flex-shrink: 0;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--gradient-brand);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8125rem;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.user-info {
  flex: 1;
  overflow: hidden;
}

.user-name {
  font-size: 0.8125rem;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-role {
  font-size: 0.6875rem;
  color: var(--clr-text-hint);
}

/* ── ÁREA PRINCIPAL ── */
.main-wrapper {
  flex: 1;
  margin-left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  transition: margin-left var(--transition-md);
}

/* ── HEADER TOPO ── */
.topbar {
  height: var(--header-height);
  background: var(--clr-surface);
  border-bottom: 1px solid var(--clr-border);
  display: flex;
  align-items: center;
  padding: 0 var(--sp-6);
  gap: var(--sp-4);
  position: sticky;
  top: 0;
  z-index: 90;
  box-shadow: var(--shadow-sm);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  flex: 1;
}

.btn-menu-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--clr-text-muted);
  font-size: 1.25rem;
  padding: var(--sp-2);
  border-radius: var(--radius-sm);
  transition: background var(--transition), color var(--transition);
}

.btn-menu-toggle:hover {
  background: var(--clr-surface-2);
  color: var(--clr-text);
}

.page-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--clr-text);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}

/* ── CONTEÚDO ── */
.page-content {
  flex: 1;
  padding: var(--sp-6);
  max-width: var(--content-max);
  width: 100%;
}

/* ── GRID DE CONTEÚDO ── */
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--sp-5); }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--sp-5); }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--sp-5); }
.grid-auto { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: var(--sp-5); }

/* ── 4. TIPOGRAFIA ─────────────────────────────────────── */
.text-xs    { font-size: 0.75rem; }
.text-sm    { font-size: 0.8125rem; }
.text-base  { font-size: 0.9375rem; }
.text-lg    { font-size: 1.0625rem; }
.text-xl    { font-size: 1.25rem; }
.text-2xl   { font-size: 1.5rem; }
.text-3xl   { font-size: 1.875rem; }

.font-normal  { font-weight: 400; }
.font-medium  { font-weight: 500; }
.font-semibold { font-weight: 600; }
.font-bold    { font-weight: 700; }

.text-primary  { color: var(--clr-text); }
.text-muted    { color: var(--clr-text-muted); }
.text-hint     { color: var(--clr-text-hint); }
.text-brand    { color: var(--clr-primary); }
.text-accent   { color: var(--clr-accent); }
.text-success  { color: var(--clr-success); }
.text-warning  { color: var(--clr-warning); }
.text-danger   { color: var(--clr-danger); }
.text-white    { color: #fff; }

/* ── 5. UTILITÁRIOS ────────────────────────────────────── */
.flex         { display: flex; }
.flex-col     { flex-direction: column; }
.items-center { align-items: center; }
.items-start  { align-items: flex-start; }
.justify-between { justify-content: space-between; }
.justify-center  { justify-content: center; }
.gap-1  { gap: var(--sp-1); }
.gap-2  { gap: var(--sp-2); }
.gap-3  { gap: var(--sp-3); }
.gap-4  { gap: var(--sp-4); }
.gap-5  { gap: var(--sp-5); }
.gap-6  { gap: var(--sp-6); }

.mt-4  { margin-top: var(--sp-4); }
.mt-6  { margin-top: var(--sp-6); }
.mb-4  { margin-bottom: var(--sp-4); }
.mb-6  { margin-bottom: var(--sp-6); }

.w-full   { width: 100%; }
.h-full   { height: 100%; }
.flex-1   { flex: 1; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); border: 0;
}

/* ── 6. OVERLAY MOBILE ─────────────────────────────────── */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 99;
  opacity: 0;
  transition: opacity var(--transition-md);
}

.sidebar-overlay.active {
  opacity: 1;
}

/* ── 7. BREAKPOINTS ────────────────────────────────────── */

/* Tablet (≤1024px) — sidebar recolhe */
@media (max-width: 1024px) {
  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-overlay {
    display: block;
  }

  .main-wrapper {
    margin-left: 0;
  }

  .btn-menu-toggle {
    display: flex;
  }

  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
}

/* Mobile (≤640px) — nav inferior */
@media (max-width: 640px) {
  .page-content {
    padding: var(--sp-4);
    padding-bottom: calc(var(--nav-bottom) + var(--sp-4));
  }

  .grid-2,
  .grid-3,
  .grid-4 {
    grid-template-columns: 1fr;
  }

  .topbar {
    padding: 0 var(--sp-4);
  }

  .topbar-right .btn-icon-label {
    display: none;
  }
}

/* ── 8. SCROLLBAR CUSTOMIZADA ──────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--clr-border);
  border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover { background: var(--clr-text-hint); }

/* ── 9. SELEÇÃO DE TEXTO ───────────────────────────────── */
::selection {
  background: rgba(0,96,200,.2);
  color: var(--clr-text);
}

/* ── 10. ANIMAÇÕES ─────────────────────────────────────── */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes slideIn {
  from { transform: translateX(-8px); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: .5; }
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

.animate-fade  { animation: fadeIn var(--transition-md) ease both; }
.animate-slide { animation: slideIn var(--transition-md) ease both; }
.animate-pulse { animation: pulse 2s ease infinite; }
.animate-spin  { animation: spin 1s linear infinite; }

/* Reduz movimento se o usuário preferir */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
