/* ===== STAT CARDS ROW ===== */
.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr)) auto auto;
  gap: 16px;
  margin-bottom: 24px;
  align-items: stretch;
}

/* ===== SINGLE STAT CARD ===== */
.stat {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;

  display: flex;                       /* REQUIRED */
  align-items: center;
  justify-content: space-between;      /* PUSH NUMBER RIGHT */

  min-height: 44px;
}

/* Default: non-clickable */
.stat {
  cursor: default;
}

/* Clickable stats only */
.stat[data-status],
.stat[data-col-index] {
  cursor: pointer;
}

/* LEFT TEXT */
.stat-left {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-main);
}

.stat-sub {
  font-size: 12px;
  color: var(--text-muted);
}


/* RIGHT NUMBER */
.stat-value {
  font-size: 28px;
  font-weight: 700;
  line-height: 1;
  color: var(--text-main);
}

/* Hover for ALL clickable stats */
.stat[data-status]:hover,
.stat[data-col-index]:hover {
  border-color: var(--primary);
  box-shadow: 0 4px 12px rgba(0,0,0,0.06);
}


.stat.danger {
  border-color: var(--danger-text);
  background: var(--danger-bg);
}

/* ===== STATS: ACTIONS ONLY (no cards) ===== */
.stats-actions-only {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.stats-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

/* ===== STATS: FIXED ONE-ROW EQUAL WIDTH ===== */
.stats-fixed-row {
  display: flex;
  align-items: stretch;
  gap: 16px;
}

/* ===== EMPTY STAT PLACEHOLDER ===== */
.stat-placeholder {
  background: transparent;
  border: none;
  box-shadow: none;
  pointer-events: none;
}

/* LEFT: stats area */
.stats-fixed-row .stats-cards {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;        /* 🔑 ALL stats equal width */
  gap: 16px;
  flex: 1;                      /* take all available space */
}

/* FORCE equal height & width */
.stats-fixed-row .stat {
  width: 100%;
  min-width: 0;
}

/* RIGHT: actions */
.stats-fixed-row .stats-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  white-space: nowrap;
}

.stat[data-status].active,
.stat[data-col-index].active {
  border: 2px solid var(--primary);
  background: #f0f9ff;
}


/* Ensure stats row stretches items correctly */
.stats.stats-fixed-row {
  display: flex;
  align-items: stretch;
  gap: 16px;
}

/* 🔑 Force ALL stat cards to equal width */
.stats.stats-fixed-row > .stat {
  flex: 1 1 0;
  min-width: 0;
}

/* 🔒 Exclude action buttons from stat sizing */
.stats.stats-fixed-row > .stats-actions {
  flex: 0 0 auto;
  display: flex;
  gap: 8px;
}

/* ===== BUTTON ===== */
.primary-btn {
  align-self: center;
  height: 44px;
  padding: 0 28px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

/* ===== PRIMARY BUTTON HOVER ===== */
.primary-btn:hover:not(:disabled) {
  background-color: #5b2dde; /* slightly darker than primary */
  box-shadow: 0 6px 14px rgba(124, 58, 237, 0.25);
  transform: translateY(-1px);
}

.primary-btn:active:not(:disabled) {
  transform: translateY(0);
  box-shadow: 0 3px 8px rgba(124, 58, 237, 0.25);
}


/* ===== ICON BUTTON (Excel) ===== */
.icon-btn {
  width: 44px;
  height: 44px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  align-self: center;
}

.icon-btn img {
  width: 20px;
  height: 20px;
}

/* ===== DELETE / DANGER BUTTON ===== */
.btn-outline.danger {
  background-color: #ef4444;   /* light red background */
  border: 1px solid #ef4444;   /* red border */
  color: #ffffff;              /* black text */
  font-weight: 600;
}

/* Hover */
.btn-outline.danger:hover {
  background-color: #fecaca;   /* slightly darker red */
  border-color: #dc2626;
}

/* Active (pressed) */
.btn-outline.danger:active {
  background-color: #fca5a5;
}

/* ===== FORM ERROR MESSAGE ===== */
.form-error {
  background: #fee2e2;
  border: 1px solid #ef4444;
  color: #7f1d1d;
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 13px;
}


/* ===== TABLE CONTAINER ===== */
.table-card {
  max-height: calc(100vh - 200px);
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-y: auto;
  position: relative;
}
.virtual-spacer {
  height: 0;
}

/* ===== TABLE ===== */
.table {
  width: 100%;
  border-collapse: collapse;   /* 🔑 REQUIRED */
  border-spacing: 0;
}

/* ===== HEADER ===== */
.table th {
  background: #F3F4F6;         /* slightly off-white */
  font-size: 13px;
  font-weight: 600;
  text-align: left;
  padding: 12px;

  color: var(--text-main);

  border-bottom: 1px solid var(--border);  /* horizontal line */
  border-right: 1px solid #dcdddf;          /* vertical line */
}
.table thead th {
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: inset 0 -1px 0 var(--border);
  
}


/* remove right border on last header */
.table th:last-child {
  border-right: none;
}

/* ===== TABLE HEADER CONTENT ===== */
.th-content {
  display: flex;
  align-items: center;
  justify-content: space-between;  /* text left, icon right */
  gap: 8px;
}

/* header text */
.th-content span {
  white-space: nowrap;
}

/* tune icon */
.th-icon {
  width: 14px;
  height: 14px;
  opacity: 0.6;
  z-index: 11;
  cursor: pointer;
  pointer-events: auto;
  transition: all 0.2s ease;
}

/* Sort indicator */
.th-content.sorted-asc::after,
.th-content.sorted-desc::after {
  font-size: 10px;
  margin-left: 6px;
  color: var(--text-muted);
}

.th-content.sorted-asc::after {
  content: "▲";
}

.th-content.sorted-desc::after {
  content: "▼";
}


/* hover feedback */
.th-icon:hover {
  opacity: 1;
}

.th-icon.filter-active {
  opacity: 1;
  filter: invert(32%) sepia(85%) saturate(4200%) hue-rotate(215deg);
  background-color: rgba(37, 99, 235, 0.1);
  width: 14px;
  height: 14px;
}

/* Optional blue dot indicator */
.th-icon.filter-active::after {
  content: "";
  position: absolute;
  top: 2px;
  right: 2px;
  width: 6px;
  height: 6px;
  background: #2563eb; /* blue */
  border-radius: 50%;
}


/* ===== BODY CELLS ===== */
.table td {
  padding: 12px;
  font-size: 14px;
  color: var(--text-main);

  border-bottom: 1px solid #dcdddf;  /* faint horizontal line */
  border-right: 1px solid #dcdddf;   /* faint vertical line */
}

/* remove right border on last column */
.table td:last-child {
  border-right: none;
}

/* remove bottom border on last row */
.table tr:last-child td {
  border-bottom: none;
}

/* ===== ROW HOVER (subtle) ===== */
.table tbody tr:hover {
  background: #F9FAFB;
}




/* ===== Device Status BADGES ===== */
.badge {
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  display: inline-block;
}

.badge.success {
  background: var(--success-bg);
  color: var(--success-text);
}

.badge.warning {
  background: var(--warning-bg);
  color: var(--warning-text);
}

.badge.neutral {
  background: var(--neutral-bg);
  color: var(--neutral-text);
}

.badge.danger {
  background: var(--danger-bg);
  color: var(--danger-text);
}

/* ===== COLUMN POPUP ===== */
.column-popup {
  position: absolute;
  width: 260px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 12px 30px rgba(0,0,0,0.12);
  padding: 14px;
  z-index: 2000;
}

.popup-actions.center {
  display: flex;
  justify-content: center;
  margin-top: 8px;
}


/* hide by default */
.hidden {
  display: none;
}

/* sections */
.popup-section {
  margin-bottom: 14px;
}

.popup-title {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 8px;
}


.char-counter {
  font-size: 10px;
  color: #9aa0a6;
  letter-spacing: 0.2px;
}



/* sort buttons */
.sort-buttons {
  display: flex;
  gap: 8px;
}

.sort-btn {
  flex: 1;
  padding: 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  cursor: pointer;
  font-size: 13px;
}

.sort-btn:hover {
  border-color: var(--primary);
}

/* filter search */
.filter-search {
  position: relative;
  margin-bottom: 8px;
}

.filter-search input {
  width: 100%;
  padding: 8px 32px 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 13px;
}

.search-icon {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  opacity: 0.5;
}

/* filter list */
.filter-list {
  max-height: 140px;
  overflow-y: auto;
}

.filter-list label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  font-size: 14px;
  font-weight: 600;
}

/* ================= DATE FILTER HIERARCHY ================= */

/* YEAR block */
.filter-list .date-year {
  margin-top: 6px;
  
}

/* YEAR label */
.filter-list .date-year > label {
  font-weight: 600;
  font-weight: 600;
}

/* MONTH block */
.filter-list .date-month {
  margin-left: 16px;
  margin-top: 4px;
}

/* MONTH label */
.filter-list .date-month > label {
  font-weight: 500;
}

/* DAY labels */
.filter-list .date-month label:not(:first-child) {
  margin-left: 16px;
  font-weight: 400;
}


/* actions */
.popup-actions {
  display: flex;
  justify-content: space-between;
  margin-top: 12px;
}

.btn-outline {
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  cursor: pointer;
}

.btn-primary {
  padding: 8px 16px;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  border: none;
  cursor: pointer;
}


.sr-link {
  color: var(--primary);
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}

.sr-link:hover {
  text-decoration: underline;
}


.machine-header {
  margin-bottom: 20px;
}

/* ================= MACHINE DETAILS ================= */

.machine-breadcrumb {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.machine-title {
  font-size: 22px;
  font-weight: 600;
  margin-bottom: 14px;
}

/* Tabs */
.machine-tabs {
  display: flex;
  gap: 28px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}

.machine-tab {
  padding: 10px 0;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  border: none;
  background: none;
  position: relative;
}

.machine-tab.active {
  color: var(--primary);
}

.machine-tab.active::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: -1px;
  width: 100%;
  height: 2px;
  background: var(--primary);
}


/* Sections */
.machine-section {
  margin-bottom: 36px;
}

.machine-section-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--primary);
  margin-bottom: 10px;
}

.machine-divider {
  height: 1px;
  background: var(--border);
  margin-bottom: 18px;
}

/* Grid */
.machine-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 32px;
}

.machine-field label {
  font-size: 12px;
  color: #6B7280;
  margin-bottom: 6px;
}

.machine-field p {
  font-size: 14px;
  font-weight: 600;
  color: #111827;
}

/* ===== MODAL ===== */

.modal.hidden {
  display: none;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-overlay {
  position: absolute;
  inset: 0;
  z-index: 1;
  background: rgba(0, 0, 0, 0.4);
}

.modal-content {
  position: relative;
  width: 420px;
  max-height: 90vh;
  overflow-y: auto;
  background: #fff;
  border-radius: 8px;
  padding: 20px;
  z-index: 2;
  pointer-events: auto;
}

/* FORM */

.modal-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-form input,
.modal-form select,
.modal-form textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  box-sizing: border-box;
}

.modal-form textarea {
  resize: none;
  height: 70px;
}

.file-upload .upload-box {
  border: 1px dashed var(--border);
  border-radius: 6px;
  padding: 20px;
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
}

.modal-actions {
  display: flex;
  justify-content: space-between;
  margin-top: 18px;
}
/* ===== READ-ONLY AUTO FILLED FIELDS ===== */
.modal-form input[readonly],
.modal-form textarea[readonly] {
  background-color: #F9FAFB;        /* light disabled look */
  color: #374151;                   /* readable text */
  cursor: not-allowed;
}

/* prevent focus highlight */
.modal-form input[readonly]:focus,
.modal-form textarea[readonly]:focus {
  outline: none;
  box-shadow: none;
  border-color: var(--border);
}


/* ===== SEARCHABLE SELECT ===== */
.searchable-select {
  position: relative;
}

.searchable-select .dropdown-caret {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 14px;
  color: #6B7280;
  pointer-events: none;   /* input remains clickable */
}
.searchable-select .options {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  max-height: 160px;
  overflow-y: auto;
  z-index: 10;
}

.searchable-select .option {
  padding: 8px 10px;
  font-size: 13px;
  cursor: pointer;
}

.searchable-select .option:hover {
  background: #F3F4F6;
}

.searchable-select .hidden {
  display: none;
}


/* ===== RADIO GROUP (Add Contact modal) ===== */
.radio-group {
  display: flex;
  align-items: center;
  gap: 12px;
}

.radio-group > label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-main);
  white-space: nowrap;
}

.radio-options {
  display: flex;
  align-items: center;
  gap: 16px;   /* space between Yes / No */
}

.radio-options label {
  display: flex;
  align-items: center;
  gap: 6px;    /* space between radio & text */
  font-size: 13px;
  cursor: pointer;
}


.btn-primary:disabled {
  background-color: #e5e7eb;
  color: #9ca3af;
  cursor: not-allowed;
  border: 1px solid #d1d5db;
}

.btn-primary:disabled:hover {
  background-color: #e5e7eb;
}


.star-rating {
  display: flex;
  justify-content: center;
  flex-direction: row-reverse; 
  gap: 12px;
}

.star-rating input {
  display: none;
}

.star-rating label {
  font-size: 28px;
  color: #d0d0d0;
  cursor: pointer;
  transition: color 0.2s ease;
}

/* Hover: fill current star + all previous */
.star-rating label:hover,
.star-rating label:hover ~ label {
  color: #d0d0d0;
}

/* THIS is the magic */
.star-rating label:hover,
.star-rating label:hover ~ label {
  color: #f5b301;
}

/* Selected: fill current star + all previous */
.star-rating input:checked ~ label {
  color: #d0d0d0;
}

.star-rating input:checked + label,
.star-rating input:checked + label ~ label {
  color: #f5b301;
}


.star-rating.readonly {
  display: flex;
  gap: 6px;
  flex-direction: row;   /* 🔑 fix direction */
}

.star-rating.readonly span {
  font-size: 22px;
  color: #d0d0d0;
}

.star-rating.readonly span.filled {
  color: #f5b301;
}

.machine-field.rating {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}


.global-error {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: #FDECEC;
  color: #7F1D1D;
  border: 1px solid #DC2626;
  padding: 12px 18px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  z-index: 5000;
  box-shadow: 0 6px 20px rgba(0,0,0,0.12);
}

.global-error.hidden {
  display: none;
}

.modal-error {
  background: #ffe5e5;
  color: #b00020;
  padding: 10px;
  border-radius: 6px;
  margin-bottom: 12px;
  font-weight: 500;
}

.global-success {
  background: #e6f4ea;
  color: #1b5e20;
  padding: 12px;
  border-radius: 6px;
  margin: 10px 0;
  font-weight: 500;
}

.info-banner {
  background: #eef3ff;
  color: #1e3a8a;
  border: 1px solid #c7d2fe;
  padding: 10px 14px;
  border-radius: 6px;
  margin-bottom: 16px;
  font-size: 14px;
}


.spinner {
  display:inline-block;
  width:14px;
  height:14px;
  border:2px solid #ccc;
  border-top:2px solid #1976d2;
  border-radius:50%;
  animation: spin 0.8s linear infinite;
  margin-right:6px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}


.sp-link::after {
  content: " ↗";
  font-size: 0.85em;
}

/* ---------- User Dropdown ---------- */
.user-menu {
  position: relative;
  cursor: pointer;
}

.user-dropdown {
  position: absolute;
  right: 0;
  top: 120%;
  background: #ffffff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  min-width: 140px;
  box-shadow: 0 6px 18px rgba(0,0,0,0.08);
  z-index: 1000;
}

.user-dropdown.hidden {
  display: none;
}

.user-dropdown .dropdown-item {
  padding: 10px 14px;
  font-size: 14px;
  color: #111827;
}

.user-dropdown .dropdown-item:hover {
  background: #f3f4f6;
}


.modal-busy {
  pointer-events: none;
}
.modal-busy .modal-content {
  pointer-events: auto;
}


.breadcrumb-link {
  cursor: pointer;
  color: #6b46ff; /* same as active tab */
  font-weight: 500;
}

.breadcrumb-link:hover {
  text-decoration: underline;
}
