/* css/layout.css */

/* ══════════════════════════════════════════════════════
   ESTRUTURA GERAL
   
   Modelo correto:
   - #appScreen ocupa 100vh
   - .sidebar  → position: fixed, left:0, top:0, height:100vh
   - .topbar   → position: fixed, top:0, left:240px, right:0
   - .content  → margin-left:240px, margin-top:56px, overflow-y:auto
   
   Assim o topbar SEMPRE ocupa a largura total menos a sidebar,
   sem depender de flex pai. E nunca corta.
══════════════════════════════════════════════════════ */

/* ── Reset global ──────────────────────────────────── */
#appScreen { display: none; }
.app       { display: block; height: 100vh; overflow: hidden; }

/* ══════════════════════════════════════════════════════
   SIDEBAR — fixed, sempre visível no desktop
══════════════════════════════════════════════════════ */
.sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: 240px;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 300;
  transition: transform .25s cubic-bezier(.4,0,.2,1);
}

/* Logo */
.logo {
  padding: 1px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  min-height: 60px;
  overflow: hidden;
}
/* Logo banner (imagem horizontal) na sidebar expandida */
.logo-banner-img {
  height: 55px;
  object-fit: contain;
  object-position: left center;
  flex-shrink: 0;
  transition: opacity 0.2s;
}
/* Sidebar collapsed: esconder banner, mostrar apenas favicon via background */
.sidebar.collapsed .logo-banner-img {
  opacity: 0;
  width: 0;
  pointer-events: none;
}
.logo-icon-img {
  width: 32px; height: 32px;
  object-fit: contain;
  border-radius: 8px;
  flex-shrink: 0;
}
.logo-text {
  font-family: 'Syne', sans-serif;
  font-size: 12px;
  font-weight: 800;
  color: var(--text);
  line-height: 1.1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: clip;
}
.logo-text span { color: var(--accent2); }

/* Nav */
.nav-section { padding: 12px 8px 4px; flex-shrink: 0; }
.nav-label {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px; font-weight: 500;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: 0 10px;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
  transition: background .12s, color .12s;
  color: var(--text2);
  font-size: 13.5px;
  font-weight: 400;
  margin-bottom: 1px;
  position: relative;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100%;
}
.nav-item:hover { background: var(--bg3); color: var(--text); }
.nav-item.active {
  background: var(--accent-dim);
  color: var(--accent2);
  font-weight: 500;
}
.nav-item.active::before {
  content: '';
  position: absolute; left: 0; top: 50%;
  transform: translateY(-50%);
  width: 3px; height: 18px;
  background: var(--accent);
  border-radius: 0 3px 3px 0;
}
.nav-icon { font-size: 14px; width: 18px; text-align: center; flex-shrink: 0; }

/* Badge */
.badge {
  margin-left: auto;
  background: var(--accent); color: #fff;
  font-size: 10px; font-weight: 600;
  padding: 2px 6px; border-radius: 20px;
  font-family: 'JetBrains Mono', monospace;
  flex-shrink: 0;
  line-height: 1.4;
}
.badge:empty { display: none; }
.badge.green  { background: var(--green); }
.badge.yellow { background: var(--yellow); color: #000; }
.badge.red    { background: var(--red); }

/* Footer */
.sidebar-footer {
  margin-top: auto;
  padding: 12px 8px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.user-chip {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 10px;
  background: var(--bg3);
  border-radius: 8px;
  overflow: hidden;
}
.avatar {
  width: 28px; height: 28px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 700; color: #fff;
  flex-shrink: 0;
}
.user-info { flex: 1; min-width: 0; overflow: hidden; }
.user-name {
  font-size: 12px; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  color: var(--text);
}
.user-role { font-size: 10px; color: var(--text3); }
.logout-btn {
  background: none; border: none;
  color: var(--text3); cursor: pointer;
  font-size: 13px; padding: 4px;
  transition: color .1s; flex-shrink: 0;
}
.logout-btn:hover { color: var(--red); }

/* ══════════════════════════════════════════════════════
   OVERLAY — mobile
══════════════════════════════════════════════════════ */
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.55);
  z-index: 299;
  backdrop-filter: blur(2px);
}
.sidebar-overlay.show { display: block; }

/* ══════════════════════════════════════════════════════
   TOPBAR — fixed, sempre ocupa da sidebar até a borda
══════════════════════════════════════════════════════ */
.main { display: contents; }  /* não participa do layout */

.topbar {
  position: fixed;
  top: 0;
  left: 240px;   /* começa depois da sidebar */
  right: 0;
  height: 56px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 12px;
  z-index: 200;
}

/* Hamburger — oculto no desktop */
.menu-btn {
  display: none;
  background: none; border: none;
  color: var(--text2); font-size: 20px;
  cursor: pointer; padding: 4px 6px;
  border-radius: 6px; line-height: 1;
  flex-shrink: 0;
}
.menu-btn:hover { color: var(--text); background: var(--bg3); }

.page-title {
  font-family: 'Syne', sans-serif;
  font-size: 16px; font-weight: 700; color: #fff;
  flex: 1; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.search-bar {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 12px;
  width: 220px; flex-shrink: 0;
  transition: border-color .2s;
}
.search-bar:focus-within { border-color: var(--accent); }
.search-bar input {
  background: none; border: none; outline: none;
  color: var(--text); font-size: 13px;
  font-family: 'Outfit', sans-serif;
  width: 100%; min-width: 0;
}
.search-bar input::placeholder { color: var(--text3); }
.topbar-btn-new { flex-shrink: 0; }

/* ══════════════════════════════════════════════════════
   CONTENT — margem para não ficar sob o topbar/sidebar
══════════════════════════════════════════════════════ */
.content {
  position: fixed;
  top: 56px;       /* altura do topbar */
  left: 240px;     /* largura da sidebar */
  right: 0;
  bottom: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 20px;
  background: var(--bg);
}

/* ── Pages ── */
.page { display: none; }
.page.active { display: block; animation: fadeIn .2s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

/* ══════════════════════════════════════════════════════
   RESPONSIVE
══════════════════════════════════════════════════════ */

/* Medium (< 1100px) */
@media (max-width: 1100px) {
  .stats-grid        { grid-template-columns: repeat(2, 1fr); }
  .attendant-grid    { grid-template-columns: repeat(2, 1fr); }
  .inv-grid          { grid-template-columns: repeat(2, 1fr); }
  .companies-grid    { grid-template-columns: repeat(2, 1fr); }
  .kb-grid           { grid-template-columns: repeat(2, 1fr); }
  .search-bar        { width: 170px; }
}

/* Tablet / Mobile (< 900px) — sidebar vira gaveta */
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .topbar  { left: 0; }
  .content { left: 0; }
  .menu-btn { display: flex; }
  .two-col       { grid-template-columns: 1fr; }
  .stats-grid    { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .content       { padding: 14px; }
  .search-bar    { width: 150px; }

  /* Grids: 2 colunas em tablet */
  .inv-grid,
  .companies-grid,
  .attendant-grid,
  .kb-grid        { grid-template-columns: repeat(2, 1fr) !important; gap: 10px; }
}



/* Mobile (< 640px) */
@media (max-width: 640px) {
  .stats-grid     { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .stat-value     { font-size: 22px; }

  /* Grids: 1 coluna no celular */
  .attendant-grid,
  .companies-grid,
  .kb-grid        { grid-template-columns: 1fr; }

  /* Inventário: 1 coluna no celular */
  .inv-grid       { grid-template-columns: 1fr !important; }

  /* Topbar */
  .topbar         { padding: 0 12px; gap: 6px; }
  .search-bar     { display: none; }
  .page-title     { font-size: 13px; }
  .content        { padding: 10px; }

  /* Tabelas com scroll horizontal */
  .table-wrap     { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .table          { min-width: 520px; }

  /* Modais aparecem na parte inferior */
  .modal {
    width: 100% !important;
    max-width: 100% !important;
    max-height: 92vh !important;
    border-radius: 16px 16px 0 0 !important;
    overflow-y: auto;
  }
  .modal-overlay { align-items: flex-end; padding: 0; }

  /* Formulários em coluna única */
  .form-row       { grid-template-columns: 1fr; }
  .perm-grid      { grid-template-columns: 1fr; }
  .company-stats  { grid-template-columns: repeat(2, 1fr); }
  .spec-grid      { grid-template-columns: 1fr; }

  /* Filtros menores */
  .filter-bar     { flex-wrap: wrap; gap: 5px; }
  .filter-chip    { font-size: 11px; padding: 4px 9px; }

  /* Botão Novo Ticket — mostrar texto "+" em vez de sumir */
  .topbar-btn-text  { display: none; }
  .topbar-btn-icon  { display: inline !important; font-size: 18px; }
  .topbar-btn-new   { padding: 7px 12px; min-width: 36px; }

  /* Grid de 2 colunas no agente some para 1 */
  #agentContent > div[style*="grid-template-columns:1fr 1fr"],
  #agentContent > div[style*="grid-template-columns: 1fr 1fr"] {
    display: flex !important;
    flex-direction: column !important;
  }
}

/* Very small (< 400px) */
@media (max-width: 400px) {
  .stat-card  { padding: 12px; }
  .stat-value { font-size: 20px; }
}

/* ── Topbar actions group ────────────────────────────────────────────────── */
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* ── Live indicator ──────────────────────────────────────────────────────── */
.live-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 20px;
  background: rgba(34,197,94,.08);
  border: 1px solid rgba(34,197,94,.2);
  cursor: default;
  transition: all .3s;
}
.live-indicator.offline {
  background: rgba(239,68,68,.07);
  border-color: rgba(239,68,68,.2);
}
.live-indicator.syncing {
  background: rgba(59,130,246,.08);
  border-color: rgba(59,130,246,.2);
}
.live-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--green);
  animation: livePulse 2s ease-in-out infinite;
  flex-shrink: 0;
}
.live-indicator.offline  .live-dot { background: var(--red);    animation: none; }
.live-indicator.syncing  .live-dot { background: var(--accent); animation: liveSpin .8s linear infinite; }
.live-label {
  font-size: 11px;
  font-family: 'JetBrains Mono', monospace;
  color: var(--green);
  font-weight: 600;
  white-space: nowrap;
}
.live-indicator.offline .live-label { color: var(--red); }
.live-indicator.syncing .live-label { color: var(--accent); }

@keyframes livePulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: .5; transform: scale(.85); }
}
@keyframes liveSpin {
  0%   { box-shadow:  2px 0 0 0 var(--accent); }
  25%  { box-shadow:  0  2px 0 0 var(--accent); }
  50%  { box-shadow: -2px 0 0 0 var(--accent); }
  75%  { box-shadow:  0 -2px 0 0 var(--accent); }
  100% { box-shadow:  2px 0 0 0 var(--accent); }
}

@media (max-width: 900px) { .live-label { display: none; } .live-indicator { padding: 4px 7px; } }

.topbar-link-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  font-size: 12px;
  text-decoration: none;
  white-space: nowrap;
}
.topbar-link-icon { font-size: 14px; }

/* Esconder texto dos botões em telas pequenas */
@media (max-width: 900px) {
  .topbar-link-text { display: none; }
  .topbar-link-btn  { padding: 6px 10px; }
}
@media (max-width: 640px) {
  .topbar-btn-text  { display: none; }
  .topbar-btn-icon  { font-size: 16px; }
  .topbar-btn-new   { padding: 7px 10px; }
}

/* Texto curto do botão Novo Ticket para mobile */
.topbar-btn-text-sm { display: none; }
@media (max-width: 640px) {
  .topbar-btn-text    { display: none; }
  .topbar-btn-text-sm { display: inline; font-size: 12px; }
  .topbar-btn-icon    { font-size: 14px; }
  .topbar-btn-new     { padding: 7px 10px; gap: 3px; display: inline-flex; align-items: center; }
}

/* Light mode — layout */
body.light .main               { background: var(--bg); }
body.light .content            { background: var(--bg); }
body.light .topbar             { background: #fff; border-bottom: 1px solid var(--border); }
