:root{
  --purple-700:#6D28D9;
  --purple-800:#5B21B6;
  --purple-100:#F3E8FF;
  --gray-700:#374151;
  --gray-300:#D1D5DB;
  --white:#FFFFFF;

  --sidebar-width: 260px;
  --sidebar-collapsed-width: 86px;
  --topbar-height: 56px;
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 10px;
  --shadow-soft: 0 10px 30px rgba(0,0,0,.06);
  --border-soft: 1px solid #E5E7EB;
}

*{ box-sizing:border-box; }

html, body{
  margin:0;
  padding:0;
}

body{
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  color: var(--gray-700);
  background: #F9FAFB;
}

body.bg-white{
  background: var(--white);
}

/* =========================
   Autenticación
   ========================= */

.auth-wrapper,
.auth-full{
  min-height: 100dvh;
  display:flex;
  align-items:center;
  justify-content:center;
  padding: 24px;
}

.auth-card{
  width: 100%;
  max-width: 420px;
  background: var(--white);
  border: 1px solid var(--gray-300);
  border-radius: var(--radius-lg);
  padding: 28px;
  box-shadow: var(--shadow-soft);
  margin: 0 auto;
}

.auth-card h1{
  margin: 0 0 6px 0;
  font-size: 24px;
  color: var(--purple-800);
}

.auth-card .help{
  margin: 0 0 16px 0;
  font-size: 14px;
  color: #6b7280;
}

label{
  display:block;
  margin: 14px 0 6px;
  font-size: 14px;
}

input,
select,
textarea{
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--gray-300);
  background: var(--purple-100);
  outline:none;
  font-size: 15px;
  color: var(--gray-700);
}

input:focus,
select:focus,
textarea:focus{
  border-color: var(--purple-700);
  box-shadow: 0 0 0 3px rgba(109,40,217,.15);
}

.btn-primary{
  margin-top: 18px;
  width: 100%;
  padding: 12px 16px;
  border: none;
  border-radius: 12px;
  background: linear-gradient(180deg, var(--purple-700), var(--purple-800));
  color: var(--white);
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  transition: .2s ease;
}

.btn-primary:hover{
  filter: brightness(1.03);
}

.alt{
  text-align:center;
  margin-top: 14px;
  font-size:14px;
}

/* =========================
   Flashes
   ========================= */

.flash-wrapper{
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  display: grid;
  gap: 8px;
  width: min(92vw, 560px);
  z-index: 1200;
}

.flash{
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 14px;
  box-shadow: 0 8px 20px rgba(0,0,0,.05);
  background: #fff;
}

.flash.error{
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

.flash.success{
  background: #dcfce7;
  color: #14532d;
  border: 1px solid #bbf7d0;
}

/* =========================
   Layout app
   ========================= */

body.layout,
body.app-layout{
  background: #F9FAFB;
}

.shell{
  min-height: 100vh;
}

.sidebar{
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  z-index: 1000;
  background: #FAFAFA;
  border-right: 1px solid #E5E7EB;
  padding: 14px 12px;
  overflow-y: auto;
  transition:
    width .25s ease,
    transform .25s ease,
    padding .25s ease;
}

.app-main{
  min-height: 100vh;
  margin-left: var(--sidebar-width);
  transition: margin-left .25s ease;
}

.topbar{
  position: sticky;
  top: 0;
  z-index: 900;
  height: var(--topbar-height);
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap: 12px;
  padding: 0 16px;
  background:#ffffff;
  border-bottom:1px solid #E5E7EB;
}

.topbar-left,
.topbar-right{
  display:flex;
  align-items:center;
  gap: 12px;
  min-width: 0;
}

.topbar .brand{
  font-weight:700;
  color:#5B21B6;
  white-space: nowrap;
}

.topbar .user-chip{
  font-size:14px;
  color:#6b7280;
  white-space: nowrap;
}

.sidebar-toggle{
  width: 40px;
  height: 40px;
  border: 1px solid #E5E7EB;
  background: #fff;
  border-radius: 10px;
  cursor: pointer;
  font-size: 18px;
  color: #5B21B6;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: .2s ease;
}

.sidebar-toggle:hover{
  background: #F3E8FF;
  border-color: #DDD6FE;
}

.btn-ghost{
  text-decoration:none;
  padding:8px 12px;
  border-radius:10px;
  border:1px solid #E5E7EB;
  font-size:14px;
  color:#5B21B6;
  background: #fff;
  transition: .2s ease;
  white-space: nowrap;
}

.btn-ghost:hover{
  background:#F3E8FF;
  border-color:#DDD6FE;
}

.content{
  padding: 24px;
}

/* =========================
   Sidebar nav
   ========================= */

.side-nav{
  display:grid;
  gap:6px;
}

.side-link,
.side-sublink,
.side-parent{
  width: 100%;
  display:flex;
  align-items:center;
  gap:10px;
  min-height: 44px;
  padding:10px 12px;
  border-radius:12px;
  color:#374151;
  text-decoration:none;
  background: transparent;
  transition: .2s ease;
}

.side-link:hover,
.side-sublink:hover,
.side-parent:hover{
  background:#F3E8FF;
}

.side-link.active,
.side-sublink.active,
.side-parent.active{
  background:#EDE9FE;
  color:#5B21B6;
  font-weight:600;
}

.side-link .icon,
.side-sublink .icon,
.side-parent .icon{
  width:20px;
  min-width:20px;
  text-align:center;
  display:inline-flex;
  align-items:center;
  justify-content:center;
}

.side-link .label,
.side-sublink .label,
.side-parent .label{
  min-width: 0;
  flex: 1;
  line-height: 1.2;
  word-break: break-word;
}

.side-group,
.side-subgroup{
  width:100%;
}

.side-group > summary,
.side-subgroup > summary{
  list-style: none;
  cursor: pointer;
}

.side-group > summary::-webkit-details-marker,
.side-subgroup > summary::-webkit-details-marker{
  display: none;
}

.chev{
  margin-left: auto;
  font-size: 12px;
  color: #6b7280;
  transition: transform .2s ease;
  flex-shrink: 0;
}

.side-group[open] > summary .chev,
.side-subgroup[open] > summary .chev{
  transform: rotate(180deg);
}

.side-sub{
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  margin-top: 6px;
  padding-left: 12px;
  border-left: 1px solid #E9D5FF;
}

.side-sublink{
  font-size: 14px;
}

/* =========================
   Sidebar colapsado escritorio
   ========================= */

body.sidebar-collapsed .sidebar{
  width: var(--sidebar-collapsed-width);
  padding-left: 10px;
  padding-right: 10px;
}

body.sidebar-collapsed .app-main{
  margin-left: var(--sidebar-collapsed-width);
}

body.sidebar-collapsed .side-link,
body.sidebar-collapsed .side-sublink,
body.sidebar-collapsed .side-parent{
  justify-content: center;
  padding-left: 10px;
  padding-right: 10px;
}

body.sidebar-collapsed .side-link .label,
body.sidebar-collapsed .side-sublink .label,
body.sidebar-collapsed .side-parent .label,
body.sidebar-collapsed .side-link .chev,
body.sidebar-collapsed .side-sublink .chev,
body.sidebar-collapsed .side-parent .chev{
  display: none;
}

body.sidebar-collapsed .side-sub{
  display: none;
}

body.sidebar-collapsed .side-group > summary,
body.sidebar-collapsed .side-subgroup > summary{
  padding-left: 10px;
  padding-right: 10px;
}

/* =========================
   Overlay móvil
   ========================= */

.sidebar-overlay{
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, .38);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: .25s ease;
  z-index: 950;
}

/* =========================
   Dashboard
   ========================= */

.dash-wrapper{
  min-height: 100dvh;
  display:flex;
  align-items:center;
  justify-content:center;
  padding: 24px;
}

.dash-card{
  width: 100%;
  max-width: 720px;
  background:#fff;
  border:1px solid #E5E7EB;
  border-radius:16px;
  padding:24px;
  box-shadow: 0 10px 30px rgba(0,0,0,.04);
}

.btn-link{
  display:inline-block;
  margin-top:10px;
  text-decoration:none;
  color: var(--purple-800);
}

/* =========================
   Páginas internas
   ========================= */

.page-wrap{
  max-width: 1100px;
  margin: 24px auto;
  padding: 0 14px;
}

.page-title{
  margin: 0 0 12px 0;
}

.page-flashes{
  margin-bottom: 12px;
}

.card{
  background: var(--white);
  border: 1px solid #E5E7EB;
  border-radius: 16px;
  padding: 18px;
  margin-bottom: 16px;
  box-shadow: 0 10px 30px rgba(0,0,0,.04);
}

.card-title{
  margin: 0 0 12px 0;
}

/* =========================
   Formularios
   ========================= */

.form-grid{
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.field label{
  margin: 0 0 6px 0;
  font-size: 13px;
}

.form-actions{
  margin-top: 14px;
}

.btn-inline{
  width: auto;
  margin-top: 0;
  padding: 10px 16px;
}

.form-grid-2{
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

/* =========================
   Tablas
   ========================= */

.table{
  width: 100%;
  border-collapse: collapse;
  background: #fff;
}

.table th,
.table td{
  border-bottom: 1px solid #eee;
  padding: 10px;
  text-align: left;
  font-size: 14px;
  vertical-align: top;
}

.table th{
  background: #FAFAFA;
}

/* =========================
   Badges
   ========================= */

.badge{
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  display: inline-block;
}

.badge-ok{
  background: #dcfce7;
  color: #14532d;
  border: 1px solid #bbf7d0;
}

.badge-off{
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

/* =========================
   Responsive
   ========================= */

@media (max-width: 991px){
  .sidebar{
    transform: translateX(-100%);
    width: min(82vw, 300px);
    box-shadow: 0 20px 50px rgba(0,0,0,.18);
  }

  .app-main{
    margin-left: 0;
  }

  body.sidebar-mobile-open .sidebar{
    transform: translateX(0);
  }

  body.sidebar-mobile-open .sidebar-overlay{
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
  }

  .topbar{
    padding: 0 12px;
  }

  .topbar .user-chip{
    display: none;
  }

  .content{
    padding: 18px;
  }

  .form-grid{
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 600px){
  .content{
    padding: 14px;
  }

  .form-grid,
  .form-grid-2{
    grid-template-columns: 1fr;
  }

  .page-wrap{
    margin: 16px auto;
    padding: 0 10px;
  }

  .card{
    padding: 14px;
  }

  .table{
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }
}