/* ═══════════════════════════════════════════════════════════
   SERNYC CMMS v2.0 — Custom styles on top of Bootstrap 5
   ═══════════════════════════════════════════════════════════ */

/* ── Base ── */
:root {
  --sidebar-width: 240px;
  --topbar-height: 56px;
  --sidebar-bg: #0f1117;
  --sidebar-bg-hover: rgba(255,255,255,0.06);
  --sidebar-active-bg: rgba(13,110,253,0.18);
  --sidebar-active-color: #6ea8fe;
  --sidebar-text: rgba(255,255,255,0.72);
  --font-mono: 'JetBrains Mono', 'Courier New', monospace;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  font-size: 14px;
}

/* ── Login Page ─────────────────────────────────────────── */

.login-page {
  background: var(--bs-body-bg);
  position: relative;
  overflow: hidden;
}

.login-bg {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse at 20% 50%, rgba(13,110,253,0.12) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 20%, rgba(111,66,193,0.08) 0%, transparent 50%);
  pointer-events: none;
  z-index: 0;
}

.login-container { position: relative; z-index: 1; }

.login-card {
  background: rgba(255,255,255,0.04);
  backdrop-filter: blur(20px);
  border: 1px solid rgba(255,255,255,0.08) !important;
}

[data-bs-theme="light"] .login-card {
  background: rgba(255,255,255,0.9);
  border: 1px solid rgba(0,0,0,0.08) !important;
}

.login-brand-icon {
  width: 64px; height: 64px;
  border-radius: 16px;
  background: linear-gradient(135deg, #0d6efd, #6610f2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
  color: white;
}

/* ── Sidebar Layout ─────────────────────────────────────── */

.sidebar {
  position: fixed;
  top: 0; left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--sidebar-bg);
  z-index: 200;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-offcanvas {
  background: var(--sidebar-bg);
  width: var(--sidebar-width);
  max-width: 85vw;
}

.sidebar-header {
  flex-shrink: 0;
  padding: 1rem;
}

.sidebar-logo-icon {
  width: 36px; height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, #0d6efd, #6610f2);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 1.1rem;
  flex-shrink: 0;
}

.sidebar-body {
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.1) transparent;
}

.sidebar-body::-webkit-scrollbar { width: 4px; }
.sidebar-body::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 2px; }

/* Sidebar Nav */
.sidebar-nav { list-style: none; padding: 0; margin: 0; }

.sidebar-nav .nav-section-label {
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.3);
  padding: 0.75rem 0.75rem 0.25rem;
  margin-top: 0.5rem;
}

.nav-sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  color: var(--sidebar-text);
  text-decoration: none;
  transition: all 0.15s ease;
  font-size: 0.82rem;
  font-weight: 500;
  margin-bottom: 2px;
}

.nav-sidebar-link i {
  width: 18px;
  font-size: 1rem;
  flex-shrink: 0;
  opacity: 0.7;
  transition: opacity 0.15s;
}

.nav-sidebar-link:hover {
  background: var(--sidebar-bg-hover);
  color: white;
}
.nav-sidebar-link:hover i { opacity: 1; }

.nav-sidebar-link.active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-active-color);
  font-weight: 600;
}
.nav-sidebar-link.active i { opacity: 1; }

/* ── Main Wrapper ───────────────────────────────────────── */

.main-wrapper {
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

@media (max-width: 991.98px) {
  .main-wrapper { margin-left: 0; }
}

/* ── Topbar ─────────────────────────────────────────────── */

.topbar {
  height: var(--topbar-height);
  background: var(--bs-body-bg);
  border-bottom: 1px solid var(--bs-border-color);
  z-index: 100;
  flex-shrink: 0;
}

/* ── Content ────────────────────────────────────────────── */

.content {
  flex: 1;
  overflow-y: auto;
  background: var(--bs-body-bg);
}

/* ── Loading Overlay ────────────────────────────────────── */

.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 9999;
  display: flex !important;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
}

.loading-overlay.d-none { display: none !important; }

/* ── KPI Cards ──────────────────────────────────────────── */

.kpi-card {
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  border-radius: 12px !important;
}

.kpi-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.15) !important;
}

/* ── Cards ──────────────────────────────────────────────── */

.card {
  border-radius: 10px !important;
}

.card-header {
  border-radius: 10px 10px 0 0 !important;
}

/* ── Tables ─────────────────────────────────────────────── */

.table th {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.table td { font-size: 0.82rem; }

.font-monospace { font-family: var(--font-mono) !important; }

/* ── Status Badges ──────────────────────────────────────── */

.badge { font-weight: 500; letter-spacing: 0.02em; }

/* ── Modals ─────────────────────────────────────────────── */

.modal-content { border-radius: 12px !important; border: 0; }

/* ── Historial timeline ──────────────────────────────────── */

/* Evita que flex hijos rompan el layout en pantallas angostas */
.min-w-0 { min-width: 0; }

/* Modal historial: ocupa casi toda la pantalla en móvil */
@media (max-width: 575.98px) {
  #modalHistorial .modal-dialog {
    margin: 0.5rem;
    max-width: calc(100vw - 1rem);
  }
  /* Texto de email puede truncarse en cards muy angostas */
  #modalHistorial .text-truncate,
  #hv-cambios .text-truncate { max-width: 160px; }
}

/* ── Signature canvas ───────────────────────────────────── */

#sigCanvas, #firmaSigCanvas {
  touch-action: none;
  border-radius: 6px;
}

/* ── Calendar ───────────────────────────────────────────── */

#calBody td {
  min-height: 90px;
  vertical-align: top;
  font-size: 0.75rem;
  transition: background 0.1s;
}

#calBody td:hover {
  background: var(--bs-secondary-bg) !important;
}

/* ── DataTables overrides ───────────────────────────────── */

.dataTables_wrapper .dataTables_length select,
.dataTables_wrapper .dataTables_filter input {
  font-size: 0.82rem;
}

.dataTables_wrapper .dataTables_info,
.dataTables_wrapper .dataTables_paginate {
  font-size: 0.78rem;
  margin-top: 0.75rem;
}

/* ── Progress bars ──────────────────────────────────────── */

.progress { border-radius: 100px; }
.progress-bar { border-radius: 100px; transition: width 0.6s ease; }

/* ── Form controls ──────────────────────────────────────── */

.form-control, .form-select {
  font-size: 0.85rem;
  border-radius: 8px !important;
}

.form-label { font-size: 0.82rem; margin-bottom: 0.3rem; }

/* ── Responsive tweaks ──────────────────────────────────── */

@media (max-width: 575.98px) {
  .content { padding: 0.75rem !important; }

  .btn-group .btn { padding: 0.2rem 0.4rem; font-size: 0.75rem; }

  .table th, .table td { font-size: 0.75rem; padding: 0.4rem 0.5rem; }

  .kpi-card .fs-2 { font-size: 1.5rem !important; }
  .kpi-card .kpi-icon { width: 48px !important; height: 48px !important; font-size: 1.2rem !important; }
}

/* ── Mobile table responsive helpers ───────────────────── */

/* Ensure table-responsive scrolls smoothly on touch */
.table-responsive { -webkit-overflow-scrolling: touch; }

/* Compact action buttons on mobile */
@media (max-width: 767.98px) {
  .btn-group-sm .btn { padding: 0.2rem 0.45rem; font-size: 0.72rem; }
  /* Tighten modal padding on small screens */
  .modal-body { padding: 0.75rem; }
  /* Make firma canvas usable on mobile */
  #firmaSigCanvas { height: 160px !important; }
  /* Prevent firma OT info from being too cramped */
  #firmaOTInfo .row { font-size: 0.78rem; }
}

/* ── Firma / OT detail panel ────────────────────────────── */

#firmaOTInfo {
  background: var(--bs-tertiary-bg);
  border-radius: 0.5rem;
  padding: 0.75rem 1rem;
  border: 1px solid var(--bs-border-color);
  max-height: 45vh;
  overflow-y: auto;
}

/* ── Scrollable completar modal body on mobile ──────────── */
@media (max-width: 767.98px) {
  #modalCompletar .modal-body,
  #modalFirma .modal-body,
  #modalMant .modal-body { max-height: 65vh; overflow-y: auto; }
}

@media (max-width: 767.98px) {
  .modal-dialog { margin: 0.5rem; }
  .modal-dialog.modal-lg, .modal-dialog.modal-xl { max-width: calc(100% - 1rem); }
}

/* ── Utilities ──────────────────────────────────────────── */

.min-w-0 { min-width: 0; }
.text-truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cursor-pointer { cursor: pointer; }
.lh-1 { line-height: 1 !important; }
.fs-7 { font-size: 0.75rem !important; }

/* ── List group ─────────────────────────────────────────── */
.list-group-item { font-size: 0.82rem; }

/* ── Input groups ───────────────────────────────────────── */
.input-group-text { font-size: 0.85rem; }

/* ── Alert ──────────────────────────────────────────────── */
.alert { border-radius: 10px !important; font-size: 0.85rem; }

/* ── Nav tabs ───────────────────────────────────────────── */
.nav-tabs .nav-link { font-size: 0.82rem; font-weight: 500; }

/* ── Sidebar footer ─────────────────────────────────────── */
.sidebar-footer { flex-shrink: 0; }

/* ── Dark/Light theme adjustments ──────────────────────── */

[data-bs-theme="dark"] {
  --sidebar-bg: #0f1117;
}

[data-bs-theme="dark"] .card {
  background: #1a1d21;
  border-color: rgba(255,255,255,0.07);
}

[data-bs-theme="dark"] .topbar {
  background: #13161b;
  border-bottom-color: rgba(255,255,255,0.07);
}

[data-bs-theme="dark"] .table-light th {
  background: rgba(255,255,255,0.05) !important;
  color: var(--bs-body-color);
}

[data-bs-theme="dark"] .table-hover > tbody > tr:hover > * {
  background-color: rgba(255,255,255,0.04);
}

[data-bs-theme="light"] {
  --sidebar-bg: #1e2330;
}

[data-bs-theme="light"] .card {
  background: #ffffff;
  border-color: rgba(0,0,0,0.06);
}

[data-bs-theme="light"] .topbar {
  background: #ffffff;
  border-bottom-color: rgba(0,0,0,0.08);
}

/* ── Offcanvas sidebar same as desktop ───────────────────── */
.offcanvas.sidebar-offcanvas .nav-sidebar-link { color: var(--sidebar-text); }
.offcanvas.sidebar-offcanvas .nav-sidebar-link:hover { background: var(--sidebar-bg-hover); color: white; }
.offcanvas.sidebar-offcanvas .nav-sidebar-link.active { background: var(--sidebar-active-bg); color: var(--sidebar-active-color); }

/* ── Print / PDF hidden ─────────────────────────────────── */
@media print {
  .sidebar, .topbar, .btn, .modal-footer { display: none !important; }
  .main-wrapper { margin-left: 0 !important; }
}
