:root{
  --sidebar-bg:#241811;
  --sidebar-bg-2:#1c130d;
  --sidebar-text:#c9beb4;
  --sidebar-text-dim:#8a7d72;
  --bg:#f5f2ec;
  --card-bg:#ffffff;
  --ink:#241811;
  --ink-soft:#6b6058;
  --border:#e8e2d8;
  --orange:#e08a3e;
  --orange-2:#d9a441;
  --pink:#e0447a;
  --red:#e2542f;
  --gold:#e0a838;
  --teal:#2aa7a0;
  --purple:#7c5ce0;
  --blue:#2f8fd6;
  --green:#2ba35a;
  --gray:#5a6472;
  --radius:16px;
  font-family:'Inter',system-ui,-apple-system,Segoe UI,Roboto,sans-serif;
}

*{box-sizing:border-box;margin:0;padding:0;}
body{background:var(--bg);color:var(--ink);}

.app{display:flex;min-height:100vh;}

/* ---------- TOPBAR MÓVIL (oculta en escritorio) ---------- */
.topbar{
  display:none;align-items:center;gap:14px;
  padding:14px 18px;background:var(--sidebar-bg);color:#fff;
  position:sticky;top:0;z-index:40;
}
.topbar-burger{
  width:38px;height:38px;border-radius:10px;border:none;background:rgba(255,255,255,.08);
  color:#fff;font-size:18px;cursor:pointer;flex-shrink:0;
}
.topbar-title{font-size:16px;font-weight:800;}
.sidebar-overlay{display:none;}

/* ---------- SIDEBAR ---------- */
.sidebar{
  width:270px;flex-shrink:0;
  background:linear-gradient(180deg,var(--sidebar-bg),var(--sidebar-bg-2));
  color:var(--sidebar-text);
  display:flex;flex-direction:column;
  padding:22px 16px;
}
.brand{display:flex;align-items:center;gap:12px;padding:6px 10px 26px;}
.brand-icon{
  width:44px;height:44px;border-radius:12px;
  background:linear-gradient(135deg,var(--orange),var(--orange-2));
  display:flex;align-items:center;justify-content:center;font-size:22px;
}
.brand-title{font-size:17px;font-weight:800;color:#fff;line-height:1.15;}
.brand-sub{font-size:13px;color:var(--sidebar-text-dim);font-weight:600;}

.nav{display:flex;flex-direction:column;gap:3px;flex:1;overflow-y:auto;}
.nav-item{
  display:flex;align-items:center;gap:12px;
  padding:11px 14px;border-radius:11px;
  color:var(--sidebar-text);text-decoration:none;
  font-size:14.5px;font-weight:600;cursor:pointer;
  border:none;background:none;width:100%;text-align:left;
  position:relative;
}
.nav-item:hover{background:rgba(255,255,255,.06);}
.nav-item.active{background:rgba(224,138,62,.18);color:#fff;}
.nav-item.active::before{
  content:"";position:absolute;left:0;top:8px;bottom:8px;width:3px;
  background:var(--orange);border-radius:3px;
}
.nav-icon{width:20px;text-align:center;font-size:16px;}
.nav-badge{
  margin-left:auto;background:var(--red);color:#fff;font-size:11px;
  font-weight:800;padding:2px 7px;border-radius:20px;
}
.nav-footer{border-top:1px solid rgba(255,255,255,.08);margin-top:10px;padding-top:10px;}

/* ---------- MAIN ---------- */
.main{flex:1;padding:32px 40px;overflow-y:auto;}
.page-header{display:flex;align-items:center;gap:18px;margin-bottom:28px;}
.page-icon{
  width:64px;height:64px;border-radius:16px;flex-shrink:0;
  background:linear-gradient(135deg,var(--orange),var(--orange-2));
  display:flex;align-items:center;justify-content:center;font-size:30px;
  box-shadow:0 8px 18px -6px rgba(224,138,62,.55);
}
.page-title{font-size:30px;font-weight:800;color:var(--ink);}
.page-sub{color:var(--ink-soft);font-size:14.5px;margin-top:2px;}

/* ---------- STAT CARDS ---------- */
.stats-grid{display:grid;grid-template-columns:repeat(4,1fr);gap:18px;margin-bottom:34px;}
.stat-card{
  background:var(--card-bg);border-radius:var(--radius);padding:20px 22px;
  border:1px solid var(--border);
}
.stat-top{display:flex;align-items:flex-start;justify-content:space-between;}
.stat-label{font-size:12px;font-weight:800;letter-spacing:.04em;color:var(--ink-soft);text-transform:uppercase;}
.stat-icon{width:38px;height:38px;border-radius:10px;display:flex;align-items:center;justify-content:center;font-size:17px;color:#fff;}
.stat-value{font-size:32px;font-weight:800;margin-top:12px;}
.stat-foot{font-size:13px;color:var(--ink-soft);margin-top:2px;}

/* ---------- MODULES GRID ---------- */
.section-title{font-size:20px;font-weight:800;margin-bottom:16px;}
.modules-grid{display:grid;grid-template-columns:repeat(4,1fr);gap:18px;margin-bottom:34px;}
.module-card{
  background:var(--card-bg);border:1px solid var(--border);border-radius:var(--radius);
  padding:22px;cursor:pointer;transition:transform .12s ease, box-shadow .12s ease;
}
.module-card:hover{transform:translateY(-2px);box-shadow:0 10px 24px -10px rgba(36,24,17,.18);}
.module-icon{width:46px;height:46px;border-radius:12px;display:flex;align-items:center;justify-content:center;font-size:21px;color:#fff;margin-bottom:14px;}
.module-name{font-size:16.5px;font-weight:800;}
.module-desc{font-size:13.5px;color:var(--ink-soft);margin-top:2px;}

/* ---------- BOTTOM PANELS ---------- */
.panels-grid{display:grid;grid-template-columns:1fr 1fr;gap:18px;}
.panel{background:var(--card-bg);border:1px solid var(--border);border-radius:var(--radius);padding:20px 22px;}
.panel-title{display:flex;align-items:center;gap:9px;font-weight:800;font-size:15.5px;margin-bottom:14px;}
.list-row{display:flex;align-items:center;gap:12px;padding:10px 0;border-bottom:1px solid var(--border);}
.list-row:last-child{border-bottom:none;}
.list-row-icon{width:34px;height:34px;border-radius:9px;display:flex;align-items:center;justify-content:center;font-size:15px;flex-shrink:0;}
.list-row-title{font-weight:700;font-size:14px;}
.list-row-sub{font-size:12.5px;color:var(--ink-soft);}
.list-row-date{margin-left:auto;font-size:12.5px;color:var(--ink-soft);white-space:nowrap;}
.dot-red{width:8px;height:8px;background:var(--red);border-radius:50%;flex-shrink:0;}
.chip{font-size:11px;font-weight:800;padding:3px 9px;border-radius:20px;background:#f0ece3;color:var(--ink-soft);margin-left:8px;}

/* ---------- GENERIC MODULE VIEW (tabla + formulario) ---------- */
.toolbar{display:flex;align-items:center;gap:12px;margin-bottom:18px;}
.search-input{
  flex:1;max-width:340px;padding:11px 14px;border-radius:11px;border:1px solid var(--border);
  background:#fff;font-size:14px;
}
.btn{
  padding:11px 18px;border-radius:11px;border:none;font-weight:700;font-size:14px;cursor:pointer;
}
.btn-primary{background:var(--orange);color:#fff;}
.btn-primary:hover{filter:brightness(1.05);}
.btn-secondary{background:#fff;border:1px solid var(--border);color:var(--ink);}
.btn-danger{background:#fce9e4;color:var(--red);}

.table-wrap{background:var(--card-bg);border:1px solid var(--border);border-radius:var(--radius);overflow:hidden;}
table{width:100%;border-collapse:collapse;}
th{text-align:left;font-size:12px;text-transform:uppercase;letter-spacing:.04em;color:var(--ink-soft);
   background:#faf8f4;padding:12px 16px;border-bottom:1px solid var(--border);}
td{padding:13px 16px;font-size:14px;border-bottom:1px solid var(--border);}
tr:last-child td{border-bottom:none;}
tr:hover td{background:#faf8f4;}
.row-actions{display:flex;gap:8px;}
.icon-btn{width:30px;height:30px;border-radius:8px;border:1px solid var(--border);background:#fff;cursor:pointer;font-size:13px;}
.empty-state{padding:60px 20px;text-align:center;color:var(--ink-soft);}

.modal-backdrop{position:fixed;inset:0;background:rgba(36,24,17,.45);display:flex;align-items:center;justify-content:center;z-index:50;}
.modal{background:#fff;border-radius:18px;padding:26px;width:460px;max-height:86vh;overflow-y:auto;}
.modal h3{font-size:19px;font-weight:800;margin-bottom:18px;}
.form-field{margin-bottom:14px;}
.form-field label{display:block;font-size:12.5px;font-weight:700;color:var(--ink-soft);margin-bottom:5px;text-transform:uppercase;letter-spacing:.03em;}
.form-field input,.form-field select,.form-field textarea{
  width:100%;padding:10px 12px;border-radius:10px;border:1px solid var(--border);font-size:14px;font-family:inherit;
}
.modal-actions{display:flex;justify-content:flex-end;gap:10px;margin-top:20px;}

.badge{padding:4px 10px;border-radius:20px;font-size:12px;font-weight:700;}
.badge-green{background:#e5f5ea;color:var(--green);}
.badge-red{background:#fce9e4;color:var(--red);}
.badge-gold{background:#fbf1de;color:var(--gold);}
.badge-gray{background:#eef0f2;color:var(--gray);}

.toast{position:fixed;bottom:26px;right:26px;background:var(--ink);color:#fff;padding:13px 20px;border-radius:11px;font-size:14px;font-weight:600;z-index:100;}

/* ---------- BUSCADOR TYPEAHEAD (searchable-select) ---------- */
.ss-wrap{position:relative;}
.ss-input{width:100%;padding:10px 12px;border-radius:10px;border:1px solid var(--border);font-size:14px;font-family:inherit;}
.ss-results{
  display:none;position:absolute;top:calc(100% + 4px);left:0;right:0;z-index:20;
  background:#fff;border:1px solid var(--border);border-radius:10px;max-height:200px;overflow-y:auto;
  box-shadow:0 10px 24px -8px rgba(36,24,17,.25);
}
.ss-results.open{display:block;}
.ss-item{padding:9px 12px;font-size:13.5px;cursor:pointer;}
.ss-item:hover{background:#faf8f4;}
.ss-empty{padding:10px 12px;font-size:13px;color:var(--ink-soft);}

/* ---------- BUSCADOR GLOBAL (sidebar) ---------- */
.global-search-wrap{position:relative;padding:0 10px 16px;}
.global-search-input{
  width:100%;padding:10px 12px;border-radius:10px;border:1px solid rgba(255,255,255,.12);
  background:rgba(255,255,255,.06);color:#fff;font-size:13.5px;font-family:inherit;
}
.global-search-input::placeholder{color:var(--sidebar-text-dim);}
.global-search-results{
  display:none;position:absolute;top:calc(100% - 10px);left:10px;right:10px;z-index:70;
  background:#fff;border-radius:10px;max-height:280px;overflow-y:auto;
  box-shadow:0 16px 32px -8px rgba(0,0,0,.4);
}
.global-search-results.open{display:block;}
.gs-item{padding:10px 12px;font-size:13.5px;cursor:pointer;border-bottom:1px solid var(--border);color:var(--ink);}
.gs-item:last-child{border-bottom:none;}
.gs-item:hover{background:#faf8f4;}
.gs-tag{display:inline-block;font-size:10px;font-weight:800;text-transform:uppercase;color:var(--ink-soft);margin-right:6px;}
.gs-sub{display:block;font-size:12px;color:var(--ink-soft);}
.gs-empty{padding:12px;font-size:13px;color:var(--ink-soft);}

/* ---------- RESPONSIVE ---------- */
@media (max-width:1100px){
  .stats-grid,.modules-grid{grid-template-columns:repeat(2,1fr);}
  .panels-grid{grid-template-columns:1fr;}
}

@media (max-width:860px){
  .app{flex-direction:column;}
  .topbar{display:flex;}
  .sidebar{
    position:fixed;left:-290px;top:0;bottom:0;width:270px;z-index:60;
    transition:left .22s ease;box-shadow:0 0 40px rgba(0,0,0,.35);
  }
  .sidebar.open{left:0;}
  .sidebar-overlay.open{
    display:block;position:fixed;inset:0;background:rgba(0,0,0,.4);z-index:55;
  }
  .main{padding:18px;}
  .page-header{gap:12px;margin-bottom:20px;}
  .page-icon{width:52px;height:52px;font-size:24px;border-radius:13px;}
  .page-title{font-size:23px;}
  .stats-grid,.modules-grid{grid-template-columns:repeat(2,1fr);gap:12px;}
  .toolbar{flex-wrap:wrap;}
  .search-input{max-width:none;min-width:0;}
}

@media (max-width:600px){
  .stats-grid,.modules-grid{grid-template-columns:1fr;}
  .stat-value{font-size:26px;}

  /* Tablas: en pantallas chicas se apilan como tarjetas en vez de scrollear horizontal */
  .table-wrap table, .table-wrap thead, .table-wrap tbody, .table-wrap th, .table-wrap td, .table-wrap tr{
    display:block;width:100%;
  }
  .table-wrap thead{display:none;}
  .table-wrap tr{border-bottom:1px solid var(--border);padding:12px 16px;}
  .table-wrap tr:last-child{border-bottom:none;}
  .table-wrap td{
    border-bottom:none;padding:6px 0;display:flex;justify-content:space-between;gap:12px;
    font-size:13.5px;text-align:right;
  }
  .table-wrap td::before{
    content:attr(data-label);font-weight:700;color:var(--ink-soft);text-align:left;
    text-transform:uppercase;font-size:11px;letter-spacing:.03em;
  }
  .table-wrap td.row-actions{justify-content:flex-end;}
  .table-wrap td.row-actions::before{content:none;}

  .modal-backdrop{align-items:flex-end;}
  .modal{
    width:100%;max-width:100%;border-radius:18px 18px 0 0;max-height:92vh;
    padding-bottom:calc(20px + env(safe-area-inset-bottom));
  }
  .panel{padding:16px 18px;}
}
