/* ═══════════════════════════════════════
   EchauriHR — Layout System v3
   Clean. Minimal. Enterprise.
   ═══════════════════════════════════════ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font);
  font-size: var(--text-base);
  color: var(--ink);
  background: var(--bg);
  line-height: var(--leading-normal);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  letter-spacing: -0.01em;
}

/* ── App Shell ── */
.app-shell[hidden] { display: none !important; }
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--header-h) 1fr;
  grid-template-areas:
    "sidebar header"
    "sidebar content";
  min-height: 100vh;
  min-height: 100dvh;
}

/* ── Sidebar ── */
.sidebar {
  grid-area: sidebar;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-w);
  z-index: var(--z-sidebar);
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-4) var(--s-5);
  height: var(--header-h);
  border-bottom: 1px solid var(--border-subtle);
}

.sidebar-logo { width: 22px; height: 22px; object-fit: contain; border-radius: 4px; }

.sidebar-brand-name {
  font-size: var(--text-md);
  font-weight: var(--weight-semibold);
  color: var(--ink);
  letter-spacing: -0.03em;
}

.sidebar-nav {
  flex: 1;
  padding: var(--s-3) var(--s-2);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-section-label {
  padding: var(--s-4) var(--s-3) var(--s-2);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--ink-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-2) var(--s-3);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--ink-secondary);
  cursor: pointer;
  transition: background var(--duration-fast), color var(--duration-fast);
  text-decoration: none;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font-family: inherit;
}

.sidebar-item:hover { background: var(--bg-hover); color: var(--ink); }
.sidebar-item.active { background: var(--accent-soft); color: var(--accent); }
.sidebar-item svg { width: 16px; height: 16px; flex-shrink: 0; opacity: 0.7; }
.sidebar-item.active svg { opacity: 1; }

.sidebar-sub { padding-left: var(--s-8); }
.sidebar-sub .sidebar-item { font-size: var(--text-sm); padding: 6px var(--s-3); }

.sidebar-foot {
  padding: var(--s-4) var(--s-5);
  border-top: 1px solid var(--border-subtle);
  margin-top: auto;
}

/* ── Header ── */
.header {
  grid-area: header;
  background: var(--bg-header);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 var(--s-6);
  gap: var(--s-4);
  position: sticky;
  top: 0;
  z-index: var(--z-header);
  height: var(--header-h);
}

.header-breadcrumb {
  font-size: var(--text-sm);
  color: var(--ink-tertiary);
  display: flex;
  align-items: center;
  gap: var(--s-2);
}

.header-breadcrumb span { color: var(--ink-secondary); font-weight: var(--weight-medium); }
.header-breadcrumb svg { width: 12px; height: 12px; opacity: 0.4; }

.header-search {
  flex: 1;
  max-width: 400px;
  margin: 0 auto;
}

.header-search-input {
  width: 100%;
  padding: var(--s-2) var(--s-4);
  padding-left: var(--s-8);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  font-size: var(--text-sm);
  font-family: inherit;
  background: var(--surface-2);
  color: var(--ink);
  transition: border-color var(--duration-fast), background var(--duration-fast), box-shadow var(--duration-fast);
  outline: none;
}

.header-search-input::placeholder { color: var(--ink-placeholder); }
.header-search-input:focus {
  background: var(--surface-0);
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(26, 115, 232, 0.1);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: var(--s-2);
}

.header-icon-btn {
  width: 32px; height: 32px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
  border: none; background: none; cursor: pointer;
  color: var(--ink-secondary);
  transition: background var(--duration-fast), color var(--duration-fast);
}
.header-icon-btn:hover { background: var(--bg-hover); color: var(--ink); }
.header-icon-btn svg { width: 18px; height: 18px; }

.header-avatar {
  width: 28px; height: 28px;
  border-radius: var(--radius-full);
  background: var(--accent);
  color: white;
  display: flex; align-items: center; justify-content: center;
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  cursor: pointer;
}

/* ── Content Area ── */
.content-area {
  grid-area: content;
  padding: var(--s-6) var(--s-6);
  max-width: var(--content-max);
  width: 100%;
  margin: 0 auto;
}

/* ── Page structure ── */
.page-title {
  font-size: var(--text-xl);
  font-weight: var(--weight-semibold);
  color: var(--ink);
  letter-spacing: -0.025em;
  line-height: var(--leading-tight);
}

.page-subtitle {
  font-size: var(--text-sm);
  color: var(--ink-tertiary);
  margin-top: var(--s-1);
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: var(--s-8);
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--ink-tertiary); }

/* ── Utilities ── */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); }

/* ── Focus ── */
:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}

#app-error {
  position: fixed; top: 0; left: 0; right: 0; z-index: 10000;
  padding: var(--s-4) var(--s-6);
  background: #7f1d1d; color: #fff;
  font-size: var(--text-sm); font-weight: 500;
  box-shadow: var(--shadow-lg);
}
#app-error[hidden] { display: none !important; }
.welcome-screen { min-height: 100vh; min-height: 100dvh; }
.welcome-screen[hidden] { display: none !important; }

.portal-layout {
  display: grid;
  grid-template-columns: 380px 1fr;
  min-height: 100vh;
}

.portal-aside {
  background: var(--ink);
  color: white;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: var(--s-12) var(--s-8);
  min-height: 100vh;
}

.portal-aside-inner { position: relative; z-index: 1; display: flex; flex-direction: column; height: 100%; }
.portal-brand { display: flex; align-items: center; gap: var(--s-4); margin-bottom: var(--s-2); }
.portal-logo { width: 56px; height: 56px; object-fit: contain; border-radius: var(--radius-md); flex-shrink: 0; }
.portal-logo-fallback { display: inline-flex; flex-shrink: 0; line-height: 0; }
.portal-logo-fallback svg { display: block; border-radius: 11px; }
.portal-wordmark {
  font-size: var(--text-2xl);
  font-weight: 700;
  letter-spacing: 0.14em;
  line-height: 1;
  background: linear-gradient(135deg, #ffffff 0%, #e0f2fe 55%, #67e8f9 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.sidebar-logo-fallback { display: inline-flex; line-height: 0; }

.portal-main {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: var(--s-12) clamp(var(--s-8), 5vw, var(--s-16));
}

.portal-main-header { margin-bottom: var(--s-10); }
.portal-main-brand {
  display: none;
  align-items: center;
  gap: var(--s-3);
  margin-bottom: var(--s-6);
}
.portal-wordmark-main {
  font-size: var(--text-xl);
  font-weight: 700;
  letter-spacing: 0.12em;
  background: linear-gradient(135deg, var(--accent) 0%, #06b6d4 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.portal-welcome-title { font-size: var(--text-2xl); font-weight: var(--weight-semibold); letter-spacing: -0.02em; margin: 0; }
.portal-welcome-sub { font-size: var(--text-sm); color: var(--ink-tertiary); margin: var(--s-1) 0 0; }

.portal-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--s-4);
  max-width: 600px;
}

/* Portal cards */
.portal-card {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  padding: var(--s-6);
  background: var(--surface-0);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  text-align: left;
  cursor: pointer;
  transition: border-color var(--duration-fast), box-shadow var(--duration-fast), transform var(--duration-fast);
  font-family: inherit;
  line-height: var(--leading-normal);
}
.portal-card:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-sm);
  transform: translateY(-2px);
}
.portal-card-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  background: var(--accent-muted);
  color: var(--accent);
  margin-bottom: var(--s-1);
}
.portal-card-icon svg { width: 20px; height: 20px; }
.portal-card-title { font-size: var(--text-md); font-weight: var(--weight-semibold); color: var(--ink); }
.portal-card-desc { font-size: var(--text-sm); color: var(--ink-tertiary); }

/* ── Responsive ── */
.sidebar-backdrop {
  position: fixed;
  inset: 0;
  z-index: calc(var(--z-sidebar) - 1);
  background: rgba(15, 20, 25, 0.35);
  backdrop-filter: blur(1px);
}
.sidebar-backdrop[hidden] { display: none !important; }

@media (max-width: 1024px) {
  .app-shell { grid-template-columns: 1fr; grid-template-areas: "header" "content"; }
  .sidebar { transform: translateX(-100%); transition: transform var(--duration-slow) var(--ease); }
  .sidebar.open { transform: translateX(0); }
  .content-area { padding: var(--s-5); }
}

@media (max-width: 768px) {
  .portal-layout { grid-template-columns: 1fr; }
  .portal-aside { display: none; }
  .portal-main-brand { display: flex; }
}

/* ── Developer Credit (watermark) ── */
#developer-credit {
  position: fixed;
  bottom: 14px;
  right: 16px;
  z-index: 40;
  margin: 0;
  opacity: 0.4;
  transition: opacity 0.3s ease, filter 0.3s ease;
  pointer-events: auto;
  filter: grayscale(0.2);
}
#developer-credit:hover {
  opacity: 0.9;
  filter: grayscale(0);
}
#developer-credit img {
  height: 52px;
  width: auto;
  border-radius: 10px;
  display: block;
}

/* V12.19 · un solo Hoy e indicadores integrados, sin un acordeón propio. */
.sidebar-nav > .sidebar-item[data-view="dashboard"]{margin:4px 0 8px;min-height:44px}
.sidebar-foot{
  margin-top:auto;
  padding:20px 12px 18px;
  border-top:1px solid var(--border-subtle);
  display:flex;
  flex-direction:column;
  gap:3px;
}
.sidebar-foot-store{margin:0 0 12px;padding-bottom:12px;border-bottom:1px solid var(--border-subtle)}
.sidebar-foot .sidebar-item{
  min-height:44px;
  color:var(--ink-secondary);
  opacity:1;
  font-size:var(--text-sm);
  font-weight:450;
  padding:10px 12px;
}
.sidebar-foot .sidebar-item:hover,.sidebar-foot .sidebar-item:focus-visible{
  opacity:1;color:var(--ink);background:var(--bg-hover);
}
.sidebar-foot .sidebar-item.active{
  opacity:1;
  background:var(--bg-hover);
  color:var(--ink-secondary);
}
.sidebar-foot .sidebar-item:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
.sidebar-foot .pwa-tools{padding:0}
.dash-analytics-integrated{margin-top:34px;padding-top:26px;border-top:1px solid var(--border-subtle);scroll-margin-top:85px}
.dash-analytics-integrated:focus{outline:none}
.dash-analytics-intro{display:flex;flex-wrap:wrap;align-items:end;justify-content:space-between;gap:12px;margin-bottom:17px}
.dash-analytics-intro h2{font-size:clamp(20px,2.1vw,27px);font-weight:760;color:var(--ink);letter-spacing:-.025em}
.dash-analytics-intro p{color:var(--ink-secondary);font-size:13px;max-width:400px}
.dash-analytics-eyebrow{font-size:10px;font-weight:800;letter-spacing:.12em;color:var(--ink-tertiary)}
.dash-analytics-section{margin:18px 0 26px}
.dash-analytics-section>h3{font-size:15px;color:var(--ink);font-weight:750;margin-bottom:12px;padding-left:10px;border-left:3px solid var(--accent)}
.dash-analytics-section .analytics-overview>.page-header{display:none}
.dash-analytics-section .kpi-grid{gap:12px}
.dash-analytics-section .kpi-card{min-width:0}
.dash-analytics-section .data-table{width:100%}
@media(max-width:720px){
  .dash-analytics-integrated{margin-top:26px;padding-top:22px;scroll-margin-top:70px}
  .dash-analytics-intro{display:block}
  .dash-analytics-intro p{margin-top:6px}
  .dash-analytics-section{min-width:0;overflow-wrap:anywhere}
  .dash-analytics-section .card{min-width:0}
}

/* Contraste de acciones secundarias y neutralización del destacado global. */
html:not([data-theme="dark"]) .sidebar-foot .sidebar-item.active{
  background:#eef1f3!important;
  color:#536471!important;
  box-shadow:none!important;
  font-weight:500;
}
html[data-theme="dark"] .sidebar-foot .sidebar-item.active{
  background:var(--surface-2)!important;
  color:var(--ink-secondary)!important;
  box-shadow:none!important;
  font-weight:500;
}
.sidebar-foot .sidebar-item:hover{color:var(--ink)!important}
.dash-analytics-section .card{max-width:100%;overflow-x:auto}
.dash-analytics-section .grid-2>*{min-width:0}
