/* ═══════════════════════════════════════════════
   COMPONENTS.CSS — Botones, Cards, Tablas, Modales
   SharpRestore v1.1.2
═══════════════════════════════════════════════ */

/* ── BOTONES ─────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .45rem 1rem; border-radius: var(--radius-sm);
  font-size: .84rem; font-weight: 500; border: 1px solid transparent;
  cursor: pointer; transition: all var(--t); white-space: nowrap;
  font-family: var(--font-body); text-decoration: none;
}
.btn-primary  { background: var(--p1); color: #111; border-color: var(--p1); }
.btn-primary:hover { background: #d4aa00; border-color: #d4aa00; }
.btn-secondary { background: transparent; color: var(--text2); border-color: var(--border); }
.btn-secondary:hover { background: var(--bg4); color: var(--text); border-color: rgba(255,255,255,.15); }
.btn-danger   { background: rgba(224,112,96,.15); color: var(--err); border-color: rgba(224,112,96,.3); }
.btn-danger:hover { background: rgba(224,112,96,.25); }
.btn-success  { background: rgba(90,158,111,.15); color: var(--ok); border-color: rgba(90,158,111,.3); }
.btn-success:hover { background: rgba(90,158,111,.25); }
.btn-sm  { padding: .3rem .65rem; font-size: .78rem; }
.btn-icon { width: 32px; height: 32px; padding: 0; justify-content: center; }
.btn:disabled { opacity: .45; cursor: not-allowed; pointer-events: none; }

/* ── KPI CARDS ───────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem; margin-bottom: 1.5rem;
}
.kpi-card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.1rem 1.25rem;
  position: relative; overflow: hidden;
  transition: transform var(--t), box-shadow var(--t);
  --kpi-color: var(--p1);
}
.kpi-card::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 2px;
  background: var(--kpi-color);
}
.kpi-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.kpi-label { font-size: .72rem; font-family: var(--font-mono); color: var(--text3);
             letter-spacing: 1.5px; text-transform: uppercase; margin-bottom: .35rem; }
.kpi-val   { font-family: var(--font-head); font-size: 2rem; color: var(--kpi-color);
             line-height: 1; margin-bottom: .25rem; letter-spacing: 1px; }
.kpi-sub   { font-size: .75rem; color: var(--text3); }
.kpi-icon  { position: absolute; right: 1rem; top: 50%; transform: translateY(-50%);
             font-size: 2rem; opacity: .08; }

/* ── PANEL ───────────────────────────────────── */
.panel {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: .85rem 1.25rem; border-bottom: 1px solid var(--border);
}
.panel-title { font-size: .9rem; font-weight: 600; color: var(--text); }
.panel-body  { padding: 1rem 1.25rem; }

/* ── TABLA ───────────────────────────────────── */
.tbl-wrap { overflow-x: auto; }
.tbl {
  width: 100%; border-collapse: collapse; font-size: .84rem;
}
.tbl th {
  background: var(--bg3); color: var(--text3); font-family: var(--font-mono);
  font-size: .7rem; letter-spacing: 1.5px; text-transform: uppercase;
  padding: .65rem 1rem; text-align: left; border-bottom: 1px solid var(--border);
  font-weight: 500; white-space: nowrap;
}
.tbl td {
  padding: .7rem 1rem; border-bottom: 1px solid var(--border2);
  color: var(--text2); vertical-align: middle;
}
.tbl tr:last-child td { border-bottom: none; }
.tbl tbody tr:hover td { background: rgba(255,255,255,.025); }
.tbl .actions { display: flex; gap: .4rem; justify-content: flex-end; }

/* ── BADGES ──────────────────────────────────── */
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 20px;
  font-size: .68rem; font-family: var(--font-mono); font-weight: 600;
  letter-spacing: .5px; text-transform: uppercase; line-height: 1.5;
}
.badge-ok      { background: rgba(90,158,111,.2);   color: var(--ok); }
.badge-warn    { background: rgba(200,160,0,.2);    color: var(--warn); }
.badge-err     { background: rgba(224,112,96,.2);   color: var(--err); }
.badge-info    { background: rgba(58,127,168,.2);   color: var(--info); }
.badge-neutral { background: rgba(255,255,255,.08); color: var(--text2); }

/* Stock badges */
.stock-ok   { color: var(--ok);   font-family: var(--font-mono); font-size: .82rem; font-weight: 700; }
.stock-low  { color: var(--warn); font-family: var(--font-mono); font-size: .82rem; font-weight: 700; }
.stock-zero { color: var(--err);  font-family: var(--font-mono); font-size: .82rem; font-weight: 700; }

/* Priority */
.prio-critica { color: var(--err);  font-weight: 600; font-size: .8rem; }
.prio-alta    { color: var(--warn); font-weight: 600; font-size: .8rem; }
.prio-media   { color: var(--info); font-weight: 600; font-size: .8rem; }
.prio-baja    { color: var(--text3);font-weight: 600; font-size: .8rem; }

/* ── FORM ────────────────────────────────────── */
.form-group { margin-bottom: 1rem; }
.form-label {
  display: block; font-size: .78rem; font-family: var(--font-mono);
  color: var(--text3); letter-spacing: 1px; text-transform: uppercase;
  margin-bottom: .4rem;
}
.form-input, .form-select, .form-textarea {
  width: 100%; background: var(--bg3); border: 1px solid var(--border);
  color: var(--text); border-radius: var(--radius-sm); padding: .55rem .85rem;
  font-size: .875rem; transition: border-color var(--t), box-shadow var(--t);
  outline: none;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--p1); box-shadow: 0 0 0 3px rgba(200,160,0,.12);
}
.form-input::placeholder { color: var(--text3); }
.form-select { appearance: none; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%234a6480' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right .75rem center; padding-right: 2.5rem;
}
.form-select option { background: var(--bg3); }
.form-textarea { resize: vertical; min-height: 90px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }

/* ── MODAL ───────────────────────────────────── */
.modal-backdrop {
  display: none; position: fixed; inset: 0; z-index: 500;
  background: rgba(0,0,0,.75); backdrop-filter: blur(4px);
  align-items: center; justify-content: center; padding: 1rem;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius-lg); width: 100%; max-width: 560px;
  max-height: 90vh; display: flex; flex-direction: column;
  animation: slideUp .2s ease; box-shadow: var(--shadow-lg);
}
@keyframes slideUp { from { opacity:0; transform: translateY(24px); } to { opacity:1; transform:none; } }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1.1rem 1.5rem; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.modal-title { font-size: 1rem; font-weight: 600; color: var(--text); }
.modal-close {
  background: none; border: none; color: var(--text3); font-size: 1.3rem;
  width: 30px; height: 30px; display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm); transition: all var(--t);
}
.modal-close:hover { background: var(--bg4); color: var(--text); }
.modal-body   { padding: 1.5rem; overflow-y: auto; flex: 1; }
.modal-footer {
  display: flex; justify-content: flex-end; gap: .75rem;
  padding: 1rem 1.5rem; border-top: 1px solid var(--border); flex-shrink: 0;
}

/* ── PERMISOS ────────────────────────────────── */
.perm-header {
  margin-bottom: 1.5rem; padding-bottom: 1rem; border-bottom: 1px solid var(--border);
}
.perm-header h3 { color: var(--text); font-size: 1.1rem; margin: 0; }
.perm-header p { margin: .5rem 0 0; color: var(--text3); font-size: .85rem; }

.perm-categories {
  display: flex; flex-direction: column; gap: 1.25rem;
}

.perm-category {
  border: 1px solid var(--border2); border-radius: var(--radius);
  overflow: hidden;
}

.perm-cat-title {
  background: var(--bg3); padding: .75rem 1rem;
  font-weight: 600; color: var(--text2); font-size: .87rem;
  display: flex; align-items: center; gap: .5rem;
}

.perm-list {
  display: flex; flex-direction: column;
  max-height: 320px; overflow-y: auto;
}

.perm-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: .75rem 1rem; border-bottom: 1px solid var(--border2);
  transition: background var(--t);
}
.perm-item:last-child { border-bottom: none; }
.perm-item:hover { background: rgba(255,255,255,.02); }

.perm-info {
  flex: 1;
}

.perm-nombre {
  font-weight: 500; color: var(--text); font-size: .88rem; margin-bottom: .3rem;
}

.perm-meta {
  display: flex; align-items: center; gap: .5rem; font-size: .75rem;
}

.perm-from {
  display: inline-flex; align-items: center; gap: .3rem;
  padding: 2px 6px; border-radius: 4px; background: var(--bg3);
  color: var(--text3); font-family: var(--font-mono);
}

.perm-from.override {
  background: rgba(200,160,0,.12); color: var(--warn);
}

.perm-from.rol {
  background: rgba(58,127,168,.12); color: var(--info);
}

.perm-control {
  flex-shrink: 0; margin-left: 1rem;
}

.toggle {
  display: inline-flex; align-items: center; cursor: pointer;
  position: relative; width: 44px; height: 24px;
}

.toggle input {
  display: none;
}

.toggle-slider {
  position: absolute; top: 0; left: 0; right: 0; bottom: 0;
  background: var(--border2); border-radius: 12px;
  transition: background var(--t), box-shadow var(--t);
  display: flex; align-items: center;
}

.toggle-slider::after {
  content: ''; position: absolute; left: 2px; top: 2px;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--bg3); transition: transform var(--t);
}

.toggle input:checked + .toggle-slider {
  background: var(--ok); box-shadow: inset 0 0 8px rgba(90,158,111,.3);
}

.toggle input:checked + .toggle-slider::after {
  transform: translateX(20px);
}

.perm-footer {
  display: flex; gap: .5rem; margin-top: 1.5rem;
}

/* ── TOASTS ──────────────────────────────────── */
#toast-container {
  position: fixed; bottom: 1.5rem; right: 1.5rem; z-index: 9999;
  display: flex; flex-direction: column; gap: .5rem; pointer-events: none;
}
.toast {
  background: var(--bg4); border: 1px solid var(--border);
  border-radius: var(--radius); padding: .75rem 1.1rem;
  font-size: .84rem; color: var(--text); box-shadow: var(--shadow-md);
  display: flex; align-items: center; gap: .6rem;
  animation: toastIn .25s ease; pointer-events: auto; min-width: 260px;
}
@keyframes toastIn { from { opacity:0; transform: translateX(20px); } to { opacity:1; transform:none; } }
.toast.out { animation: toastOut .25s ease forwards; }
@keyframes toastOut { to { opacity:0; transform: translateX(20px); } }
.toast-ok   { border-left: 3px solid var(--ok);   }
.toast-err  { border-left: 3px solid var(--err);  }
.toast-warn { border-left: 3px solid var(--warn); }
.toast-info { border-left: 3px solid var(--info); }

/* ── SEARCH BAR ──────────────────────────────── */
.search-bar {
  display: flex; align-items: center; gap: .75rem;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: .45rem .85rem;
  flex: 1; max-width: 340px;
}
.search-bar i { color: var(--text3); font-size: .9rem; flex-shrink: 0; }
.search-bar input {
  background: none; border: none; color: var(--text); flex: 1;
  font-size: .84rem; outline: none;
}
.search-bar input::placeholder { color: var(--text3); }

/* ── PAGINATION ──────────────────────────────── */
.pagination {
  display: flex; align-items: center; gap: .4rem;
  justify-content: flex-end; padding: .75rem 1.25rem;
  border-top: 1px solid var(--border2); font-size: .82rem;
}
.page-btn {
  background: none; border: 1px solid var(--border); color: var(--text2);
  width: 30px; height: 30px; border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: .8rem; transition: all var(--t);
}
.page-btn:hover  { background: var(--bg4); color: var(--text); }
.page-btn.active { background: rgba(200,160,0,.15); border-color: var(--p1); color: var(--p1); }
.page-btn:disabled { opacity: .35; cursor: not-allowed; }
.page-info { color: var(--text3); font-family: var(--font-mono); font-size: .75rem; margin: 0 .5rem; }

/* ── EMPTY STATE ─────────────────────────────── */
.empty-state {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; padding: 3rem 1rem; color: var(--text3);
  gap: .75rem; text-align: center;
}
.empty-state i    { font-size: 2.5rem; opacity: .4; }
.empty-state p    { font-size: .9rem; }
.empty-state span { font-size: .8rem; color: var(--text3); font-family: var(--font-mono); }

/* ── SPINNER ─────────────────────────────────── */
.spinner {
  width: 20px; height: 20px; border-radius: 50%;
  border: 2px solid var(--border); border-top-color: var(--p1);
  animation: spin .7s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── CHIP / TAG ──────────────────────────────── */
.chip {
  display: inline-flex; align-items: center; gap: .3rem;
  background: var(--bg4); border: 1px solid var(--border);
  border-radius: 20px; padding: 2px 10px; font-size: .75rem; color: var(--text2);
}

/* ── SECTION HEADER ──────────────────────────── */
.section-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1rem; gap: 1rem; flex-wrap: wrap;
}
.section-title { font-size: 1rem; font-weight: 600; color: var(--text); }

/* ── NOTIFICACIONES DROPDOWN ─────────────────── */
.notif-dropdown {
  position: absolute; top: calc(100% + 8px); right: 0;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); width: 320px; z-index: 600;
  box-shadow: var(--shadow-lg); overflow: hidden;
  animation: slideUp .15s ease;
}
.notif-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: .75rem 1rem; border-bottom: 1px solid var(--border);
  font-size: .85rem; font-weight: 600;
}
.notif-list { max-height: 320px; overflow-y: auto; }
.notif-item {
  display: flex; gap: .75rem; padding: .75rem 1rem;
  border-bottom: 1px solid var(--border2); cursor: pointer;
  transition: background var(--t);
}
.notif-item:hover { background: var(--bg3); }
.notif-item.unread { background: rgba(200,160,0,.04); }
.notif-dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--p1);
  flex-shrink: 0; margin-top: .35rem;
}
.notif-item p { font-size: .82rem; color: var(--text); margin-bottom: .15rem; }
.notif-item span { font-size: .72rem; color: var(--text3); font-family: var(--font-mono); }

/* ── BOTONES EXTRA ───────────────────────────── */
.btn-warning { background: rgba(224,160,32,.15); color: var(--warn); border-color: rgba(224,160,32,.3); }
.btn-warning:hover { background: rgba(224,160,32,.28); }
.btn-ok      { background: rgba(40,160,98,.15);  color: var(--ok);   border-color: rgba(40,160,98,.3); }
.btn-ok:hover { background: rgba(40,160,98,.28); }

/* ── REPORTES — Tabs de módulo ───────────────── */
.rep-tab {
  background: none; border: none; border-bottom: 2px solid transparent;
  padding: .55rem .85rem; font-size: .82rem; font-weight: 600;
  color: var(--text2); cursor: pointer; transition: color .2s, border-color .2s;
  white-space: nowrap;
}
.rep-tab:hover { color: var(--text); }
.rep-tab.active { color: var(--p1); border-bottom-color: var(--p1); }

/* ── FACTURACIÓN — Autocomplete cliente ──────── */
.fac-autocomplete-wrap { position: relative; }
.fac-autocomplete-dropdown {
  position: absolute; top: 100%; left: 0; right: 0; z-index: 300;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
  max-height: 220px; overflow-y: auto;
}
.fac-autocomplete-item {
  display: flex; align-items: center; gap: .6rem;
  padding: .55rem .85rem; cursor: pointer; transition: background .15s;
  border-bottom: 1px solid var(--border2); font-size: .84rem;
}
.fac-autocomplete-item:last-child { border-bottom: none; }
.fac-autocomplete-item:hover { background: var(--bg3); }

/* ── FACTURACIÓN — Buscador de items ─────────── */
.fac-result-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: .55rem .85rem; cursor: pointer; border-bottom: 1px solid var(--border2);
  transition: background .15s; font-size: .84rem;
}
.fac-result-item:last-child { border-bottom: none; }
.fac-result-item:hover { background: var(--bg3); }

/* ── NOTIFICACIONES — Vista full ─────────────── */
.notif-view-item {
  display: flex; align-items: flex-start; gap: .75rem;
  padding: .85rem 1rem; border-bottom: 1px solid var(--border2);
  transition: background .15s;
}
.notif-view-item.unread { background: rgba(200,160,0,.04); }
.notif-type-icon {
  width: 32px; height: 32px; border-radius: 8px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: .85rem;
}
.notif-type-icon.error   { background: rgba(192,48,48,.15);  color: var(--err); }
.notif-type-icon.warn    { background: rgba(224,160,32,.15); color: var(--warn); }
.notif-type-icon.success { background: rgba(40,160,98,.15);  color: var(--ok); }
.notif-type-icon.info    { background: rgba(32,96,200,.15);  color: #60a0e8; }

/* ── Errores: truncate + expand ─────────────────────────────── */
.err-code   { color:var(--p1); font-size:.8rem; font-family:monospace; letter-spacing:.04em; }
.err-modelo { font-weight:600; color:var(--text1); font-size:.88rem; }
.err-desc-cell,
.err-sol-cell  { max-width:260px; font-size:.82rem; line-height:1.45; }
.err-sol-cell  { color:var(--ok); }

/* Trunc logic */
.err-trunc-wrap .err-full      { display:none; }
.err-trunc-wrap .err-short     { display:inline; }
.err-trunc-wrap.err-open .err-full  { display:inline; }
.err-trunc-wrap.err-open .err-short { display:none; }
.err-expand-btn {
  background:none; border:none; cursor:pointer;
  color:var(--p1); font-size:.75rem; padding:0 2px;
  text-decoration:underline dotted; white-space:nowrap;
}
.err-expand-btn:hover { color:var(--gold); }

/* Detail panel */
#err-detail-panel {
  display:none;
  background:var(--bg2); border:1px solid var(--border);
  border-radius:var(--radius); margin-top:1rem; padding:1.25rem 1.5rem;
}
.err-detail-header {
  display:flex; align-items:center; gap:.5rem;
  border-bottom:1px solid var(--border); padding-bottom:.75rem; margin-bottom:.75rem;
}
.err-detail-label {
  font-size:.75rem; font-weight:700; text-transform:uppercase;
  letter-spacing:.06em; color:var(--text3); margin-bottom:.35rem;
}
.err-detail-text {
  font-size:.88rem; line-height:1.65; color:var(--text1);
  white-space:pre-wrap; word-break:break-word;
}
.err-sol-full { color:var(--ok); }
.err-detail-section {
  background:var(--bg3); border-radius:6px;
  padding:.85rem 1rem; border-left:3px solid var(--border2);
}
