/* ── Design Tokens ─────────────────────────────────────────────── */
:root {
  /* Colors – Light */
  --bg:          #f4f5f7;
  --surface:     #ffffff;
  --surface-2:   #f9fafb;
  --border:      #e5e7eb;
  --border-2:    #d1d5db;
  --text:        #111827;
  --text-2:      #6b7280;
  --text-3:      #9ca3af;

  /* Accent */
  --accent:      #4f46e5;
  --accent-h:    #4338ca;
  --accent-bg:   #eef2ff;
  --accent-text: #4338ca;

  /* Status */
  --green:       #16a34a;
  --green-bg:    #dcfce7;
  --red:         #dc2626;
  --red-bg:      #fee2e2;
  --yellow:      #d97706;
  --yellow-bg:   #fef3c7;
  --blue:        #2563eb;
  --blue-bg:     #dbeafe;

  /* Sidebar */
  --sb-bg:       #1e1e2e;
  --sb-text:     #a1a1b5;
  --sb-text-h:   #ffffff;
  --sb-active:   #4f46e5;
  --sb-active-bg:#2d2b55;
  --sb-border:   rgba(255,255,255,0.06);
  --sb-width:    240px;
  --sb-width-col:60px;

  /* Layout */
  --topbar-h:    58px;
  --radius-sm:   6px;
  --radius:      8px;
  --radius-lg:   12px;
  --radius-xl:   16px;

  /* Shadows */
  --shadow-sm:   0 1px 2px rgba(0,0,0,.05);
  --shadow:      0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md:   0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
  --shadow-lg:   0 10px 15px rgba(0,0,0,.1), 0 4px 6px rgba(0,0,0,.05);

  /* Typography */
  --font:        'Inter', system-ui, -apple-system, sans-serif;
  --font-mono:   'JetBrains Mono', 'Fira Code', monospace;

  /* Transitions */
  --t:           150ms ease;
  --t-slow:      250ms ease;
}

[data-theme="dark"] {
  --bg:          #0f0f14;
  --surface:     #1a1a27;
  --surface-2:   #22223a;
  --border:      #2a2a3e;
  --border-2:    #3a3a52;
  --text:        #e4e4f0;
  --text-2:      #8888a8;
  --text-3:      #55556a;
  --accent-bg:   #2d2b55;
  --sb-bg:       #12121e;
  --sb-border:   rgba(255,255,255,0.04);
}

/* ── Reset ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; -webkit-font-smoothing: antialiased; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}
a { color: var(--accent); text-decoration: none; }
button { font-family: var(--font); cursor: pointer; border: none; background: none; }
input, select, textarea { font-family: var(--font); font-size: 14px; }
img { max-width: 100%; display: block; }
ul, ol { list-style: none; }

/* ── Scrollbar ─────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-3); }

/* ── Typography ────────────────────────────────────────────────── */
h1 { font-size: 1.5rem;  font-weight: 700; letter-spacing: -.02em; }
h2 { font-size: 1.25rem; font-weight: 600; letter-spacing: -.01em; }
h3 { font-size: 1rem;    font-weight: 600; }
h4 { font-size: .875rem; font-weight: 600; }
p  { color: var(--text-2); font-size: .875rem; }

.text-sm   { font-size: .8125rem; }
.text-xs   { font-size: .75rem; }
.text-muted { color: var(--text-2); }
.text-success { color: var(--green); }
.text-danger  { color: var(--red); }
.text-warning { color: var(--yellow); }
.font-mono { font-family: var(--font-mono); }
.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }

/* ── Utilities ─────────────────────────────────────────────────── */
.flex       { display: flex; }
.flex-col   { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1  { gap: .25rem; }
.gap-2  { gap: .5rem; }
.gap-3  { gap: .75rem; }
.gap-4  { gap: 1rem; }
.gap-6  { gap: 1.5rem; }
.w-full { width: 100%; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }

/* ── Grid ──────────────────────────────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; }

@media (max-width: 900px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 600px) {
  .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; }

  /* Dashboard mobile — colapsa grids inline dos gráficos */
  #page-content [style*="grid-template-columns:2fr 1fr"],
  #page-content [style*="grid-template-columns: 2fr 1fr"],
  #page-content [style*="grid-template-columns:1fr 1fr"],
  #page-content [style*="grid-template-columns: 1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }

  /* Reduz altura dos gráficos em mobile */
  #page-content canvas {
    max-height: 160px;
  }
  #page-content [style*="height:230px"],
  #page-content [style*="height: 230px"],
  #page-content [style*="height:200px"],
  #page-content [style*="height: 200px"] {
    height: 160px !important;
  }

  /* Oculta colunas menos relevantes em mobile */
  .dash-section-label { margin-top: .75rem; }

  /* Topbar: esconde relógio e busca em mobile para ganhar espaço */
  .topbar-search-wrap { display: none; }
  #relogio { display: none !important; }
  #topbar-empresa-cidade { display: none; }
}

/* ── Login Screen ──────────────────────────────────────────────── */
#login-screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
  z-index: 1000;
}

.login-card {
  width: 100%;
  max-width: 380px;
  padding: 2.5rem 2rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
}

.login-logo {
  text-align: center;
  margin-bottom: 2rem;
}
.login-logo .logo-mark {
  width: 48px; height: 48px;
  background: var(--accent);
  border-radius: var(--radius-lg);
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 1rem;
  font-size: 1.5rem;
}
.login-logo h1 { font-size: 1.25rem; color: var(--text); }
.login-logo p  { font-size: .8125rem; color: var(--text-2); margin-top: .25rem; }

.login-form .form-group { margin-bottom: 1rem; }
.error-msg { color: var(--red); font-size: .8125rem; margin-top: .75rem; text-align: center; }

/* ── Portal de Empresas ────────────────────────────────────────── */
#empresa-portal {
  position: fixed; inset: 0; z-index: 900;
  display: flex; flex-direction: column;
  overflow-y: auto;
}
.portal-bg {
  min-height: 100vh;
  background: var(--bg);
  display: flex; flex-direction: column;
}

.portal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 2rem; background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10; gap: 1rem;
}
.portal-header-left  { display: flex; align-items: center; gap: .875rem; }
.portal-header-right { display: flex; align-items: center; gap: .75rem; }
.portal-logo-img { height: 36px; width: auto; object-fit: contain; }
.portal-header-title { font-size: .9375rem; font-weight: 700; color: var(--text); }
.portal-header-sub   { font-size: .75rem; color: var(--text-2); margin-top: .1rem; }
.portal-clock { font-size: .8125rem; color: var(--text-2); }
.portal-theme-btn { color: var(--text-2); }
.portal-logout-btn { font-size: .8125rem; gap: .375rem; }

.portal-body {
  flex: 1; padding: 2.5rem 2rem;
  max-width: 1200px; width: 100%; margin: 0 auto;
}
.portal-intro { margin-bottom: 2rem; }
.portal-intro h1 { font-size: 1.5rem; color: var(--text); }
.portal-intro p  { color: var(--text-2); margin-top: .375rem; }

.portal-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1.25rem;
}
.portal-loading {
  grid-column: 1 / -1;
  display: flex; align-items: center; justify-content: center;
  gap: 1rem; padding: 3rem;
  color: var(--text-2); font-size: .875rem;
}

/* Card de empresa */
.empresa-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-xl); overflow: hidden;
  transition: transform var(--t-slow), box-shadow var(--t-slow), border-color var(--t);
  cursor: pointer;
}
.empresa-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
  border-color: var(--accent);
}
.empresa-card-header {
  padding: 1.5rem 1.5rem 1rem;
  display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem;
}
.empresa-card-logo {
  width: 52px; height: 52px; border-radius: var(--radius-lg);
  background: var(--accent-bg); display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; overflow: hidden;
}
.empresa-card-logo img { width: 100%; height: 100%; object-fit: contain; padding: 4px; }
.empresa-card-logo-letter {
  font-size: 1.375rem; font-weight: 800; color: var(--accent); letter-spacing: -.04em;
}
.empresa-card-status {
  display: flex; align-items: center; gap: .3rem;
  font-size: .7rem; font-weight: 600; padding: .2rem .5rem;
  border-radius: 999px;
}
.empresa-card-status.ativo   { background: var(--green-bg); color: var(--green); }
.empresa-card-status.inativo { background: var(--red-bg); color: var(--red); }

.empresa-card-body { padding: 0 1.5rem 1rem; }
.empresa-card-nome { font-size: 1rem; font-weight: 700; color: var(--text); margin-bottom: .375rem; }
.empresa-card-cidades {
  display: flex; flex-wrap: wrap; gap: .3rem; margin-bottom: 1rem;
}
.empresa-card-cidade-tag {
  font-size: .7rem; padding: .15rem .45rem;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 999px; color: var(--text-2); font-weight: 500;
}

.empresa-card-stats {
  display: grid; grid-template-columns: 1fr 1fr 1fr;
  gap: .5rem; margin-bottom: 1rem;
}
.empresa-card-stat {
  text-align: center; padding: .5rem .25rem;
  background: var(--surface-2); border-radius: var(--radius);
}
.empresa-card-stat-val { font-size: 1rem; font-weight: 700; color: var(--text); display: block; }
.empresa-card-stat-lbl { font-size: .65rem; color: var(--text-2); display: block; margin-top: .1rem; }
.empresa-card-stat-lbl.alert { color: var(--yellow); }

.empresa-card-footer { padding: .875rem 1.5rem; border-top: 1px solid var(--border); }
.btn-acessar-empresa {
  width: 100%; background: var(--accent); color: #fff;
  border: none; border-radius: var(--radius); padding: .625rem 1rem;
  font-size: .875rem; font-weight: 600; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: .5rem;
  transition: background var(--t), transform var(--t);
}
.btn-acessar-empresa:hover { background: var(--accent-h); transform: scale(1.02); }

/* Pending actions banner */
.actions-banner {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 1rem 1.25rem;
  margin-bottom: 1.5rem;
  display: flex; flex-wrap: wrap; align-items: center; gap: .75rem;
}
.actions-banner-title {
  font-size: .8125rem; font-weight: 700; color: var(--text);
  white-space: nowrap; margin-right: .25rem;
}
.action-pill {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .275rem .625rem; border-radius: 999px;
  font-size: .75rem; font-weight: 600; cursor: pointer;
  transition: opacity var(--t), transform var(--t);
  text-decoration: none;
}
.action-pill:hover { opacity: .85; transform: scale(1.04); }
.action-pill.red    { background: var(--red-bg);    color: var(--red); }
.action-pill.yellow { background: var(--yellow-bg); color: var(--yellow); }
.action-pill.blue   { background: var(--blue-bg);   color: var(--blue); }
.action-pill.green  { background: var(--green-bg);  color: var(--green); }

/* Notification dropdown items */
.notif-item {
  display: flex; gap: .75rem; align-items: flex-start;
  padding: .875rem 1rem; border-bottom: 1px solid var(--border);
  transition: background var(--t); cursor: pointer;
}
.notif-item:hover { background: var(--surface-2); }
.notif-item:last-child { border-bottom: none; }
.notif-icon {
  width: 34px; height: 34px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; font-size: .9rem;
}
.notif-icon.red    { background: var(--red-bg);    color: var(--red); }
.notif-icon.yellow { background: var(--yellow-bg); color: var(--yellow); }
.notif-icon.blue   { background: var(--blue-bg);   color: var(--blue); }
.notif-title { font-size: .8125rem; font-weight: 600; color: var(--text); }
.notif-sub   { font-size: .75rem; color: var(--text-2); margin-top: .1rem; }
.notif-header {
  padding: .875rem 1rem; font-size: .8rem; font-weight: 700; color: var(--text);
  border-bottom: 1px solid var(--border); display: flex; justify-content: space-between;
}
.notif-empty { padding: 1.5rem; text-align: center; color: var(--text-2); font-size: .8125rem; }

/* .desktop-only / .mobile-only supplement */
.desktop-only { display: flex; }
@media (max-width: 768px) {
  .desktop-only { display: none !important; }
  .portal-body { padding: 1.25rem 1rem; }
  .portal-header { padding: .75rem 1rem; }
  .portal-grid { grid-template-columns: 1fr; }
  .topbar-search input { width: 120px; }
}
