/* CSS Variables defined in css/tokens.css — loaded before this file */

/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 15px; }

body {
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.55;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { text-decoration: none; color: inherit; }
button { cursor: pointer; border: none; background: none; font-family: inherit; }
input, select, textarea { font-family: inherit; }
ul, ol { list-style: none; }

/* ===== App Layout ===== */
.app-layout {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  min-height: 100vh;
}

/* ===== Sidebar ===== */
.sidebar {
  background: var(--color-primary-dark);
  background-image: linear-gradient(180deg, var(--color-primary-dark) 0%, #0A141F 100%);
  color: #fff;
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: sticky;
  top: 0;
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 100;
  transition: transform var(--transition);
}

.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 2px; }

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 16px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.sidebar-logo {
  width: 36px; height: 36px;
  background: linear-gradient(135deg, var(--color-primary-lt), var(--color-primary));
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  color: #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}

.sidebar-brand { flex: 1; min-width: 0; }
.sidebar-brand-name {
  display: block;
  font-size: 0.875rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-brand-sub {
  display: block;
  font-size: 0.7rem;
  color: rgba(255,255,255,0.5);
  margin-top: 1px;
}

.sidebar-close {
  color: rgba(255,255,255,0.5);
  font-size: 1.1rem;
  padding: 4px;
  display: none;
}

/* ===== Sidebar Nav ===== */
.sidebar-nav {
  padding: 12px 8px;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  color: rgba(255,255,255,0.65);
  transition: all var(--transition);
  position: relative;
  margin-bottom: 2px;
  letter-spacing: 0.01em;
}

.nav-item:hover {
  background: rgba(255,255,255,0.07);
  color: rgba(255,255,255,0.95);
  transform: translateX(2px);
}

.nav-item.active {
  background: linear-gradient(90deg, rgba(30,61,89,0.35), rgba(30,61,89,0.15));
  color: #fff;
  border-left: 3px solid var(--color-primary-lt);
  padding-left: 9px;
}

.nav-item svg { flex-shrink: 0; opacity: 0.85; }
.nav-item.active svg { opacity: 1; }

.nav-item--logout {
  width: 100%;
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-size: inherit;
  color: rgba(255,255,255,0.6);
  text-align: left;
}
.nav-item--logout:hover {
  background: rgba(230,57,70,0.2);
  color: #fca5a5;
}

.nav-badge {
  margin-left: auto;
  background: var(--color-danger);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
}

.nav-divider {
  height: 1px;
  background: rgba(255,255,255,0.08);
  margin: 8px 4px;
}

/* ===== Sidebar Overlay (mobile) ===== */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 99;
}

/* ===== Main Wrapper ===== */
.main-wrapper {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-width: 0;
}

/* ===== Topbar ===== */
.topbar {
  height: var(--topbar-height);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: 0 1px 0 var(--color-border), var(--shadow-sm);
  backdrop-filter: blur(8px);
  background: rgba(255,255,255,0.92);
}

.hamburger {
  display: none;
  flex-direction: column;
  gap: 5px;
  padding: 4px;
}
.hamburger span {
  display: block;
  width: 20px;
  height: 2px;
  background: var(--color-text);
  border-radius: 2px;
  transition: var(--transition);
}

.topbar-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--color-text);
  flex: 1;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar-period {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  background: var(--color-bg);
  padding: 4px 10px;
  border-radius: 20px;
  border: 1px solid var(--color-border);
}

/* ===== App Content ===== */
.app-content {
  flex: 1;
  padding: 24px;
  max-width: 1400px;
  width: 100%;
}

/* ===== Loading Screen ===== */
.loading-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  min-height: 300px;
  color: var(--color-text-muted);
}

.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

/* ===== Page Header ===== */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 16px;
  flex-wrap: wrap;
}

.page-header h2 {
  font-size: 1.3rem;
  font-weight: 700;
}

.page-header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

/* ===== Back button ===== */
.btn-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--color-primary);
  font-size: 0.875rem;
  font-weight: 600;
  padding: 6px 0;
  margin-bottom: 16px;
}
.btn-back:hover { text-decoration: underline; }

/* ===== Responsive ===== */
/* ===== PWA Install Button ===== */
.btn-install {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px; height: 36px;
  border-radius: 8px;
  border: 1.5px solid var(--color-border);
  color: var(--color-primary);
  background: transparent;
  transition: all var(--transition);
}
.btn-install:hover { background: var(--color-bg); }

/* ===== Bottom Nav (mobile) ===== */
.bottom-nav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: calc(var(--bottom-nav-height) + var(--safe-bottom));
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  box-shadow: 0 -2px 12px rgba(0,0,0,0.08);
  z-index: 90;
  padding-bottom: var(--safe-bottom);
  display: none;
  grid-template-columns: repeat(5, 1fr);
  align-items: stretch;
}

.bottom-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 8px 4px;
  color: var(--color-text-muted);
  font-size: 0.73rem;
  font-weight: 600;
  position: relative;
  transition: color var(--transition);
  background: none;
  border: none;
  cursor: pointer;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}
.bottom-nav-item.active { color: var(--color-primary); }
.bottom-nav-item.active svg { stroke: var(--color-primary); }
.bottom-nav-more { cursor: pointer; }

.bottom-badge {
  position: absolute;
  top: 6px;
  right: calc(50% - 14px);
  width: 8px; height: 8px;
  background: var(--color-danger);
  border-radius: 50%;
  border: 2px solid var(--color-surface);
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .app-layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    transform: translateX(-100%);
    width: var(--sidebar-width);
    z-index: 110;
  }
  .sidebar.open { transform: translateX(0); }

  .sidebar-overlay.open { display: block; z-index: 109; }
  .sidebar-close { display: block; }
  .hamburger { display: none; } /* hide hamburger, using bottom nav "Mais" instead */

  .app-content {
    padding: 16px 16px calc(var(--bottom-nav-height) + var(--safe-bottom) + 8px);
  }
  .topbar { padding: 0 16px 0 calc(16px + var(--safe-left)); }

  /* Show bottom nav */
  .bottom-nav { display: grid; }

  /* Topbar on mobile: show hamburger only as fallback */
  .topbar { padding-top: var(--safe-top); }
}

@media (max-width: 480px) {
  .page-header { flex-direction: column; align-items: flex-start; }
  .page-header-actions { width: 100%; justify-content: flex-start; }
  .topbar-period { display: none; }

  /* Mobile-optimized spacing */
  .app-content {
    padding: 12px 12px calc(var(--bottom-nav-height) + var(--safe-bottom) + 8px);
  }
  .topbar {
    padding: var(--safe-top) 12px 0;
  }

  /* Optimize topbar for small screens */
  .topbar-actions { gap: 8px; }
  .btn-install { width: 40px; height: 40px; padding: 0; }

  /* Better modal sizing */
  .modal {
    padding: 16px;
    border-radius: 12px;
  }
  .modal-header { margin-bottom: 16px; }

  /* Table responsiveness */
  table { font-size: 0.8rem; }
  th, td { padding: 8px 4px; }
}

/* Standalone PWA mode adjustments */
@media (display-mode: standalone) {
  .topbar {
    padding-top: max(var(--safe-top), 8px);
    height: calc(var(--topbar-height) + var(--safe-top));
  }
}
