/* ============================================================
   M&S Accounting Advisers — app.css
   Base + layout responsivo + componentes reutilizables
   ============================================================ */

* { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }

/* Accesibilidad: foco visible */
:focus-visible {
  outline: 2px solid var(--green);
  outline-offset: 2px;
  border-radius: 4px;
}

.is-portal { background: var(--bg-portal); }

/* ============================================================
   TOP BAR
   ============================================================ */
.topbar {
  background: var(--navy);
  height: var(--topbar-h);
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 200;
}
.topbar-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand { display: flex; align-items: center; gap: 11px; min-width: 0; }
.logo {
  width: 36px; height: 36px; flex-shrink: 0;
  background: var(--green); border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; color: #fff;
  box-shadow: var(--shadow-brand);
}
.brand-name { color: #fff; font-size: var(--fs-h3); font-weight: 600; white-space: nowrap; }
.brand-sub  { color: var(--green); font-size: var(--fs-2xs); margin-top: 1px; }
.brand-role { color: var(--green); font-size: var(--fs-sm); }
.brand-text { min-width: 0; overflow: hidden; }

.topbar-right { display: flex; align-items: center; gap: 8px; }
.icon-btn {
  width: 34px; height: 34px; flex-shrink: 0;
  background: rgba(255,255,255,0.1); border: none; border-radius: var(--r-sm);
  display: flex; align-items: center; justify-content: center;
  position: relative; transition: background var(--t);
}
.icon-btn:hover { background: rgba(255,255,255,0.18); }
.dot-alert {
  width: 8px; height: 8px; background: var(--red); border-radius: 50%;
  position: absolute; top: 5px; right: 5px; border: 1.5px solid var(--navy);
}
.user-pill {
  display: flex; align-items: center; gap: 8px;
  background: rgba(255,255,255,0.1); border-radius: 24px;
  padding: 5px 13px 5px 6px; transition: background var(--t); border: none;
}
.user-pill:hover { background: rgba(255,255,255,0.18); }
.user-avatar {
  width: 28px; height: 28px; background: var(--green); border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: var(--fs-xs); color: #fff; font-weight: 700; flex-shrink: 0;
}
.user-name { color: #fff; font-size: var(--fs-body); font-weight: 500; }

/* Menú de usuario (cierre de sesión) */
.user-menu-wrap { position: relative; }
.user-menu {
  position: absolute; top: calc(100% + 6px); right: 0; min-width: 168px;
  background: var(--surface); border: 0.5px solid var(--line); border-radius: var(--r-md);
  box-shadow: var(--shadow-md); padding: 5px; z-index: 200; display: none;
}
.user-menu.open { display: block; }
.user-menu-item {
  display: flex; align-items: center; gap: 8px; width: 100%; text-align: left;
  background: none; border: none; padding: 9px 11px; border-radius: var(--r-sm);
  font-size: var(--fs-body); font-weight: 600; color: var(--ink); cursor: pointer;
}
.user-menu-item:hover { background: var(--line-soft); }
.user-menu-item.danger { color: var(--red-ink); }

/* Dropdowns del topbar (notificaciones + búsqueda) — compartidos */
.notif-wrap { position: relative; }
.notif-menu { position: absolute; top: calc(100% + 8px); right: 0; min-width: 260px;
  background: var(--surface); border: 0.5px solid var(--line); border-radius: var(--r-md);
  box-shadow: var(--shadow-md); padding: 6px; z-index: 200; display: none; }
.notif-menu.open { display: block; }
.notif-head { font-size: var(--fs-xs); font-weight: 700; color: var(--ink-muted); padding: 6px 10px; }
.notif-item { display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 9px 10px; border-radius: var(--r-sm); color: var(--ink); font-size: var(--fs-sm);
  font-weight: 600; text-decoration: none; }
.notif-item:hover { background: var(--line-soft); }
.notif-item .sub { font-weight: 500; color: var(--ink-muted); font-size: var(--fs-xs); margin-top: 1px; }
.notif-count { background: var(--green-tint); color: var(--green-ink); border-radius: 10px;
  padding: 1px 8px; font-size: var(--fs-2xs); font-weight: 700; flex-shrink: 0; }
.notif-empty { padding: 14px 10px; color: var(--ink-muted); font-size: var(--fs-sm); text-align: center; }
.search-input { width: 100%; border: 1px solid var(--line); border-radius: var(--r-sm);
  padding: 8px 10px; font-size: var(--fs-body); outline: none; margin-bottom: 4px; }
.search-input:focus { border-color: var(--green); }
.search-result { display: block; padding: 8px 10px; border-radius: var(--r-sm); color: var(--ink);
  font-size: var(--fs-sm); font-weight: 600; text-decoration: none; }
.search-result:hover { background: var(--line-soft); }
.search-result .sub { font-weight: 500; color: var(--ink-muted); font-size: var(--fs-xs); }

/* Botón hamburguesa — solo móvil/tablet */
.menu-toggle { display: none; }

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

/* ---- SIDEBAR ---- */
.sidebar {
  background: var(--navy);
  width: var(--sidebar-w);
  flex-shrink: 0;
  padding: 14px 0;
  position: sticky;
  top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
}
.nav-section {
  font-size: var(--fs-2xs); color: rgba(255,255,255,0.3);
  padding: 12px 20px 4px; text-transform: uppercase;
  letter-spacing: 0.8px; font-weight: 600;
}
.nav-item {
  padding: 11px 20px; font-size: var(--fs-body);
  color: rgba(255,255,255,0.55); border-left: 3px solid transparent;
  display: flex; align-items: center; gap: 10px;
  transition: all var(--t-fast); width: 100%; text-align: left; background: none; border-top: 0; border-right: 0; border-bottom: 0;
}
.nav-item svg { flex-shrink: 0; }
.nav-item.active { color: #fff; border-left-color: var(--green); background: rgba(255,255,255,0.07); }
.nav-item:hover:not(.active) { color: rgba(255,255,255,0.85); background: rgba(255,255,255,0.04); }
.nav-badge {
  min-width: 18px; height: 18px; border-radius: 9px;
  font-size: var(--fs-2xs); color: #fff; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  margin-left: auto; padding: 0 5px;
}
.nb-green { background: var(--green); }
.nb-red   { background: var(--red); }
.nb-amber { background: var(--amber); }
.nav-dot  { width: 7px; height: 7px; background: var(--green); border-radius: 50%; margin-left: auto; flex-shrink: 0; }

/* Overlay del drawer (oculto en desktop) */
.scrim {
  display: none;
  position: fixed; inset: var(--topbar-h) 0 0 0;
  background: rgba(15,23,42,0.5);
  z-index: 150; opacity: 0; transition: opacity var(--t);
}

/* ---- MAIN ---- */
.main { flex: 1; padding: 20px; overflow-x: hidden; min-width: 0; }
@media (max-width: 600px) { .main { padding: 14px; } }

.page-title { font-size: var(--fs-h2); font-weight: 600; color: var(--ink); margin-bottom: 10px; }

/* ============================================================
   COMPONENTES — Tarjetas de estadística
   ============================================================ */
.stat-grid {
  display: grid; gap: 12px; margin-bottom: 18px;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}
.stat {
  background: var(--surface); border: 0.5px solid var(--line);
  border-radius: var(--r-lg); padding: 14px 16px; transition: box-shadow var(--t);
}
.stat:hover { box-shadow: var(--shadow-md); }
.stat-label { font-size: var(--fs-xs); color: var(--ink-muted); font-weight: 500; margin-bottom: 4px; }
.stat-value { font-size: var(--fs-display); font-weight: 700; color: var(--ink); line-height: 1.1; }
.tag {
  font-size: var(--fs-xs); padding: 3px 8px; border-radius: var(--r-sm);
  display: inline-block; margin-top: 6px; font-weight: 600;
}
.tag-green { background: var(--green-tint); color: var(--green-ink); }
.tag-amber { background: var(--amber-tint); color: var(--amber-ink); }
.tag-blue  { background: var(--blue-tint);  color: var(--blue-ink); }
.tag-red   { background: var(--red-tint);   color: var(--red-ink); }

/* ---- Panel genérico ---- */
.panel {
  background: var(--surface); border: 0.5px solid var(--line);
  border-radius: var(--r-lg); overflow: hidden; box-shadow: var(--shadow-sm);
}
.panel-head {
  padding: 12px 16px; border-bottom: 0.5px solid var(--line-soft);
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.panel-title { font-size: var(--fs-h3); font-weight: 600; color: var(--ink); }
.link {
  font-size: var(--fs-sm); color: var(--green); font-weight: 500;
  background: none; border: none; padding: 0;
}
.link:hover { color: var(--green-700); }

/* ---- Sección con encabezado ---- */
.section-row {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 10px; margin-top: 4px;
}
.section-title { font-size: var(--fs-h3); font-weight: 600; color: var(--ink); }

/* ---- Lista de filas (clientes/docs/mensajes) ---- */
.row {
  display: flex; align-items: center; gap: 11px;
  padding: 12px 16px; border-bottom: 0.5px solid var(--line-soft);
  transition: background var(--t-fast); width: 100%; text-align: left; background: none; border-left: 0; border-right: 0; border-top: 0;
}
.row:last-child { border-bottom: none; }
.row:hover { background: #fafbfc; }
.row-avatar {
  width: 34px; height: 34px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: var(--fs-xs); font-weight: 700; color: #fff;
}
.row-info { flex: 1; min-width: 0; }
.row-name { font-size: var(--fs-body); font-weight: 600; color: var(--ink); }
.row-sub  { font-size: var(--fs-xs); color: var(--ink-muted); margin-top: 1px;
            white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---- Botones ---- */
.btn {
  border: none; border-radius: var(--r-md); font-weight: 600;
  font-size: var(--fs-body); padding: 10px 18px; transition: opacity var(--t);
}
.btn-primary { background: var(--green); color: #fff; box-shadow: var(--shadow-brand); }
.btn-primary:hover { opacity: 0.92; }
.btn-ghost { background: rgba(255,255,255,0.12); color: #fff; }

/* Interruptor de idioma */
.lang-toggle {
  display: flex; align-items: center; gap: 5px;
  background: rgba(255,255,255,0.1); border: none; border-radius: var(--r-sm);
  height: 34px; padding: 0 11px; color: #fff; font-size: var(--fs-sm); font-weight: 600;
  transition: background var(--t);
}
.lang-toggle:hover { background: rgba(255,255,255,0.18); }
.lang-toggle svg { opacity: 0.85; }

/* ============================================================
   RESPONSIVO — tablet y móvil
   ============================================================ */
@media (max-width: 1024px) {
  :root { --sidebar-w: 240px; }

  .menu-toggle {
    display: flex; align-items: center; justify-content: center;
    width: 38px; height: 38px; background: rgba(255,255,255,0.1);
    border: none; border-radius: var(--r-sm);
  }

  /* La barra lateral se convierte en panel deslizable */
  .sidebar {
    position: fixed; top: var(--topbar-h); left: 0;
    height: calc(100vh - var(--topbar-h));
    transform: translateX(-100%);
    transition: transform var(--t);
    z-index: 160; box-shadow: 4px 0 24px rgba(0,0,0,0.25);
  }
  body.nav-open .sidebar { transform: translateX(0); }
  body.nav-open .scrim   { display: block; opacity: 1; }

  /* Acortar nombre de marca en pantallas medianas */
  .brand-sub, .brand-role { display: none; }
}

@media (max-width: 600px) {
  .topbar { padding: 0 12px; }
  .user-name { display: none; }
  .user-pill { padding: 5px; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat-value { font-size: 22px; }
  .brand-name { font-size: var(--fs-body); }
}
