/* app/theme/components.css — componentes base */

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 12px; border-radius: var(--r-sm);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font-size: var(--fs-sm); font-weight: 500; white-space: nowrap; user-select: none;
  transition: background .12s, border-color .12s, transform .05s, box-shadow .12s;
}
.btn:hover { background: var(--surface-2); border-color: var(--text-3); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--c-primary); border-color: var(--c-primary); color: #fff; }
.btn-primary:hover { background: var(--c-primary-600); border-color: var(--c-primary-600); }
.btn-accent { background: var(--c-accent); border-color: var(--c-accent); color: #1a1a1a; }
.btn-accent:hover { background: var(--c-accent-700); border-color: var(--c-accent-700); }
.btn-danger { background: var(--c-danger); border-color: var(--c-danger); color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-3); color: var(--text); border-color: transparent; }
.btn-sm { height: 28px; padding: 0 8px; font-size: var(--fs-xs); }
.btn-xs { height: 24px; padding: 0 6px; font-size: var(--fs-xs); }
.btn-icon { width: 34px; padding: 0; }
.btn-icon.btn-sm { width: 28px; }
.btn-icon.btn-xs { width: 24px; }
.btn.active { background: var(--c-primary-100); border-color: var(--c-primary); color: var(--c-primary); }
:root[data-theme="dark"] .btn.active { color: #9be0b8; }

.seg { display: inline-flex; background: var(--surface-3); border-radius: var(--r-sm); padding: 2px; gap: 2px; }
.seg .btn { height: 26px; border: none; background: transparent; box-shadow: none; }
.seg .btn.active { background: var(--surface); box-shadow: var(--sh-1); color: var(--text); }

/* ---------- Campos ---------- */
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > label { font-size: var(--fs-xs); font-weight: 600; color: var(--text-2); letter-spacing: .02em; }
.input, .select, .textarea {
  height: 34px; padding: 0 10px; border-radius: var(--r-sm); border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); font-size: var(--fs-sm); width: 100%; min-width: 0;
}
.textarea { height: auto; min-height: 70px; padding: 8px 10px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--c-primary); box-shadow: var(--focus); outline: none; }
.input::placeholder { color: var(--text-3); }
.input-sm { height: 28px; font-size: var(--fs-xs); }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: var(--fs-sm); cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--c-primary); margin: 0; }
.search { position: relative; }
.search .icon { position: absolute; left: 9px; top: 50%; transform: translateY(-50%); color: var(--text-3); pointer-events: none; }
.search .input { padding-left: 30px; }

/* ---------- Tarjetas y paneles ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); box-shadow: var(--sh-1); }
.panel { display: flex; flex-direction: column; min-height: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); box-shadow: var(--sh-1); overflow: hidden; }
.panel-head { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--border); background: var(--surface); min-height: 44px; flex: 0 0 auto; }
.panel-head h3 { font-size: var(--fs-md); font-weight: 600; }
.panel-body { flex: 1 1 auto; min-height: 0; overflow: auto; }
.panel-foot { padding: 8px 12px; border-top: 1px solid var(--border); flex: 0 0 auto; }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); padding: 0 8px; background: var(--surface); flex: 0 0 auto; }
.tab { position: relative; white-space: nowrap; padding: 10px 12px; font-size: var(--fs-sm); font-weight: 500; color: var(--text-2); cursor: pointer; border: none; background: none; display: inline-flex; align-items: center; gap: 6px; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--c-primary); }
.tab.active::after { content: ""; position: absolute; left: 8px; right: 8px; bottom: -1px; height: 2px; background: var(--c-primary); border-radius: 2px; }
:root[data-theme="dark"] .tab.active { color: #9be0b8; }
.tab .count { background: var(--surface-3); color: var(--text-2); border-radius: var(--r-pill); padding: 0 7px; font-size: var(--fs-xs); font-weight: 600; min-width: 20px; text-align: center; }
.tab.active .count { background: var(--c-primary-100); color: var(--c-primary); }

/* ---------- Badges / chips ---------- */
.badge { display: inline-flex; align-items: center; gap: 4px; height: 20px; padding: 0 8px; border-radius: var(--r-pill); font-size: var(--fs-xs); font-weight: 600; white-space: nowrap; background: var(--surface-3); color: var(--text-2); }
.badge-ok { background: #e3f5ea; color: #1b6b3a; }
.badge-warn { background: #fff4cc; color: #7a5c00; }
.badge-danger { background: #fde7e7; color: #a12a2a; }
.badge-info { background: #e4edfd; color: #1f4fa8; }
.badge-purple { background: #f0e4f7; color: #6a2c85; }
.badge-accent { background: var(--c-accent); color: #1a1a1a; }
:root[data-theme="dark"] .badge-ok { background: #16402a; color: #8fdcae; }
:root[data-theme="dark"] .badge-warn { background: #3f3610; color: #ffd966; }
:root[data-theme="dark"] .badge-danger { background: #4a1d1d; color: #ff9a9a; }
:root[data-theme="dark"] .badge-info { background: #1a2d54; color: #9bbcff; }
:root[data-theme="dark"] .badge-purple { background: #35204a; color: #d9a8f0; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: 0 0 auto; }
.dot-ok { background: var(--c-ok); } .dot-warn { background: var(--c-warn); } .dot-danger { background: var(--c-danger); } .dot-off { background: var(--c-op-offline); }
.dot-live { animation: dot-live 1.8s infinite; }
@keyframes dot-live { 0% { box-shadow: 0 0 0 0 rgba(46,158,91,.55); } 70% { box-shadow: 0 0 0 7px rgba(46,158,91,0); } 100% { box-shadow: 0 0 0 0 rgba(46,158,91,0); } }

/* ---------- KPI ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: var(--sp-3); }
.kpi { display: flex; flex-direction: column; gap: 2px; padding: 12px 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); box-shadow: var(--sh-1); position: relative; overflow: hidden; }
.kpi::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--kpi-color, var(--c-primary)); }
.kpi .kpi-label { font-size: var(--fs-xs); font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); }
.kpi .kpi-value { font-size: var(--fs-2xl); font-weight: 700; line-height: 1.1; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.kpi .kpi-sub { font-size: var(--fs-xs); color: var(--text-2); }
.kpi .icon { position: absolute; right: 12px; top: 12px; color: var(--kpi-color, var(--c-primary)); opacity: .55; }

/* ---------- Estados vacíos ---------- */
.empty { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; padding: 32px 16px; text-align: center; color: var(--text-2); }
.empty .icon-xl { color: var(--text-3); }
.empty h4 { font-size: var(--fs-md); font-weight: 600; color: var(--text); }
.spinner { width: 22px; height: 22px; border: 3px solid var(--border-strong); border-top-color: var(--c-primary); border-radius: 50%; animation: spin .8s linear infinite; }

/* ---------- Modal / Drawer ---------- */
.overlay { position: fixed; inset: 0; background: rgba(10, 14, 12, .45); backdrop-filter: blur(2px); z-index: 900; display: flex; align-items: center; justify-content: center; animation: fade-in .12s; }
.modal { background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--sh-3); width: min(var(--modal-w, 760px), calc(100vw - 32px)); max-height: calc(100vh - 32px); display: flex; flex-direction: column; overflow: hidden; }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.modal-head h2 { font-size: var(--fs-lg); flex: 1; }
.modal-body { padding: 18px; overflow: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--border); background: var(--surface-2); }
.drawer-overlay { position: fixed; inset: 0; z-index: 890; background: rgba(10,14,12,.25); }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(var(--drawer-w, 420px), 100vw); background: var(--surface); box-shadow: var(--sh-3); z-index: 895; display: flex; flex-direction: column; animation: slide-in-right .18s ease-out; }
@media (max-width: 767px) {
  .modal { width: 100vw; max-height: 100vh; border-radius: 0; height: 100vh; }
  .overlay { align-items: stretch; }
  .drawer { width: 100vw; }
}

/* ---------- Toast ---------- */
.toasts { position: fixed; left: 50%; transform: translateX(-50%); top: calc(var(--topbar-h) + 10px); z-index: 999; display: flex; flex-direction: column; align-items: center; gap: 8px; width: max-content; max-width: min(460px, calc(100vw - 32px)); }
.toast { display: flex; align-items: flex-start; gap: 10px; padding: 10px 12px; background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--c-info); border-radius: var(--r-md); box-shadow: var(--sh-2); font-size: var(--fs-sm); animation: fade-in .18s; }
.toast-ok { border-left-color: var(--c-ok); } .toast-warn { border-left-color: var(--c-warn); } .toast-danger { border-left-color: var(--c-danger); }
.toast .icon { margin-top: 1px; }
.toast-ok .icon { color: var(--c-ok); } .toast-warn .icon { color: var(--c-warn); } .toast-danger .icon { color: var(--c-danger); } .toast-info .icon { color: var(--c-info); }

/* ---------- Tabla simple ---------- */
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.table th { text-align: left; font-size: var(--fs-xs); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--text-3); padding: 8px 10px; border-bottom: 1px solid var(--border); background: var(--surface-2); position: sticky; top: 0; }
.table td { padding: 7px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tr:hover td { background: var(--surface-2); }

/* ---------- Página con toolbar (patrón de reportes) ---------- */
.page { display: flex; flex-direction: column; height: 100%; min-height: 0; padding: var(--sp-4); gap: var(--sp-3); }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.page-head h1 { font-size: var(--fs-xl); }
.page-head .sub { color: var(--text-2); font-size: var(--fs-sm); }
.toolbar { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; padding: 10px 12px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); box-shadow: var(--sh-1); }
.toolbar .spacer { flex: 1; }
.grid-host { flex: 1 1 auto; min-height: 300px; border: 1px solid var(--border); border-radius: var(--r-md); overflow: hidden; background: var(--surface); box-shadow: var(--sh-1); }
@media (max-width: 767px) { .page { padding: var(--sp-3); } .toolbar .btn-text { display: none; } }

/* ---------- Tooltip simple ---------- */
[data-tip] { position: relative; }
[data-tip]:hover::after { content: attr(data-tip); position: absolute; left: 50%; top: calc(100% + 6px); transform: translateX(-50%); background: #1a1f24; color: #fff; font-size: var(--fs-xs); padding: 4px 8px; border-radius: 4px; white-space: nowrap; z-index: 50; pointer-events: none; }
