/* ========================================
   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 {
  font-size: 17px; font-weight: 700; color: var(--accent); letter-spacing: -0.3px;
}

.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); }

.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(--accent); border: none; color: #000;
  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; }

.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; }
}

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