/* ========================================
   Layout comum — Topbar, Sidebar, Modal, Auth
   ======================================== */

/* ---------- Topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 200; height: var(--topbar-h);
  padding: 0 20px; background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-right { position: relative; display: flex; align-items: center; }

.brand-logo { height: 26px; width: auto; display: block; }

.btn-menu {
  background: none; border: none; color: var(--muted); width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center; border-radius: 6px;
  transition: all .2s;
}
.btn-menu:hover { color: var(--text); background: rgba(255,255,255,0.06); }
body.light .btn-menu:hover { background: rgba(0,0,0,0.06); }

.btn-login {
  background: transparent; border: 1px solid var(--border); color: var(--muted);
  padding: 5px 16px; border-radius: 14px; font-size: 12px; font-weight: 600;
  transition: all .2s;
}
.btn-login:hover { border-color: var(--accent); color: var(--text); }
.btn-login.is-admin { border-color: var(--orange); color: var(--orange); }
.btn-login.is-admin:hover { border-color: var(--orange); color: #fff; background: var(--orange); }

.user-dropdown {
  position: absolute; top: 100%; right: 0; margin-top: 6px; min-width: 180px;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 4px; display: none; z-index: 300;
}
.user-dropdown.open { display: block; }
.user-dropdown .dropdown-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 6px;
  font-size: 12px; color: var(--muted); cursor: pointer; transition: all .15s;
  border: none; background: none; width: 100%; text-align: left; text-decoration: none;
}
.user-dropdown .dropdown-item:hover { background: rgba(255,255,255,0.06); color: var(--text); }

.btn-theme {
  background: none; border: none; color: var(--muted); width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center; border-radius: 50%;
  transition: all .2s; margin-right: 4px;
}
.btn-theme:hover { color: var(--accent); background: rgba(255,255,255,0.06); }
body.light .btn-theme:hover { background: rgba(0,0,0,0.06); }

/* ---------- App Layout ---------- */
.app-layout { display: flex; min-height: calc(100vh - var(--topbar-h)); }

.drawer-overlay { display: none; }

.sidebar {
  position: fixed; top: var(--topbar-h); left: 0; bottom: 0; width: 60px; z-index: 100;
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; overflow: hidden;
  transition: width .25s cubic-bezier(.4,0,.2,1);
}
body.drawer-open .sidebar { width: 260px; }

.sidebar-nav { flex: 1; display: flex; flex-direction: column; gap: 2px; padding: 6px 0; }

.nav-item {
  display: flex; align-items: center; gap: 14px; height: 40px; padding: 0 16px;
  font-size: 12px; font-weight: 500; color: var(--muted);
  border-left: 3px solid transparent; transition: all .2s; white-space: nowrap;
  flex-shrink: 0; text-decoration: none;
}
.nav-item:hover { color: var(--text); background: rgba(255,255,255,0.04); }
.nav-item.active {
  color: var(--md-accent); border-left-color: var(--md-accent);
  background: rgba(168,199,250,.08);
}

.nav-icon {
  width: 20px; height: 20px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}

.nav-label {
  font-size: 10px; text-transform: uppercase; letter-spacing: .5px;
  opacity: 0; transition: opacity .2s; white-space: nowrap;
}
body.drawer-open .nav-label { opacity: 1; }

.sidebar-divider {
  height: 1px; background: var(--border); margin: 6px 16px; flex-shrink: 0;
}

.nav-spacer { flex: 1; }

.version-tag {
  font-size: 10px; color: var(--muted); opacity: .4; text-align: center;
  padding: 8px 0; font-family: 'Courier New', monospace;
  transition: opacity .2s; flex-shrink: 0; letter-spacing: .5px;
}
.version-tag:hover { opacity: .7; }

/* ---------- Main ---------- */
main {
  flex: 1; min-width: 0; margin-left: 60px; padding: 24px 24px 40px;
}
body.drawer-open main { margin-left: 260px; }

/* ---------- Overlay / Modal ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6); z-index: 400;
  display: none; align-items: center; justify-content: center; padding: 16px;
}
.overlay.open { display: flex; }

.modal {
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  max-width: 400px; width: 100%; padding: 24px; max-height: 90vh; overflow-y: auto;
}
.modal h2 { font-size: 16px; font-weight: 600; margin-bottom: 4px; }
.modal p { font-size: 12px; color: var(--muted); margin-bottom: 20px; }
.modal-close {
  float: right; background: none; border: none; color: var(--muted);
  font-size: 18px; line-height: 1; padding: 0; margin: -4px -4px 0 0;
}
.modal-close:hover { color: var(--text); }

/* ---------- Auth Forms ---------- */
.form-group { margin-bottom: 14px; }
.form-group label {
  display: block; font-size: 11px; font-weight: 600;
  color: var(--muted-alt); margin-bottom: 4px;
}
.form-group input {
  width: 100%; background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 12px; color: var(--text); font-size: 13px;
  outline: none; font-family: inherit; transition: border .25s;
}
.form-group input:focus { border-color: var(--accent); }
.form-group input::placeholder { color: var(--muted); }

.forgot-link {
  display: block; font-size: 11px; color: var(--muted); cursor: pointer; margin-top: 6px;
}
.forgot-link:hover { color: var(--accent); }

.btn-primary {
  width: 100%; background: var(--md-accent); border: none; color: var(--md-accent-text);
  padding: 10px 24px; border-radius: 8px; font-size: 14px; font-weight: 700;
  cursor: pointer; font-family: inherit; transition: opacity .2s;
}
.btn-primary:hover { opacity: .85; }
.btn-primary:disabled { opacity: .4; cursor: not-allowed; }

.btn-danger {
  background: transparent; border: 1px solid var(--red); color: var(--red);
  padding: 9px 24px; border-radius: 8px; font-size: 13px; font-weight: 600;
  cursor: pointer; font-family: inherit; transition: all .2s;
}
.btn-danger:hover { background: rgba(255,71,87,0.1); }

.auth-error {
  display: none; background: rgba(255,71,87,0.12); color: var(--red);
  padding: 8px 12px; border-radius: 6px; font-size: 12px; margin-bottom: 12px;
}
.auth-success {
  display: none; background: rgba(0,200,150,0.12); color: var(--green);
  padding: 8px 12px; border-radius: 6px; font-size: 12px; margin-bottom: 12px;
}

.auth-toggle { text-align: center; margin-top: 14px; font-size: 12px; color: var(--muted); }
.auth-toggle a { color: var(--accent); cursor: pointer; }
.auth-toggle a:hover { text-decoration: underline; }

.auth-divider {
  display: flex; align-items: center; gap: 12px; margin: 16px 0;
  color: var(--muted); font-size: 11px;
}
.auth-divider::before, .auth-divider::after {
  content: ''; flex: 1; height: 1px; background: var(--border);
}

.btn-google {
  width: 100%; background: transparent; border: 1px solid var(--border);
  color: var(--text); padding: 9px 24px; border-radius: 8px; font-size: 13px;
  font-weight: 600; cursor: pointer; display: flex; align-items: center;
  justify-content: center; gap: 10px; transition: border .2s; font-family: inherit;
}
.btn-google:hover { border-color: var(--accent); }

/* ---------- Responsive ---------- */
@media(max-width: 768px) {
  main { margin-left: 0; padding: 20px 12px 30px; }
  body.drawer-open main { margin-left: 0; }

  .app-layout { display: block; }

  .sidebar {
    position: fixed; top: var(--topbar-h); left: 0; bottom: 0; width: 260px;
    z-index: 150; transform: translateX(-100%);
    transition: transform .25s cubic-bezier(.4,0,.2,1);
    border-right: 1px solid var(--border);
  }
  body.drawer-open .sidebar { transform: translateX(0); width: 260px; }

  .drawer-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,0.5); z-index: 149;
  }
  body.drawer-open .drawer-overlay { display: block; }

  .nav-label { opacity: 1; }
}

/* ---------- Loading Spinner (shared) ---------- */
.loading {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 60px 0; color: var(--muted); gap: 10px;
}
.loading .spinner {
  width: 28px; height: 28px; border: 3px solid var(--border);
  border-top-color: var(--accent); border-radius: 50%;
  animation: spin .7s linear infinite;
}

/* ---------- View Mode Toggle (Carteira) ---------- */
.visao-ativo {
  padding: 4px 12px; font-size: 10px; font-weight: 600; border-radius: 20px;
  border: 1px solid var(--md-accent); background: var(--md-accent);
  color: var(--md-accent-text); cursor: pointer; font-family: inherit; transition: all .2s;
}
.visao-inativo {
  padding: 4px 12px; font-size: 10px; font-weight: 600; border-radius: 20px;
  border: 1px solid var(--md-border); background: var(--md-input-bg);
  color: var(--md-text); cursor: pointer; font-family: inherit; transition: all .2s; opacity: .7;
}

/* ---------- Bottom Tab Bar (mobile nav) ---------- */
.bottom-tabs {
  display: none;
  position: fixed; bottom: 0; left: 0; right: 0; height: 56px;
  background: rgba(26,28,30,0.92);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  z-index: 200;
  justify-content: space-around; align-items: center;
  padding-bottom: env(safe-area-inset-bottom);
}
body.light .bottom-tabs { background: rgba(255,255,255,0.92); }

.tab-item {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 4px 0; text-decoration: none; color: var(--muted);
  font-size: 10px; font-weight: 500; flex: 1; min-width: 0;
  transition: color .2s;
}
.tab-item .tab-icon { width: 20px; height: 20px; display: flex; align-items: center; justify-content: center; }
.tab-item .tab-icon svg { width: 18px; height: 18px; }
.tab-item.active { color: var(--md-accent); }
.tab-item:hover { color: var(--text); }
.tab-item:active { opacity: .7; }

/* ---------- Bottom Sheet (shared mobile filter panel) ---------- */
.bottom-sheet-backdrop {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.5); z-index: 290;
}
.bottom-sheet-backdrop.open { display: block; }

.bottom-sheet {
  position: fixed; bottom: 0; left: 0; right: 0;
  max-height: 65vh; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px 16px 0 0; z-index: 300;
  transform: translateY(100%);
  transition: transform .3s cubic-bezier(.4,0,.2,1);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottom-sheet.open { transform: translateY(0); }

.sheet-handle {
  width: 32px; height: 4px; background: var(--border);
  border-radius: 2px; margin: 8px auto 16px;
}

/* ---------- Page Header & Breadcrumbs ---------- */
.page-header { padding: 0 0 12px; margin-bottom: 4px; }
.page-header h1 { font-size: 22px; font-weight: 700; color: var(--text); margin: 0; }
@media (max-width: 768px) {
  .page-header h1 { font-size: 18px; }
}

button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--md-accent);
  outline-offset: 2px;
}

/* ---------- Segmented Control (shared) ---------- */
.seg-control {
  display: inline-flex; background: var(--md-input-bg);
  border-radius: 10px; padding: 3px; gap: 2px;
}
.seg-option {
  padding: 6px 14px; border-radius: 8px; font-size: 11px; font-weight: 600;
  border: none; background: transparent; color: var(--muted);
  cursor: pointer; font-family: inherit; transition: all .15s;
  white-space: nowrap; line-height: 1.3;
}
.seg-option:hover:not(.active) { color: var(--text); }
.seg-option.active {
  background: var(--md-surface); color: var(--text);
  box-shadow: 0 1px 3px rgba(0,0,0,0.12);
}
body.light .seg-option.active { box-shadow: 0 1px 3px rgba(0,0,0,0.06); }

/* ---------- Skeleton Cards (shared) ---------- */
.sk-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 12px; padding: 14px; margin-bottom: 8px;
  animation: skPulse 1.6s ease-in-out infinite;
}
.sk-card:nth-child(2) { animation-delay: .1s; }
.sk-card:nth-child(3) { animation-delay: .2s; }
.sk-card:nth-child(4) { animation-delay: .3s; }
.sk-card:nth-child(5) { animation-delay: .4s; }
.sk-card:nth-child(6) { animation-delay: .5s; }
.sk-card:nth-child(7) { animation-delay: .6s; }
.sk-card:nth-child(8) { animation-delay: .7s; }
.sk-line { height: 12px; background: var(--md-input-bg); border-radius: 6px; margin-bottom: 8px; }
.sk-line.w60 { width: 60%; }
.sk-line.w40 { width: 40%; }
.sk-line.w30 { width: 30%; }
.sk-line.w80 { width: 80%; }
.sk-metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.sk-metric { height: 32px; background: var(--md-input-bg); border-radius: 8px; }
@keyframes skPulse { 0%,100% { opacity: 1 } 50% { opacity: .45 } }

/* ---------- Sticky Chip Bar ---------- */
.chip-bar-sticky {
  position: sticky; top: var(--topbar-h); z-index: 50;
  background: var(--bg); padding: 10px 0 6px;
  margin: -6px -12px 0;
  padding-left: 12px; padding-right: 12px;
}

/* ---------- Bottom Sheet Tabs ---------- */
.bs-tabs { display: flex; gap: 0; margin-bottom: 14px; border-bottom: 1px solid var(--border); }
.bs-tab {
  flex: 1; text-align: center; padding: 10px 0; font-size: 12px; font-weight: 600;
  color: var(--muted); cursor: pointer; border: none; background: none;
  font-family: inherit; border-bottom: 2px solid transparent; transition: all .15s;
}
.bs-tab:hover { color: var(--text); }
.bs-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ---------- Profile Cards (Quick Tune) ---------- */
.profile-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 14px; }
.profile-card {
  padding: 12px 10px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--md-input-bg); cursor: pointer; text-align: center;
  transition: all .15s; font-family: inherit;
}
.profile-card:hover { border-color: var(--md-accent); }
.profile-card.active { border-color: var(--md-accent); background: rgba(168,199,250,.1); }
body.light .profile-card.active { background: rgba(11,87,208,.06); }
.profile-card .prof-icon { font-size: 22px; margin-bottom: 4px; display: block; }
.profile-card .prof-name { font-size: 12px; font-weight: 600; color: var(--text); }
.profile-card .prof-desc { font-size: 9px; color: var(--muted); margin-top: 2px; }

/* ---------- Accordion (Advanced) ---------- */
.acc-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px; background: var(--md-input-bg); border: 1px solid var(--border);
  border-radius: 8px; font-size: 12px; font-weight: 600; color: var(--text);
  cursor: pointer; margin-bottom: 4px; transition: border .15s; font-family: inherit; width: 100%;
}
.acc-header:hover { border-color: var(--md-accent); }
.acc-header .acc-arrow { transition: transform .2s; font-size: 10px; color: var(--muted); }
.acc-header.open .acc-arrow { transform: rotate(180deg); }
.acc-body { display: none; padding: 8px 4px 12px; }
.acc-body.open { display: block; }
.acc-expand-all {
  font-size: 10px; color: var(--muted); cursor: pointer; background: none; border: none;
  font-family: inherit; padding: 4px 0; margin-bottom: 8px; transition: color .15s;
}
.acc-expand-all:hover { color: var(--accent); }

/* ---------- Profile chips (ranking + admin) ---------- */
.profile-chips{display:flex;align-items:center;gap:6px;flex-wrap:wrap}
.profile-chip{height:32px;padding:0 14px;border-radius:8px;font-size:12px;font-weight:600;color:var(--muted);border:1px solid var(--border);background:transparent;cursor:pointer;font-family:inherit;transition:all .2s;white-space:nowrap}
.profile-chip:hover:not(.active){border-color:var(--md-accent);color:var(--text)}
.profile-chip.active{background:rgba(168,199,250,.18);color:#A8C7FA}
body.light .profile-chip.active{background:rgba(11,87,208,.1);color:#0B57D0}

/* ---------- Ranking controls (panel + admin profile editor) ---------- */
.rs-header{font-size:11px;font-weight:700;color:var(--muted-alt);text-transform:uppercase;letter-spacing:.8px;margin-bottom:6px}
.rs-divider{height:1px;background:var(--border);margin:10px 0}
.rs-reset{width:100%;padding:8px;border-radius:8px;font-size:12px;font-weight:600;cursor:pointer;font-family:inherit;background:var(--bg);border:1px solid var(--border);color:var(--muted);transition:all .2s;margin-top:16px}
.rs-reset:hover{border-color:var(--accent);color:var(--text)}
.ps-row{display:flex;align-items:center;gap:8px;margin:4px 0}
.ps-track-wrap{flex:1;position:relative;height:24px;display:flex;align-items:center}
.ps-track{position:relative;width:100%;height:4px;background:var(--border);border-radius:2px}
.ps-fill{position:absolute;top:0;height:4px;background:var(--accent);border-radius:2px;pointer-events:none}
.ps-min,.ps-max{position:absolute;top:-10px;width:100%;height:24px;-webkit-appearance:none;appearance:none;background:transparent;pointer-events:none;margin:0;padding:0}
.ps-min{z-index:3}
.ps-max{z-index:2}
.ps-min::-webkit-slider-thumb,.ps-max::-webkit-slider-thumb{-webkit-appearance:none;appearance:none;width:20px;height:20px;border-radius:50%;background:var(--accent);border:2px solid var(--card);cursor:pointer;pointer-events:auto;box-shadow:0 1px 4px rgba(0,0,0,0.5)}
.ps-min::-moz-range-thumb,.ps-max::-moz-range-thumb{width:20px;height:20px;border-radius:50%;background:var(--accent);border:2px solid var(--card);cursor:pointer;pointer-events:auto}
.pf-row{display:flex;gap:6px;margin-bottom:4px}
.pf-cell{flex:1;display:flex;flex-direction:column;gap:2px}
.pf-label{font-size:9px;color:var(--muted);font-weight:600}
.pf-cell input,.pf-cell select{width:100%;background:var(--md-input-bg);border:1px solid var(--md-border);border-radius:6px;padding:5px 6px;color:var(--text);font-size:11px;outline:none;font-family:inherit}
.pf-cell input:focus,.pf-cell select:focus{border-color:var(--md-accent)}
.pf-cell select{color:var(--md-accent);font-weight:600;cursor:pointer}

/* ---------- Mobile layout switch ---------- */
@media (max-width: 768px) {
  .bottom-tabs { display: flex; }
  .sidebar { display: none; }
  body.drawer-open .sidebar { display: flex; }
  main { margin-left: 0; padding-bottom: 72px; }
  body.drawer-open main { margin-left: 0; }
}
