/* =====================================================
   Calibration Management System - Global Styles
   Modern professional UI
   ===================================================== */

:root {
  --primary: #0f766e;
  --primary-dark: #0d9488;
  --primary-light: #14b8a6;
  --primary-50: #f0fdfa;
  --primary-100: #ccfbf1;
  --sidebar-bg: #0f172a;
  --sidebar-hover: #1e293b;
  --sidebar-active: #134e4a;
  --sidebar-text: #94a3b8;
  --sidebar-text-active: #f0fdfa;
  --bg: #f1f5f9;
  --card: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #3b82f6;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.08), 0 2px 4px -2px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.08), 0 4px 6px -4px rgba(0,0,0,0.05);
  --transition: all 0.2s ease;
}

* {
  margin: 0;
  padding: 1px;
  box-sizing: border-box;
}

html {
  height: 100%;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100%;
  height: 100%;
  overflow: hidden;
}

a { text-decoration: none; color: inherit; }
button { font-family: inherit; cursor: pointer; border: none; outline: none; }
input, select, textarea { font-family: inherit; }

/* ---------- Layout ---------- */
.app {
  display: flex;
  min-height: 100%;
  height: 100%;
  overflow: hidden;
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: 260px;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  height: 100vh;
  height: 100dvh;
  z-index: 200;
  transition: transform 0.3s ease;
  overflow: hidden;
}

.sidebar-brand {
  padding: 1.5rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  flex-shrink: 0;
}

.sidebar-brand .logo {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, var(--primary-light), var(--primary));
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 1.25rem;
  font-weight: 700;
}

.sidebar-brand h1 {
  font-size: 1.05rem;
  font-weight: 700;
  color: white;
  letter-spacing: -0.02em;
}

.sidebar-brand span {
  font-size: 0.7rem;
  color: var(--sidebar-text);
  display: block;
  margin-top: 1px;
}

.sidebar-nav {
  flex: 1;
  padding: 1rem 0.75rem;
  overflow-y: auto;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
}

.nav-section {
  margin-bottom: 1.25rem;
}

.nav-section-title {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #475569;
  padding: 0 0.75rem;
  margin-bottom: 0.5rem;
  font-weight: 600;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.7rem 0.85rem;
  border-radius: 8px;
  color: var(--sidebar-text);
  font-size: 0.9rem;
  font-weight: 500;
  transition: var(--transition);
  margin-bottom: 2px;
}

.nav-item:hover {
  background: var(--sidebar-hover);
  color: white;
}

.nav-item.active {
  background: var(--sidebar-active);
  color: var(--sidebar-text-active);
}

.nav-item i {
  width: 20px;
  text-align: center;
  font-size: 1.05rem;
  opacity: 0.9;
}

.sidebar-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid rgba(255,255,255,0.06);
  flex-shrink: 0;
  background: var(--sidebar-bg);
}

.user-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 600;
  font-size: 0.85rem;
}

.user-meta {
  flex: 1;
  min-width: 0;
}

.user-meta .name {
  color: white;
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-meta .role {
  font-size: 0.7rem;
  color: var(--sidebar-text);
  text-transform: capitalize;
}

.btn-logout {
  width: 100%;
  padding: 0.5rem;
  background: rgba(239, 68, 68, 0.15);
  color: #fca5a5;
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 500;
  transition: var(--transition);
}

.btn-logout:hover {
  background: rgba(239, 68, 68, 0.25);
  color: #fecaca;
}

/* ---------- Main content ---------- */
.main {
  flex: 1;
  margin-left: 260px;
  min-height: 100vh;
  min-height: 100dvh;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}

.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 0.85rem 1.75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
  flex-shrink: 0;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.menu-toggle {
  display: none;
  background: none;
  font-size: 1.25rem;
  color: var(--text-muted);
  padding: 0.35rem;
}

.page-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.content {
  padding: 1.75rem;
  flex: 1;
}

/* ---------- Cards ---------- */
.card {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.card-header h2 {
  font-size: 1rem;
  font-weight: 600;
}

.card-html {
  height: 100%;
}

body {
  padding: 1.25rem;
}

/* ---------- Stats ---------- */
/* ---------- Stats grid ---------- */
.stats-container {
  container-type: inline-size;
  container-name: stats;
  width: 100%;
  margin-bottom: 1.75rem;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1.25rem;
  width: 100%;
}

.stat-card {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 1.25rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 0.65rem;
  transition: var(--transition);
  min-width: 0;
}

.stat-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.35rem;
  flex-shrink: 0;
}

.stat-icon.teal { background: color-mix(in srgb, var(--primary-100) 80%, transparent); color: var(--primary); }
.stat-icon.amber { background: color-mix(in srgb, #fef3c7 80%, transparent); color: #d97706; }
.stat-icon.red { background: color-mix(in srgb, #fee2e2 80%, transparent); color: #dc2626; }
.stat-icon.blue { background: color-mix(in srgb, #dbeafe 80%, transparent); color: #2563eb; }
.stat-icon.green { background: color-mix(in srgb, #d1fae5 80%, transparent); color: #059669; }
.stat-icon.purple { background: color-mix(in srgb, #ede9fe 80%, transparent); color: #7c3aed; }

.progress-wrap {
  height: 8px;
  background: #e2e8f0;
  border-radius: 999px;
  overflow: hidden;
  margin: 0.35rem auto 0;
  max-width: 160px;
}

.progress-bar {
  height: 100%;
  background: var(--success);
  border-radius: 999px;
  transition: width 0.3s ease;
  min-width: 0;
}

.progress-bar.warn {
  background: var(--warning);
}

.progress-bar.danger {
  background: var(--danger);
}

.stat-value {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.2;
  text-align: center;
}

.stat-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 2px;
  text-align: center;
}

/* Container queries — parent is .stats-container */
@container stats (max-width: 520px) {
  .stats-grid {
    grid-template-columns: 1fr;
    gap: 0.85rem;
  }

  .stat-card {
    padding: 1rem;
  }

  .stat-value,
  .pct-value {
    font-size: 1.45rem;
  }

  .stat-icon {
    width: 40px;
    height: 40px;
    font-size: 1.15rem;
  }
}

@container stats (min-width: 521px) and (max-width: 820px) {
  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@container stats (min-width: 821px) {
  .stats-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

/* Viewport fallback when container queries are unavailable */
@supports not (container-type: inline-size) {
  @media (max-width: 700px) {
    .stats-grid {
      grid-template-columns: 1fr;
    }
  }
}

@media (max-width: 700px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }
}

/* ---------- Tables ---------- */
.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

thead th {
  text-align: left;
  padding: 0.75rem 1rem;
  background: #f8fafc;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody td {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tbody tr:last-child td {
  border-bottom: none;
}

tbody tr:hover {
  background: #f8fafc;
}

/* ---------- Badges ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.badge-ok { background: #d1fae5; color: #065f46; }
.badge-due-soon { background: #fef3c7; color: #92400e; }
.badge-overdue { background: #fee2e2; color: #991b1b; }
.badge-unknown { background: #e2e8f0; color: #475569; }
.badge-active { background: #d1fae5; color: #065f46; }
.badge-inactive { background: #e2e8f0; color: #64748b; }
.badge-admin { background: #ede9fe; color: #5b21b6; }
.badge-user { background: #dbeafe; color: #1e40af; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.55rem 1rem;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 550;
  transition: var(--transition);
  white-space: nowrap;
}

.btn-primary {
  background: var(--primary);
  color: white;
}
.btn-primary:hover {
  background: var(--primary-dark);
  box-shadow: 0 4px 12px rgba(15, 118, 110, 0.3);
}

.btn-secondary {
  background: #f1f5f9;
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover {
  background: #e2e8f0;
}

.btn-danger {
  background: #fef2f2;
  color: #dc2626;
  border: 1px solid #fecaca;
}
.btn-danger:hover {
  background: #fee2e2;
}

.btn-sm {
  padding: 0.35rem 0.65rem;
  font-size: 0.78rem;
}

.btn-icon {
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
}
.btn-icon:hover {
  background: #f1f5f9;
  color: var(--text);
}
.btn-icon.danger:hover {
  background: #fef2f2;
  color: #dc2626;
}

/* ---------- Forms ---------- */

/* ---------- Mobile-friendly forms & modals ---------- */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr));
  gap: 1rem;
}

.modal {
  width: min(720px, calc(100vw - 1.5rem));
  max-width: calc(100vw - 1.5rem);
  max-height: calc(100vh - 1.5rem);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-body {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  flex: 1 1 auto;
  min-height: 0;
  padding: 1rem 1.25rem;
}

.modal-header,
.modal-footer {
  flex-shrink: 0;
}

.modal-footer {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: flex-end;
}

.modal-footer .btn {
  min-width: 100px;
}

@media (max-width: 640px) {
  .form-grid {
    grid-template-columns: 1fr;
    gap: 0.75rem;
  }

  .modal {
    width: calc(100vw - 0.75rem);
    max-width: calc(100vw - 0.75rem);
    max-height: calc(100vh - 0.75rem);
    margin: 0.35rem auto;
    border-radius: 12px;
  }

  .modal-header {
    padding: 0.85rem 1rem;
  }

  .modal-header h3 {
    font-size: 1rem;
  }

  .modal-body {
    padding: 0.85rem 1rem;
  }

  .modal-footer {
    padding: 0.75rem 1rem;
  }

  .modal-footer .btn {
    flex: 1 1 auto;
    min-width: 0;
  }

  .form-control {
    font-size: 16px; /* prevent iOS zoom */
  }

  .toolbar {
    gap: 0.5rem;
  }

  .toolbar .form-control,
  .toolbar .search-box {
    width: 100%;
    min-width: 0 !important;
    flex: 1 1 100%;
  }

  .toolbar .btn {
    width: 100%;
  }
}


.form-group {
  margin-bottom: 0;
}

.form-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 550;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}

.form-control {
  width: 100%;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.875rem;
  background: white;
  transition: var(--transition);
  color: var(--text);
}

.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.15);
}

textarea.form-control {
  min-height: 80px;
  resize: vertical;
}

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  opacity: 0;
  visibility: hidden;
  transition: var(--transition);
  padding: 1rem;
}

.modal-overlay.open {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: white;
  border-radius: 16px;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  transform: translateY(12px);
  transition: var(--transition);
}

.modal-overlay.open .modal {
  transform: translateY(0);
}

.modal-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 {
  font-size: 1.1rem;
  font-weight: 650;
}

.modal-close {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  font-size: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-close:hover {
  background: #f1f5f9;
  color: var(--text);
}

.modal-html {
  height: 100%;
}

body {
  padding: 1.5rem;
}

.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
}

/* ---------- Search & filters ---------- */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
}

.search-box {
  position: relative;
  flex: 1;
  min-width: 200px;
  max-width: 320px;
}

.search-box i {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 0.9rem;
}

.search-box input {
  width: 100%;
  padding: 0.55rem 0.75rem 0.55rem 2.25rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.875rem;
  background: white;
}

.search-box input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.15);
}

/* ---------- Calendar specific ---------- */
.cal-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}

.cal-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.15rem;
  box-shadow: var(--shadow);
  transition: var(--transition);
  border-left: 4px solid var(--primary);
}

.cal-card.overdue { border-left-color: var(--danger); }
.cal-card.due-soon { border-left-color: var(--warning); }
.cal-card.ok { border-left-color: var(--success); }

.cal-card:hover {
  box-shadow: var(--shadow-md);
}

.cal-card h4 {
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 0.35rem;
}

.cal-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.cal-date {
  font-size: 0.85rem;
  font-weight: 550;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

/* ---------- Empty state ---------- */
.empty-state {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--text-muted);
}

.empty-state i {
  font-size: 2.5rem;
  opacity: 0.4;
  margin-bottom: 0.75rem;
}

.empty-state p {
  font-size: 0.95rem;
}

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .main {
    margin-left: 0;
  }
  .menu-toggle {
    display: block;
  }
  .sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 99;
    opacity: 0;
    visibility: hidden;
    transition: var(--transition);
  }
  .sidebar-overlay.open {
    opacity: 1;
    visibility: visible;
  }
}

/* ---------- Utilities ---------- */
.flex { display: flex; }
.items-center { align-items: center; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 0.75rem; }
.mt-1 { margin-top: 0.25rem; }
.mt-2 { margin-top: 0.5rem; }
.mb-3 { margin-bottom: 1rem; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 0.85rem; }
.font-medium { font-weight: 550; }
.hidden { display: none !important; }


/* Card body that is purely a scroll area */
.card-body.list-scroll {
  padding-top: 0.5rem;
  padding-bottom: 0.5rem;
}

/* Equipment / admin table containers inside cards */
.card > .table-wrap.table-scroll,
.card > .cal-scroll {
  max-height: calc(100vh - 250px);
}

@media (max-width: 900px) {
  .table-scroll,
  .cal-scroll {
    max-height: calc(100vh - 200px);
  }
  .list-scroll {
    max-height: 240px;
  }
}

/* ---------- Fixed frame + scrollable data lists ---------- */
.content {
  max-width: 100%;
  overflow-x: hidden;
}

.table-scroll {
  overflow: auto !important;
  max-height: calc(100vh - 250px);
  position: relative;
  border-top: 1px solid var(--border);
  width: 100%;
}

.table-scroll table {
  border-collapse: separate;
  border-spacing: 0;
}

.table-scroll thead th {
  position: sticky;
  top: 0;
  z-index: 10;
  background: #f8fafc !important;
  box-shadow: 0 1px 0 var(--border);
}

/* Calendar matrix: fixed frame = dashboard content width; scroll inside */
.cal-scroll {
  overflow: auto !important;
  max-width: 100%;
  width: 100%;
  height: auto;
  max-height: 540px;
  position: relative;
  border-top: 1px solid var(--border);
  -webkit-overflow-scrolling: touch;
}

.list-scroll {
  overflow-y: auto !important;
  max-height: 300px;
  position: relative;
}

.card-body.list-scroll {
  padding-top: 0.5rem;
  padding-bottom: 0.5rem;
}

.card > .table-wrap.table-scroll,
.card > .cal-scroll {
  max-height: calc(100vh - 250px);
}

/* Fixed frame card: header fixed, body scrolls within dashboard width */
.card.card-fixed {
  display: flex;
  flex-direction: column;
  max-height: none;

  max-width: 100%;
  width: 100%;
  overflow: hidden;
}

.card.card-fixed > .card-header {
  flex-shrink: 0;
  max-width: 100%;
}

.card.card-fixed > .table-scroll,
.card.card-fixed > .cal-scroll,
.card.card-fixed > .card-body.list-scroll {
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  max-height: none;
  width: 100%;
  overflow: auto !important;
}

@media (max-width: 900px) {
  .table-scroll,
  .cal-scroll {
    max-height: calc(100vh - 200px);
    height: calc(100vh - 200px);
  }
  .list-scroll {
    max-height: 240px;
  }
}


/* Equipment list sticky offsets */
/* superseded: col-ctrl is second column */
.table-scroll .col-name {
  left: 100px;
  min-width: 160px;
  border-right: 2px solid #cbd5e1 !important;
  box-shadow: 2px 0 4px rgba(15, 23, 42, 0.06);
}

/* Calendar matrix sticky offsets (equipment calendar) */
.cal-matrix .col-name { left: 0; min-width: 160px; max-width: 180px; }
.cal-matrix .col-ctrl { left: 160px; min-width: 90px; }
.cal-matrix .col-mfr { left: 250px; min-width: 100px; }
.cal-matrix .col-model { left: 350px; min-width: 80px; }
.cal-matrix .col-serial {
  left: 430px;
  min-width: 90px;
  border-right: 2px solid #cbd5e1 !important;
  box-shadow: 2px 0 4px rgba(15, 23, 42, 0.06);
}

/* Cleanroom / compressed sticky offsets */
.cal-matrix .col-area { left: 0; min-width: 120px; max-width: 150px; }
.cal-matrix .col-class { left: 120px; min-width: 110px; }
.cal-matrix .col-dept { left: 230px; min-width: 120px; }
.cal-matrix .col-test {
  left: 350px;
  min-width: 95px;
  border-right: 2px solid #cbd5e1 !important;
  box-shadow: 2px 0 4px rgba(15, 23, 42, 0.06);
}

/* Thermal (extra Testing Due column) */
.cal-matrix .col-due {
  left: 445px;
  min-width: 90px;
  border-right: 2px solid #cbd5e1 !important;
  box-shadow: 2px 0 4px rgba(15, 23, 42, 0.06);
}

/* ---------- Sticky table headers (shared) ---------- */
.table-scroll thead th,
.cal-scroll thead th,
.cal-matrix thead th {
  position: sticky;
  top: 0;
  z-index: 10;
  background: #f8fafc !important;
  box-shadow: 0 1px 0 #e2e8f0;
}

/* Second header row (week labels under months) */
.cal-matrix thead tr:nth-child(2) th {
  top: 27px;
  z-index: 9;
  background: #ccfbf1 !important;
  box-shadow: 0 1px 0 #e2e8f0;
}

/* Month header row stays on top */
.cal-matrix thead tr:first-child th.month-header {
  top: 0;
  z-index: 11;
  background: #0f766e !important;
  color: #fff !important;
}

/* Corner cells: sticky header + sticky left column */
.table-scroll thead th.sticky-col,
.cal-matrix thead th.sticky-col {
  z-index: 15 !important;
  background: #f8fafc !important;
}

.cal-matrix thead tr:nth-child(2) th.sticky-col {
  top: 27px;
  z-index: 14 !important;
}

/* ---------- Sticky left columns (implemented) ---------- */
.table-scroll table,
.cal-matrix {
  border-collapse: separate !important;
  border-spacing: 0 !important;
}

th.sticky-col,
td.sticky-col {
  position: sticky !important;
  background-clip: padding-box;
}

td.sticky-col {
  background: #ffffff !important;
  z-index: 3;
}

thead th.sticky-col {
  background: #f8fafc !important;
  z-index: 15 !important;
}

tbody tr:hover td.sticky-col {
  background: #f0fdfa !important;
}

/* Equipment — Name first, Control No. second */
.table-scroll .col-name {
  left: 0 !important;
  min-width: 180px;
  width: 180px;
}
.table-scroll .col-ctrl {
  left: 180px !important;
  min-width: 110px;
  width: 110px;
  border-right: 2px solid #94a3b8 !important;
  box-shadow: 3px 0 6px rgba(15, 23, 42, 0.08);
}

/* Calendar equipment matrix */
.cal-matrix .col-name { left: 0 !important; min-width: 160px; }
.cal-matrix .col-ctrl { left: 160px !important; min-width: 90px; }
.cal-matrix .col-mfr { left: 250px !important; min-width: 100px; }
.cal-matrix .col-model { left: 350px !important; min-width: 80px; }
.cal-matrix .col-serial {
  left: 430px !important;
  min-width: 90px;
  border-right: 2px solid #94a3b8 !important;
  box-shadow: 3px 0 6px rgba(15, 23, 42, 0.08);
}

/* Cleanroom / compressed */
.cal-matrix .col-area { left: 0 !important; min-width: 120px; }
.cal-matrix .col-class { left: 120px !important; min-width: 110px; }
.cal-matrix .col-dept { left: 230px !important; min-width: 120px; }
.cal-matrix .col-test {
  left: 350px !important;
  min-width: 95px;
  border-right: 2px solid #94a3b8 !important;
  box-shadow: 3px 0 6px rgba(15, 23, 42, 0.08);
}

/* Thermal with due column */
.cal-matrix .col-due {
  left: 445px !important;
  min-width: 90px;
  border-right: 2px solid #94a3b8 !important;
  box-shadow: 3px 0 6px rgba(15, 23, 42, 0.08);
}

/* ---------- Uniform data table rows 28px ---------- */
.table-scroll table tbody tr,
.table-scroll table tbody td,
.cal-matrix tbody tr,
.cal-matrix tbody td {
  height: 28px !important;
  max-height: 28px;
  line-height: 1.1;
  padding-top: 0 !important;
  padding-bottom: 0 !important;
  vertical-align: middle;
}

.table-scroll table thead th,
.cal-matrix thead th {
  height: 28px;
  line-height: 1.1;
  padding-top: 0.2rem !important;
  padding-bottom: 0.2rem !important;
}

.week-cell {
  height: 28px !important;
  max-height: 28px;
}

.week-check {
  width: 16px !important;
  height: 16px !important;
  font-size: 0.6rem !important;
}

/* Month week highlight (light green) when any week checked */
.week-cell.month-hl {
  background: #d1fae5 !important;
}
.cal-matrix tbody tr:hover td.week-cell.month-hl {
  background: #a7f3d0 !important;
}

/* Print toolbar controls (screen only) */
.print-toolbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.print-toolbar label.hide-checks-label {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  cursor: pointer;
  margin: 0;
  font-weight: 500;
}

/* When hide checks is on: month highlight → #0095ff (print + live preview) */
body.print-hide-checks .week-cell.month-hl,
body.hide-checks-preview .week-cell.month-hl {
  background: #0095ff !important;
}
body.print-hide-checks .cal-matrix tbody tr:hover td.week-cell.month-hl,
body.hide-checks-preview .cal-matrix tbody tr:hover td.week-cell.month-hl {
  background: #007acc !important;
}

/* ---------- Print (A4 landscape) ---------- */
.cms-print-header {
  display: none;
}


@media print {
  @page {
    /* Prefer landscape; printer may override with "auto"/fit */
    size: A4 landscape;
    margin: 8mm;
  }

  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
    color-adjust: exact !important;
  }

  html, body {
    width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: visible !important;
    background: #fff !important;
    font-size: 8pt !important;
  }

  .sidebar,
  .sidebar-overlay,
  .sidebar-footer,
  .menu-toggle,
  .btn-logout,
  .print-toolbar,
  .no-print,
  .modal-overlay,
  .modal,
  .search-box,
  .toolbar .form-control,
  .toolbar .btn,
  .legend,
  .btn:not(.print-keep),
  .btn-icon,
  .col-actions,
  th.col-actions,
  td.col-actions,
  .cms-sync-wrap,
  #btnCmsSync,
  #btnCmsSyncTop {
    display: none !important;
  }

  /* Hide Action column even if class missing (last header labeled Actions) */
  body.printing table thead th.col-actions,
  body.printing table tbody td.col-actions,
  body.printing .cal-matrix th.col-actions,
  body.printing .cal-matrix td.col-actions {
    display: none !important;
    width: 0 !important;
    max-width: 0 !important;
    padding: 0 !important;
    border: none !important;
    overflow: hidden !important;
  }

  .app {
    display: block !important;
    height: auto !important;
    overflow: visible !important;
  }

  .main {
    margin: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
    overflow: visible !important;
  }

  .topbar {
    position: static !important;
    box-shadow: none !important;
    border: none !important;
    padding: 0 0 2mm 0 !important;
    background: transparent !important;
  }

  .page-title { font-size: 10pt !important; font-weight: 700 !important; }

  .content {
    padding: 0 !important;
    overflow: visible !important;
    width: 100% !important;
  }

  .cms-print-header {
    display: block !important;
    margin: 0 0 3mm 0 !important;
    padding: 0 0 2mm 0 !important;
    border-bottom: 1.5pt solid #0f766e !important;
    page-break-after: avoid;
  }

  .cms-print-brand {
  font-size: 9pt;
  font-weight: 600;
  color: #0f766e;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 1mm;
}
.cms-print-title {
    font-size: 12pt !important;
    font-weight: 700 !important;
    margin: 0 0 1.5mm 0 !important;
  }

  .cms-print-meta {
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 2mm 6mm !important;
    font-size: 8pt !important;
  }

  .card, .card-fixed, .list-card {
    box-shadow: none !important;
    border: 0.4pt solid #94a3b8 !important;
    border-radius: 0 !important;
    max-height: none !important;
    height: auto !important;
    overflow: visible !important;
    width: 100% !important;
  }

  .card-header {
    padding: 1.5mm 2mm !important;
    border-bottom: 0.4pt solid #cbd5e1 !important;
    page-break-after: avoid;
  }

  .card-header h2 { font-size: 9pt !important; }

  .card-body,
  .cal-scroll,
  .table-scroll,
  .list-scroll,
  .card-fixed > .cal-scroll,
  .card-fixed > .table-scroll,
  .table-wrap {
    max-height: none !important;
    height: auto !important;
    overflow: visible !important;
    width: 100% !important;
    border: none !important;
  }

  /* Full-width tables — show ALL columns */
  table,
  .table-scroll table,
  .cal-matrix {
    width: 100% !important;
    min-width: 100% !important;
    max-width: 100% !important;
    border-collapse: collapse !important;
    border-spacing: 0 !important;
    font-size: 6pt !important;
    table-layout: fixed !important;
  }

  thead { display: table-header-group !important; }
  tfoot { display: table-footer-group !important; }
  tbody { display: table-row-group !important; }

  /* Dynamic page breaks: table may span pages; never split a single row */
  table.cms-print-table,
  .table-scroll table,
  .table-wrap table,
  .cal-matrix {
    page-break-inside: auto !important;
    break-inside: auto !important;
  }

  table.cms-print-table tr,
  .table-scroll tbody tr,
  .table-wrap tbody tr,
  .cal-matrix tbody tr {
    page-break-inside: avoid !important;
    break-inside: avoid !important;
  }

  tr.vs-pad { display: none !important; height: 0 !important; }

  th, td,
  .cal-matrix th, .cal-matrix td,
  .table-scroll th, .table-scroll td {
    height: 22px !important;
    max-height: none !important;
    padding: 1px 1px !important;
    border: 0.25pt solid #94a3b8 !important;
    background: #fff !important;
    color: #0f172a !important;
    vertical-align: middle !important;
    white-space: nowrap !important;
    word-wrap: normal !important;
    overflow: visible !important;
    font-size: 6pt !important;
    line-height: 1.15 !important;
  }

  thead th, .cal-matrix thead th {
    background: #f1f5f9 !important;
    font-weight: 600 !important;
    font-size: 5.5pt !important;
  }

  .month-header {
    background: #0f766e !important;
    color: #fff !important;
    font-size: 6pt !important;
  }

  .week-header {
    background: #ccfbf1 !important;
    color: #0f766e !important;
    font-size: 5pt !important;
    min-width: 0 !important;
    width: auto !important;
  }

  .week-cell {
    min-width: 0 !important;
    width: auto !important;
    height: 18px !important;
    padding: 0 !important;
  }

  /* Kill sticky offsets so every column prints in flow (no blank gap between name & control no.) */
  .sticky-col,
  thead th,
  .cal-matrix thead th,
  .cal-matrix thead tr:nth-child(2) th,
  .table-scroll thead th,
  .col-name, .col-ctrl, .col-mfr, .col-model, .col-serial,
  .col-area, .col-class, .col-dept, .col-test, .col-due,
  .table-scroll .col-name,
  .table-scroll .col-ctrl,
  .table-scroll th.sticky-col,
  .table-scroll td.sticky-col,
  .cal-matrix .col-name,
  .cal-matrix .col-ctrl,
  .cal-matrix .col-mfr,
  .cal-matrix .col-model,
  .cal-matrix .col-serial,
  .cal-matrix th.sticky-col,
  .cal-matrix td.sticky-col,
  body.printing .table-scroll .col-name,
  body.printing .table-scroll .col-ctrl,
  body.printing .cal-matrix .col-name,
  body.printing .cal-matrix .col-ctrl {
    position: static !important;
    left: auto !important;
    right: auto !important;
    top: auto !important;
    z-index: auto !important;
    box-shadow: none !important;
    min-width: 0 !important;
    max-width: none !important;
    width: auto !important;
    border-right: 1px solid #e2e8f0 !important;
  }

  .week-cell.month-hl { background: #d1fae5 !important; }

  .week-check {
    width: 10px !important;
    height: 10px !important;
    font-size: 6px !important;
    background: #10b981 !important;
    color: #fff !important;
    box-shadow: none !important;
  }

  body.print-hide-checks .week-check { display: none !important; }

  body.print-hide-checks .week-cell.month-hl {
    background: #0095ff !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  /* Tables: full data, no crop, landscape auto multi-page by row count */
  .table-scroll,
  .table-wrap,
  .cal-scroll,
  .card.card-fixed,
  .card-fixed,
  .card {
    max-height: none !important;
    height: auto !important;
    overflow: visible !important;
    box-shadow: none !important;
  }

  .table-scroll table,
  .table-wrap table,
  .cal-matrix {
    table-layout: auto !important;
    width: 100% !important;
    min-width: 100% !important;
    max-width: 100% !important;
    font-size: 7pt !important;
    border-collapse: collapse !important;
    page-break-inside: auto !important;
  }

  .table-scroll thead,
  .table-wrap thead,
  .cal-matrix thead {
    display: table-header-group !important;
  }

  .table-scroll tfoot,
  .cal-matrix tfoot {
    display: table-footer-group !important;
  }

  .table-scroll tr,
  .table-wrap tr,
  .cal-matrix tr {
    page-break-inside: avoid !important;
    break-inside: avoid !important;
  }

  .table-scroll th,
  .table-scroll td,
  .table-wrap th,
  .table-wrap td,
  .cal-matrix th,
  .cal-matrix td {
    white-space: nowrap !important;
    overflow: visible !important;
    text-overflow: clip !important;
    width: auto !important;
    max-width: none !important;
    min-width: 0 !important;
    font-size: inherit !important;
    padding: 1.5pt 2pt !important;
    vertical-align: middle !important;
  }

  /* Adaptive density for wide calendars / long equipment lists */
  body.print-fit-md .table-scroll table,
  body.print-fit-md .table-wrap table,
  body.print-fit-md .cal-matrix { font-size: 6pt !important; }

  body.print-fit-sm .table-scroll table,
  body.print-fit-sm .table-wrap table,
  body.print-fit-sm .cal-matrix { font-size: 5pt !important; }

  body.print-fit-xs .table-scroll table,
  body.print-fit-xs .table-wrap table,
  body.print-fit-xs .cal-matrix { font-size: 4pt !important; }

  body.print-fit-xs .week-cell,
  body.print-fit-sm .week-cell {
    min-width: 0 !important;
    width: auto !important;
    height: auto !important;
    padding: 0.5pt !important;
  }

  /* Dense mode when many data rows — still paginates automatically */
  body.print-rows-dense .table-scroll th,
  body.print-rows-dense .table-scroll td,
  body.print-rows-dense .table-wrap th,
  body.print-rows-dense .table-wrap td,
  body.print-rows-dense .cal-matrix th,
  body.print-rows-dense .cal-matrix td {
    padding: 0.75pt 1.25pt !important;
    line-height: 1.1 !important;
  }

  body.print-rows-dense .table-scroll table,
  body.print-rows-dense .table-wrap table,
  body.print-rows-dense .cal-matrix {
    font-size: 5.5pt !important;
  }

  body.print-rows-dense.print-fit-sm .table-scroll table,
  body.print-rows-dense.print-fit-sm .cal-matrix,
  body.print-rows-dense.print-fit-xs .table-scroll table,
  body.print-rows-dense.print-fit-xs .cal-matrix {
    font-size: 4pt !important;
  }


  .stats-grid,
  .dashboard-grid-4,
  .dashboard-grid-3,
  .dashboard-grid {
    display: block !important;
  }

  .stats-grid > *,
  .dashboard-grid-4 > *,
  .dashboard-grid-3 > * {
    page-break-inside: avoid;
    margin-bottom: 2mm !important;
  }

  .vs-pad td {
    border: none !important;
    background: transparent !important;
    height: 0 !important;
    padding: 0 !important;
  }

  a { color: inherit !important; text-decoration: none !important; }
  .badge { border: 0.25pt solid #94a3b8 !important; box-shadow: none !important; }
}

/* ---------- Scrollbars: lists hide all; tables/calendars hide vertical only ---------- */
.sidebar-nav,
.list-scroll {
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.sidebar-nav::-webkit-scrollbar,
.list-scroll::-webkit-scrollbar {
  width: 0 !important;
  height: 0 !important;
  display: none !important;
}

.table-scroll,
.cal-scroll,
.table-wrap,
.card-fixed > .cal-scroll,
.card-fixed > .table-scroll {
  scrollbar-width: thin;
  scrollbar-color: #64748b #e2e8f0;
}

.table-scroll::-webkit-scrollbar,
.cal-scroll::-webkit-scrollbar,
.table-wrap::-webkit-scrollbar {
  width: 0;
  height: 12px;
}
.table-scroll::-webkit-scrollbar:vertical,
.cal-scroll::-webkit-scrollbar:vertical,
.table-wrap::-webkit-scrollbar:vertical {
  width: 0;
}
.table-scroll::-webkit-scrollbar:horizontal,
.cal-scroll::-webkit-scrollbar:horizontal,
.table-wrap::-webkit-scrollbar:horizontal {
  height: 12px;
}
.table-scroll::-webkit-scrollbar-thumb:horizontal,
.cal-scroll::-webkit-scrollbar-thumb:horizontal,
.table-wrap::-webkit-scrollbar-thumb:horizontal {
  background: #64748b;
  border-radius: 6px;
  border: 2px solid #e2e8f0;
}
.table-scroll::-webkit-scrollbar-track:horizontal,
.cal-scroll::-webkit-scrollbar-track:horizontal,
.table-wrap::-webkit-scrollbar-track:horizontal {
  background: #e2e8f0;
}


/* Calendar matrix — centered headers */
.cal-matrix thead th,
.cal-matrix th.month-header,
.cal-matrix th.week-header {
  text-align: center !important;
  vertical-align: middle !important;
}
.cal-matrix td.week-cell {
  text-align: center;
  vertical-align: middle;
}



