/* =============================================================
   base.css — Tokens, reset, layout shell, navbar, sidebar
   ============================================================= */

:root {
  --bg:             #f6faff;
  --surface:        #ffffff;
  --surface-tonal:  #f0f5fc;
  --surface-hover:  #e8f0fb;

  --primary:        #002555;
  --primary-hv:     #001d44;
  --accent:         #4A90E2;
  --accent-hv:      #3a7cd5;
  --accent-glow:    rgba(74,144,226,.18);

  --danger:         #dc2626;
  --danger-bg:      #fff1f1;
  --success:        #16a34a;
  --warning:        #d97706;

  --text:           #0d1b2e;
  --text-muted:     #6b7fa3;
  --text-faint:     #a0b0cb;

  --nav-h:          60px;
  --sidebar-w:      230px;

  --radius-sm:      8px;
  --radius-md:      12px;
  --radius-lg:      18px;
  --radius-xl:      24px;
  --radius-pill:    999px;

  --shadow-ambient: 8px 12px 24px rgba(0, 37, 85, 0.04), -8px -8px 24px rgba(255, 255, 255, 0.8), inset -4px -4px 10px rgba(0, 37, 85, 0.03), inset 4px 4px 10px rgba(255, 255, 255, 0.95);
  --shadow-hover:   12px 18px 30px rgba(0, 37, 85, 0.06), -12px -12px 30px rgba(255, 255, 255, 0.9), inset -4px -4px 10px rgba(0, 37, 85, 0.02), inset 4px 4px 10px rgba(255, 255, 255, 0.98);
  --shadow-card:    8px 12px 24px rgba(0, 37, 85, 0.04), -8px -8px 24px rgba(255, 255, 255, 0.8), inset -4px -4px 10px rgba(0, 37, 85, 0.03), inset 4px 4px 10px rgba(255, 255, 255, 0.95);
  --shadow-float:   16px 24px 40px rgba(0, 37, 85, 0.08), -12px -12px 30px rgba(255, 255, 255, 0.95), inset -6px -6px 12px rgba(0, 37, 85, 0.04), inset 6px 6px 12px rgba(255, 255, 255, 1);

  --ff-sans: "Outfit", "Panton", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --ff-display: "Outfit", "Panton", ui-sans-serif, system-ui, sans-serif;
  --ff-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  font-family: var(--ff-sans);
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  margin: 0;
  padding: 0;
  cursor: default;
  user-select: none;
  -webkit-user-select: none;
}

input, textarea {
  user-select: auto;
  -webkit-user-select: auto;
  cursor: text;
}

a, button, select, label {
  cursor: pointer;
}

/* Permitir seleção apenas onde necessário */
code, pre, .selectable {
  user-select: text;
  -webkit-user-select: text;
  cursor: text;
}

/* Tabelas e estados vazios sem interatividade de texto */
.data-table td, .empty-state-text, svg {
  user-select: none;
  -webkit-user-select: none;
  cursor: default;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 {
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--primary);
  margin: 0 0 .2rem;
  line-height: 1.2;
}
h2 { font-size: 1.1rem; font-weight: 700; letter-spacing: -0.015em; color: var(--primary); margin: 0; }
h3 { font-size: .95rem; font-weight: 700; letter-spacing: -0.01em;  color: var(--primary); margin: 0; }

body.has-sidebar { padding-left: var(--sidebar-w); }

/* ----- Navbar --------------------------------------------- */
.navbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--nav-h);
  background: rgba(0, 31, 77, 0.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid rgba(255,255,255,.08);
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
  z-index: 200;
  gap: .75rem;
}

.navbar__hamburger {
  display: none;
}

@media (max-width: 768px) {
  .navbar__hamburger {
    background: none; border: none;
    color: rgba(255,255,255,.6);
    cursor: pointer;
    padding: .4rem;
    border-radius: var(--radius-sm);
    display: flex; align-items: center;
    transition: background .15s, color .15s;
  }
  .navbar__hamburger:hover { background: rgba(255,255,255,.1); color: #fff; }
}

.navbar__brand {
  display: flex; align-items: center; gap: .6rem;
  color: #fff; font-weight: 800; font-size: .9rem;
  letter-spacing: -0.01em; text-decoration: none;
  user-select: none;
  -webkit-user-select: none;
}
.navbar__brand:hover { text-decoration: none; color: #fff; opacity: .85; }

.navbar__brand-img {
  height: 28px;
  width: auto;
  object-fit: contain;
  filter: brightness(0) invert(1);
}

.navbar__spacer { flex: 1; }

.navbar__user { display: flex; align-items: center; gap: .75rem; }

.navbar__email { color: rgba(255,255,255,.85); font-size: .78rem; font-weight: 500; }

.navbar__logout-btn {
  background: rgba(255,255,255,.08);
  border: 1px solid rgba(255,255,255,.12);
  color: rgba(255,255,255,.75);
  font-family: inherit; font-size: .78rem; font-weight: 600;
  padding: .35rem .9rem;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
  letter-spacing: .01em;
}
.navbar__logout-btn:hover {
  background: rgba(255,255,255,.16);
  border-color: rgba(255,255,255,.22);
  color: #fff;
}

.role-badge {
  font-size: .62rem; font-weight: 700;
  padding: .18rem .6rem;
  border-radius: var(--radius-pill);
  letter-spacing: .06em; text-transform: uppercase; white-space: nowrap;
}
.role-badge--admin       { background: rgba(74,144,226,.22);  color: #93c5fd; }
.role-badge--operacional { background: rgba(34,197,94,.16);   color: #86efac; }
.role-badge--programador { background: rgba(168,85,247,.2);   color: #d8b4fe; }
.role-badge--gerente     { background: rgba(20,184,166,.2);   color: #2dd4bf; }
.role-badge--consulta    { background: rgba(255,255,255,.15); color: rgba(255,255,255,.85); }

/* ----- Sidebar -------------------------------------------- */
.sidebar {
  position: fixed;
  top: var(--nav-h); left: 0;
  width: var(--sidebar-w);
  height: calc(100vh - var(--nav-h));
  background: linear-gradient(160deg, #002153 0%, #00102a 100%);
  display: flex; flex-direction: column;
  overflow-y: auto; z-index: 100;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,.12) transparent;
  box-shadow: 4px 0 24px rgba(0, 15, 35, 0.15);
}

.sidebar__section-title {
  padding: 1.25rem 1.25rem .4rem;
  font-size: .6rem; font-weight: 700;
  letter-spacing: .12em; text-transform: uppercase;
  color: rgba(255,255,255,.25);
}

.sidebar__nav { flex: 1; padding: .35rem 0; }

.sidebar__item {
  display: flex; align-items: center; gap: .65rem;
  padding: .65rem 1.1rem;
  margin: .25rem .75rem;
  color: rgba(255,255,255,.85);
  font-size: .85rem; font-weight: 500; letter-spacing: -.005em;
  transition: all .2s cubic-bezier(.4,0,.2,1);
  text-decoration: none; cursor: pointer;
  border: none; background: none;
  width: calc(100% - 1.5rem);
  font-family: inherit;
  border-radius: var(--radius-pill);
}
.sidebar__item:hover { background: rgba(255,255,255,.1); color: #fff; text-decoration: none; transform: translateX(4px); }
.sidebar__item--active {
  color: #fff;
  background: linear-gradient(135deg, rgba(74, 144, 226, 0.28) 0%, rgba(74, 144, 226, 0.1) 100%);
  font-weight: 600;
  box-shadow: 
    inset 2px 2px 4px rgba(255, 255, 255, 0.15),
    inset -2px -2px 4px rgba(0, 0, 0, 0.22);
  border: 1px solid rgba(255, 255, 255, 0.08);
}
.sidebar__item--active .sidebar__icon { opacity: 1; color: var(--accent); }

.sidebar__icon { opacity: .85; flex-shrink: 0; display: flex; transition: opacity .2s; }
.sidebar__item:hover .sidebar__icon { opacity: 1; }

.sidebar__footer {
  padding: 1rem 1.25rem;
  font-size: .72rem; color: rgba(255,255,255,.2);
  border-top: 1px solid rgba(255,255,255,.06); letter-spacing: .01em;
}

.sidebar__divider {
  margin: .5rem .75rem; border: none;
  border-top: 1px solid rgba(255,255,255,.06);
}

.sidebar__item--disabled { opacity: .3; cursor: default; pointer-events: none; }

.sidebar__chip {
  margin-left: auto;
  font-size: .58rem; font-weight: 700;
  padding: .1rem .45rem;
  border-radius: var(--radius-pill);
  background: rgba(255,255,255,.08); color: rgba(255,255,255,.4);
  letter-spacing: .05em; text-transform: uppercase; flex-shrink: 0;
}

/* ----- Page shell ----------------------------------------- */
.page {
  margin-top: var(--nav-h);
  margin-left: auto; margin-right: auto;
  padding: 2.25rem 2.5rem;
  max-width: 980px;
}
.page--wide { max-width: 1280px; }

.page-header {
  display: flex; align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 1.75rem; gap: 1rem; flex-wrap: wrap;
}
.page-header__subtitle {
  color: var(--text-muted); font-size: .855rem;
  margin-top: .2rem; font-weight: 400;
}
.page-header__actions {
  display: flex; gap: .6rem; align-items: center;
  flex-shrink: 0; padding-top: .25rem;
}

/* ----- Sidebar overlay ------------------------------------ */
.sidebar-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  backdrop-filter: blur(2px); z-index: 99;
}
.sidebar-overlay--visible { display: block; }

/* ----- Animations ----------------------------------------- */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}
.animate-in { animation: fadeInUp .35s cubic-bezier(.4,0,.2,1) both; }

/* ----- Responsive ----------------------------------------- */
@media (max-width: 768px) {
  body.has-sidebar { padding-left: 0; }
  .sidebar {
    transform: translateX(-100%);
    transition: transform .3s cubic-bezier(.4,0,.2,1);
  }
  .sidebar--open { transform: translateX(0); }
  .sidebar-overlay { display: none; }
  .sidebar-overlay--visible { display: block; }
  .page { padding: 1.25rem 1rem; }
}

/* ----- Top progress bar (HTMX loading) -------------------- */
#loading-bar {
  position: fixed;
  top: 0;
  left: 0;
  width: 0%;
  height: 3px;
  background: var(--accent);
  box-shadow: 0 0 8px rgba(74, 144, 226, 0.6);
  z-index: 99999;
  opacity: 0;
  transition: width 0.4s ease, opacity 0.4s ease;
  pointer-events: none;
}

/* Page fade transition under HTMX boost swaps */
.page {
  animation: pageFadeIn 0.22s cubic-bezier(0.4, 0, 0.2, 1);
}
@keyframes pageFadeIn {
  from { opacity: 0.65; transform: translateY(2px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ----- Global Modal with Backdrop Blur -------------------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 15, 35, 0.4);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  opacity: 0;
  transition: opacity 0.25s ease-out;
  padding: 1.5rem;
}
.modal-overlay--visible {
  opacity: 1;
}

.modal-card {
  position: relative;
  background: var(--surface);
  border-radius: 24px;
  width: 100%;
  max-width: 680px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 
    0 20px 50px rgba(0, 20, 50, 0.15),
    inset -6px -6px 12px rgba(0, 20, 50, 0.03),
    inset 6px 6px 12px rgba(255, 255, 255, 0.8);
  border: 1.5px solid rgba(255, 255, 255, 0.7);
  transform: scale(0.95);
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
  padding: 1rem;
}
.modal-overlay--visible .modal-card {
  transform: scale(1);
}

.modal-close-btn {
  position: absolute;
  top: 1.25rem;
  right: 1.25rem;
  background: var(--surface-tonal);
  border: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
  z-index: 10;
}
.modal-close-btn:hover {
  background: var(--danger-bg);
  color: var(--danger);
}

/* ----- Mobile Overrides (Responsividade) ------------------ */
@media (max-width: 768px) {
  /* Navbar */
  .navbar { padding: 0 1rem; gap: 0.5rem; }
  .navbar__email, .role-badge { display: none; }
  .navbar__brand-img { height: 24px; }
  .navbar__logout-btn { padding: .35rem .6rem; }
  
  /* Page Header */
  .page-header {
    flex-direction: column;
    align-items: stretch;
    gap: 0.85rem;
    margin-bottom: 1.25rem;
  }
  .page-header__actions {
    width: 100%;
    justify-content: flex-start;
    flex-wrap: wrap;
    gap: 0.5rem;
  }
  .page-header__actions .btn,
  .page-header__actions .styled-button {
    flex: 1; /* Faz os botões expandirem para ocupar o espaço no mobile */
    justify-content: center;
    text-align: center;
  }
}

@media (max-width: 480px) {
  /* Page Shell */
  .page { padding: 1rem 0.75rem; }
  
  /* Modal */
  .modal-overlay { padding: 0.5rem; }
  .modal-card { 
    padding: 1.25rem 1rem; 
    border-radius: 20px; 
    margin: 0; 
    width: 100%; 
    max-height: 98vh; 
  }
}
