:root {
  --bg-app: #f8fafc;
  --bg-card: #ffffff;
  --bg-subtle: #f1f5f9;
  --border-color: #e2e8f0;
  --border-strong: #cbd5e1;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-secondary: #334155;
  
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-subtle: #eff6ff;
  
  --success: #10b981;
  --success-bg: #ecfdf5;
  --success-text: #065f46;
  --success-border: #a7f3d0;
  
  --warning: #f59e0b;
  --warning-bg: #fffbeb;
  --warning-text: #92400e;
  --warning-border: #fde68a;
  
  --danger: #ef4444;
  --danger-bg: #fef2f2;
  --danger-text: #991b1b;
  --danger-border: #fecaca;
  
  --empty-bg: #f3f4f6;
  --empty-text: #9ca3af;
  --empty-border: #e5e7eb;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.03);
}

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

body {
  font-family: 'Sarabun', 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background-color: var(--bg-app);
  color: var(--text-main);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
.app-header {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
  padding: 1rem 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow-sm);
}

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

.brand-icon {
  font-size: 1.75rem;
  background: linear-gradient(135deg, #3b82f6, #1d4ed8);
  color: white;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  box-shadow: 0 4px 10px rgba(37, 99, 235, 0.25);
}

.brand-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-main);
}

.brand-subtitle {
  font-size: 0.825rem;
  color: var(--text-muted);
}

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

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.35rem 0.75rem;
  border-radius: 9999px;
}

.badge-prototype {
  background: #f1f5f9;
  color: #475569;
  border: 1px solid #cbd5e1;
}

.badge-online {
  background: var(--success-bg);
  color: var(--success-text);
  border: 1px solid var(--success-border);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
}

.status-dot.pulse {
  animation: pulseDot 2s infinite;
}

@keyframes pulseDot {
  0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
  70% { transform: scale(1); box-shadow: 0 0 0 6px rgba(16, 185, 129, 0); }
  100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

/* Main Container */
.main-container {
  max-width: 98%;
  margin: 1.5rem auto;
  padding: 0 1rem;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* Device Card */
.device-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 1.25rem 1.5rem;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.search-section {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border-color);
}

.search-input-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 0.35rem;
}

.input-with-button {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  position: relative;
}

.autocomplete-wrapper {
  position: relative;
  width: 380px;
  max-width: 100%;
  display: flex;
  align-items: center;
}

.input-icon {
  position: absolute;
  left: 0.75rem;
  font-size: 0.9rem;
  pointer-events: none;
  z-index: 2;
}

.autocomplete-wrapper input {
  width: 100%;
  padding: 0.55rem 2.2rem 0.55rem 2.25rem;
  font-size: 0.95rem;
  font-family: inherit;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text-main);
  transition: all 0.2s;
}

.autocomplete-wrapper input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.hidden {
  display: none !important;
}

.btn-clear-input {
  position: absolute;
  right: 0.65rem;
  top: 50%;
  transform: translateY(-50%);
  width: 22px;
  height: 22px;
  min-width: 22px;
  max-width: 22px;
  min-height: 22px;
  max-height: 22px;
  background: #e2e8f0;
  border: none;
  color: #64748b;
  cursor: pointer;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0;
  margin: 0;
  line-height: 1;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease-in-out;
  z-index: 5;
  box-sizing: border-box;
}

.btn-clear-input.hidden {
  display: none !important;
}

.btn-clear-input:hover,
.btn-clear-input:active {
  background: #cbd5e1;
  color: #0f172a;
}

.sites-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: #ffffff;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  box-shadow: 0 10px 25px -5px rgba(15, 23, 42, 0.12), 0 8px 10px -6px rgba(15, 23, 42, 0.08);
  max-height: 380px;
  overflow-y: auto;
  z-index: 1050;
  display: flex;
  flex-direction: column;
}

.sites-dropdown.hidden {
  display: none !important;
}

.dropdown-header-info {
  padding: 0.4rem 0.75rem;
  background: #f8fafc;
  border-bottom: 1px solid #e2e8f0;
  font-size: 0.75rem;
  font-weight: 600;
  color: #64748b;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 3;
}

.dropdown-item {
  padding: 0.55rem 0.75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  cursor: pointer;
  border-bottom: 1px solid #f1f5f9;
  transition: background-color 0.15s, border-left-color 0.15s;
  border-left: 3px solid transparent;
}

.dropdown-item:last-child {
  border-bottom: none;
}

.dropdown-item:hover,
.dropdown-item.active {
  background-color: #f0f7ff;
  border-left-color: var(--primary);
}

.dropdown-site-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
}

.dropdown-site-code {
  font-family: 'SF Mono', Consolas, Monaco, monospace;
  font-weight: 600;
  font-size: 0.85rem;
  color: #1e293b;
  letter-spacing: 0.02em;
}

.dropdown-site-name {
  font-size: 0.825rem;
  color: #475569;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}

.dropdown-lswid {
  font-family: 'SF Mono', Consolas, Monaco, monospace;
  font-size: 0.8rem;
  font-weight: 600;
  color: #64748b;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  padding: 2px 7px;
  border-radius: 5px;
  white-space: nowrap;
}

.dropdown-item:hover .dropdown-lswid,
.dropdown-item.active .dropdown-lswid {
  background: #dbeafe;
  color: #1d4ed8;
  border-color: #bfdbfe;
}

.highlight-match {
  font-weight: 700;
  color: #1d4ed8;
  text-decoration: underline;
  background: rgba(37, 99, 235, 0.09);
  padding: 0 1px;
  border-radius: 2px;
}

.dropdown-empty {
  padding: 1.25rem 1rem;
  text-align: center;
  color: #94a3b8;
  font-size: 0.875rem;
}

.quick-examples {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.825rem;
}

.quick-label {
  color: var(--text-muted);
}

.quick-chip {
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  padding: 0.35rem 0.75rem;
  border-radius: 6px;
  font-size: 0.8rem;
  cursor: pointer;
  color: var(--primary);
  font-weight: 500;
  transition: all 0.15s;
}

.quick-chip:hover {
  background: var(--primary-subtle);
  border-color: var(--primary);
}

/* Device Meta Grid */
.device-meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
}

.meta-item {
  display: flex;
  flex-direction: column;
  background: var(--bg-app);
  padding: 0.65rem 0.9rem;
  border-radius: 8px;
  border: 1px solid var(--border-color);
}

.meta-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
}

.meta-value {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-main);
  margin-top: 0.15rem;
}

.meta-value.highlight {
  color: var(--primary);
}

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

/* Action Toolbar */
.action-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.toolbar-left, .toolbar-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  padding: 0.55rem 1rem;
  border-radius: 8px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.2s ease;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover {
  background: var(--primary-hover);
  box-shadow: 0 4px 10px rgba(37, 99, 235, 0.25);
}

.btn-action-recheck {
  background: linear-gradient(135deg, #0284c7, #0369a1);
  color: white;
  box-shadow: 0 4px 12px rgba(2, 132, 199, 0.3);
  font-size: 0.925rem;
  padding: 0.6rem 1.25rem;
}

.btn-action-recheck:hover {
  background: linear-gradient(135deg, #0369a1, #075985);
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(2, 132, 199, 0.4);
}

.btn-action-recheck:active {
  transform: translateY(0);
}

.btn-action-recheck.loading .btn-icon {
  animation: spin 0.8s linear infinite;
}

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

.badge-count {
  background: rgba(255, 255, 255, 0.25);
  padding: 0.15rem 0.5rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 700;
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-secondary);
  border: 1px solid var(--border-strong);
}

.btn-secondary:hover {
  background: var(--bg-subtle);
}

.btn-outline {
  background: var(--bg-card);
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
}

.btn-outline:hover {
  background: var(--bg-subtle);
  border-color: var(--border-strong);
}

.btn-outline-danger {
  background: var(--bg-card);
  color: var(--danger-text);
  border: 1px solid var(--danger-border);
}

.btn-outline-danger:hover {
  background: var(--danger-bg);
}

.filter-box input {
  padding: 0.55rem 0.85rem;
  font-size: 0.85rem;
  font-family: inherit;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  width: 240px;
  background: #ffffff;
}

.filter-box input:focus {
  outline: none;
  border-color: var(--primary);
}

/* Toast Banner */
.toast-banner {
  background: #0284c7;
  color: white;
  padding: 0.65rem 1.25rem;
  border-radius: 8px;
  font-size: 0.875rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  box-shadow: var(--shadow-md);
  transition: all 0.3s ease;
}

.toast-banner.hidden {
  display: none;
}

/* Matrix Card & Table */
.matrix-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

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

.matrix-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-main);
}

.matrix-desc {
  font-size: 0.825rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
}

.legend-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.85rem;
  font-size: 0.75rem;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--text-secondary);
}

.legend-box {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  display: inline-block;
}

.bg-good { background: var(--success); }
.bg-warn { background: var(--warning); }
.bg-crit { background: var(--danger); }
.bg-empty { background: var(--empty-border); }

/* Table Scroll Wrapper - Expands Vertically with No Internal Scroll */
.table-scroll-wrapper {
  width: 100%;
  overflow-x: auto;
  overflow-y: visible;
  position: relative;
  max-height: none;
  min-height: auto;
  -webkit-overflow-scrolling: touch;
}

.matrix-table {
  width: max-content;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.85rem;
}

.matrix-table th {
  background: var(--bg-subtle);
  color: var(--text-secondary);
  font-weight: 600;
  padding: 0.5rem 0.65rem;
  text-align: left;
  border-bottom: 2px solid var(--border-strong);
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 20;
}

.matrix-table td {
  padding: 0.45rem 0.65rem;
  border-bottom: 1px solid var(--border-color);
  background: #ffffff;
  vertical-align: middle;
}

.matrix-table tbody tr:hover td {
  background-color: #f8fafc;
}

/* Sticky Left Columns - Untruncated & Generous */
.col-port {
  position: sticky;
  left: 0;
  z-index: 30;
  width: 170px;
  min-width: 170px;
  max-width: 170px;
  background: #ffffff !important;
  font-family: 'Inter', monospace;
  font-weight: 600;
  font-size: 0.825rem;
  color: var(--primary);
  border-right: 1px solid var(--border-color);
  padding: 0.55rem 0.75rem !important;
  white-space: nowrap;
}

.port-name {
  display: block;
}

.port-desc-sub {
  display: none;
}

.port-cid-sub {
  display: none;
}

.col-desc {
  position: sticky;
  left: 170px;
  z-index: 30;
  width: 380px;
  min-width: 380px;
  max-width: 380px;
  background: #ffffff !important;
  color: var(--text-secondary);
  font-size: 0.825rem;
  border-right: 1px solid var(--border-color);
  white-space: normal;
  word-break: break-word;
  line-height: 1.35;
  padding: 0.55rem 0.75rem !important;
}

.col-cid {
  position: sticky;
  left: 550px;
  z-index: 30;
  width: 160px;
  min-width: 160px;
  max-width: 160px;
  background: #ffffff !important;
  color: #0369a1;
  font-family: 'Inter', monospace;
  font-weight: 600;
  font-size: 0.8125rem;
  border-right: 1px solid var(--border-color);
  white-space: normal;
  word-break: break-word;
  line-height: 1.4;
  padding: 0.55rem 0.75rem !important;
}

.col-status {
  position: sticky;
  left: 710px;
  z-index: 30;
  width: 60px;
  min-width: 60px;
  max-width: 60px;
  background: #ffffff !important;
  border-right: 2px solid var(--border-strong) !important;
  text-align: center;
  padding: 0.55rem 0.35rem !important;
}

.matrix-table th.col-port,
.matrix-table th.col-desc,
.matrix-table th.col-cid,
.matrix-table th.col-sfp,
.matrix-table th.col-status {
  background: var(--bg-subtle) !important;
  z-index: 40;
}

/* Dynamic Time Columns - Compact & Snug */
.col-time-header {
  width: 140px;
  min-width: 140px;
  max-width: 140px;
  text-align: center !important;
  border-left: 1px solid var(--border-color);
  background: #f8fafc !important;
  padding: 0.4rem 0.35rem !important;
}

.time-title {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-main);
  display: block;
  white-space: nowrap;
}

.time-label {
  font-size: 0.65rem;
  font-weight: 500;
  color: var(--text-muted);
  display: block;
  margin-top: 0.05rem;
  white-space: nowrap;
}

.col-time-cell {
  width: 140px;
  min-width: 140px;
  max-width: 140px;
  border-left: 1px solid var(--border-color);
  padding: 0.35rem 0.4rem !important;
  vertical-align: middle;
  transition: background-color 0.5s ease;
}

.col-time-cell.highlight-new {
  background-color: #ecfeff !important;
}

/* Power Matrix Cell Layout - Compact Snug Grid */
.power-matrix-cell {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  width: 100%;
}

.power-line {
  display: grid;
  grid-template-columns: 20px 1fr 32px;
  align-items: center;
  gap: 0.25rem;
  width: 100%;
}

.power-tag {
  font-size: 0.6rem;
  font-weight: 800;
  padding: 0.1rem 0;
  border-radius: 3px;
  text-align: center;
  letter-spacing: 0.5px;
  line-height: 1;
}

.tag-rx {
  background: #e0f2fe;
  color: #0369a1;
  border: 1px solid #bae6fd;
}

.tag-tx {
  background: #f1f5f9;
  color: #475569;
  border: 1px solid #e2e8f0;
}

.power-reading {
  display: inline-flex;
  align-items: baseline;
  justify-content: center;
  gap: 0.15rem;
  padding: 0.15rem 0.35rem;
  border-radius: 4px;
  white-space: nowrap;
  font-family: 'Inter', -apple-system, sans-serif;
  line-height: 1.2;
}

.power-reading .num {
  font-size: 0.775rem;
  font-weight: 700;
  letter-spacing: -0.2px;
}

.power-reading .unit {
  font-size: 0.6rem;
  font-weight: 500;
  opacity: 0.85;
}

.badge-good {
  background: #ecfdf5;
  color: #065f46;
  border: 1px solid #a7f3d0;
}

.badge-warn {
  background: #fffbeb;
  color: #92400e;
  border: 1px solid #fde68a;
}

.badge-crit {
  background: #fef2f2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

.badge-empty {
  background: #f8fafc;
  color: #94a3b8;
  border: 1px solid #e2e8f0;
  cursor: help;
  transition: all 0.15s ease;
}

.badge-empty:hover {
  background: #fef2f2;
  color: #dc2626;
  border-color: #fca5a5;
  box-shadow: 0 1px 3px rgba(220, 38, 38, 0.15);
}

.sfp-pill-empty {
  color: #94a3b8;
  cursor: help;
  display: inline-block;
  padding: 2px 8px;
  border-radius: 9999px;
  background: #f8fafc;
  border: 1px dashed #cbd5e1;
  font-size: 0.75rem;
  transition: all 0.15s ease;
}

.sfp-pill-empty:hover {
  background: #fef2f2;
  color: #dc2626;
  border-color: #fca5a5;
  border-style: solid;
  box-shadow: 0 1px 3px rgba(220, 38, 38, 0.15);
}

.diff-tag {
  font-size: 0.625rem;
  font-weight: 700;
  font-family: 'Inter', monospace;
  text-align: right;
  white-space: nowrap;
}

.diff-better {
  color: #16a34a;
}

.diff-worse {
  color: #dc2626;
}

.diff-same {
  color: #94a3b8;
}

.diff-placeholder {
  display: inline-block;
  width: 32px;
}

/* Link Status Pills */
.pill-up {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  background: #dcfce7;
  color: #15803d;
}

.pill-down {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  background: #fee2e2;
  color: #b91c1c;
}

.pill-empty {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  background: #f1f5f9;
  color: #64748b;
}

/* Actionable Badges for NMS Session Expired Renewal (Light Theme) */
.badge-actionable {
  cursor: pointer;
  user-select: none;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}
.badge-actionable:hover {
  background: #fee2e2;
  border-color: #f87171;
  color: #7f1d1d;
  box-shadow: 0 2px 8px rgba(239, 68, 68, 0.25);
  transform: translateY(-1px);
}
.badge-actionable:active {
  transform: translateY(0);
}
.badge-action-hint {
  display: inline-block;
  margin-left: 0.35rem;
  padding: 0.1rem 0.45rem;
  font-size: 0.675rem;
  font-weight: 700;
  background: #dc2626;
  color: #ffffff;
  border-radius: 4px;
  letter-spacing: 0.02em;
  animation: pulse-action-hint 2s infinite ease-in-out;
}
@keyframes pulse-action-hint {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.85; transform: scale(0.96); }
}
.badge-cooldown {
  cursor: not-allowed;
  user-select: none;
  opacity: 0.92;
}

/* Status Change Pulse Animations */
@keyframes link-status-pulse {
  0% { transform: scale(1.2); box-shadow: 0 0 10px rgba(22, 163, 74, 0.6); }
  50% { transform: scale(1.1); box-shadow: 0 0 6px rgba(22, 163, 74, 0.4); }
  100% { transform: scale(1); box-shadow: none; }
}
@keyframes link-status-pulse-down {
  0% { transform: scale(1.2); box-shadow: 0 0 10px rgba(220, 38, 38, 0.6); }
  50% { transform: scale(1.1); box-shadow: 0 0 6px rgba(220, 38, 38, 0.4); }
  100% { transform: scale(1); box-shadow: none; }
}
.pill-up.status-changed {
  animation: link-status-pulse 1.6s ease-out;
}
.pill-down.status-changed {
  animation: link-status-pulse-down 1.6s ease-out;
}

/* Footer */
.app-footer {
  text-align: center;
  font-size: 0.775rem;
  color: var(--text-muted);
  padding: 1.5rem;
  margin-top: auto;
  border-top: 1px solid var(--border-color);
  background: var(--bg-card);
}

/* Lock Screen Modal Overlay (Clean Light Theme) */
.lock-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(248, 250, 252, 0.88);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 99999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.lock-modal-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.lock-modal-card {
  background: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: 16px;
  box-shadow: 0 20px 40px -10px rgba(15, 23, 42, 0.12), 0 8px 16px -6px rgba(15, 23, 42, 0.08);
  width: 100%;
  max-width: 420px;
  padding: 2.25rem 2rem;
  text-align: center;
  animation: lockCardPop 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes lockCardPop {
  0% { transform: scale(0.94); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.lock-icon-badge {
  font-size: 2.25rem;
  width: 64px;
  height: 64px;
  background: var(--primary-subtle);
  color: var(--primary);
  border: 2px solid #bfdbfe;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 1.25rem auto;
}

.lock-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 0.35rem;
}

.lock-subtitle {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 1.5rem;
  line-height: 1.4;
}

.lock-form {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  text-align: left;
}

.lock-input-group label {
  display: block;
  font-size: 0.825rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 0.4rem;
}

.password-input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.password-input-wrapper input {
  width: 100%;
  padding: 0.75rem 2.5rem 0.75rem 2.5rem;
  font-size: 0.95rem;
  border: 1.5px solid var(--border-color);
  border-radius: 8px;
  outline: none;
  transition: all 0.2s ease;
  background: #ffffff;
  color: var(--text-main);
}

.password-input-wrapper input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.lock-field-icon {
  position: absolute;
  left: 0.85rem;
  font-size: 1rem;
  color: var(--text-muted);
  pointer-events: none;
}

.btn-toggle-pwd {
  position: absolute;
  right: 0.65rem;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.25rem;
  font-size: 1rem;
  opacity: 0.6;
  transition: opacity 0.2s;
}

.btn-toggle-pwd:hover {
  opacity: 1;
}

.btn-unlock {
  width: 100%;
  padding: 0.75rem;
  font-size: 0.95rem;
  font-weight: 600;
  justify-content: center;
  margin-top: 0.25rem;
}

.lock-error {
  background: var(--danger-bg);
  color: var(--danger-text);
  border: 1px solid var(--danger-border);
  border-radius: 6px;
  padding: 0.6rem 0.75rem;
  font-size: 0.825rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

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

.lock-card-footer {
  margin-top: 1.75rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border-color);
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ==========================================================================
   Mobile & Responsive Adaptations (Rule 15: Clean Light Theme Preserved)
   Optimized for Portrait Smartphone Viewport (360px - 768px)
   ========================================================================== */

@media (max-width: 768px) {
  /* 1. Header Layout */
  .app-header {
    padding: 0.75rem 0.85rem;
    flex-direction: column;
    align-items: stretch;
    gap: 0.65rem;
  }

  .header-left {
    gap: 0.65rem;
  }

  .brand-icon {
    width: 36px;
    height: 36px;
    font-size: 1.2rem;
  }

  .brand-title {
    font-size: 1.05rem;
  }

  .brand-subtitle {
    font-size: 0.725rem;
    line-height: 1.3;
  }

  .header-right {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.4rem;
  }

  .header-right .badge {
    font-size: 0.7rem;
    padding: 0.25rem 0.5rem;
  }

  /* 2. Main Container */
  .main-container {
    padding: 0.65rem 0.4rem;
    gap: 0.65rem;
  }

  /* 3. Search & Device Meta Card */
  .device-card {
    padding: 0.85rem 0.75rem;
    border-radius: 10px;
  }

  .search-section {
    margin-bottom: 0.85rem;
    padding-bottom: 0.75rem;
  }

  .search-input-group label {
    font-size: 0.8rem;
  }

  .input-with-button {
    display: flex;
    flex-direction: column;
    width: 100%;
    gap: 0.45rem;
  }

  .autocomplete-wrapper {
    width: 100% !important;
  }

  .autocomplete-wrapper input {
    width: 100% !important;
    font-size: 0.9rem;
    padding: 0.65rem 2.2rem 0.65rem 2.25rem;
  }

  .input-with-button > #btn-search {
    width: 100%;
    justify-content: center;
    padding: 0.65rem 1rem;
    font-size: 0.9rem;
  }

  .btn-clear-input {
    width: 22px !important;
    height: 22px !important;
    min-width: 22px !important;
    max-width: 22px !important;
    min-height: 22px !important;
    max-height: 22px !important;
    padding: 0 !important;
    margin: 0 !important;
    top: 50% !important;
    right: 0.65rem !important;
    transform: translateY(-50%) !important;
    border-radius: 50% !important;
  }

  .device-meta-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 0.45rem !important;
  }

  .meta-item {
    padding: 0.45rem 0.6rem;
  }

  .meta-label {
    font-size: 0.65rem;
  }

  .meta-value {
    font-size: 0.775rem;
  }

  /* 4. Action Toolbar */
  .action-toolbar {
    padding: 0.65rem;
    flex-direction: column;
    align-items: stretch;
    gap: 0.55rem;
    border-radius: 10px;
  }

  .toolbar-left {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.45rem;
    width: 100%;
  }

  #btn-recheck {
    grid-column: span 2;
    width: 100%;
    justify-content: center;
    padding: 0.7rem 1rem;
    font-size: 0.9rem;
  }

  #btn-auto-poll,
  #btn-clear-history {
    width: 100%;
    justify-content: center;
    padding: 0.45rem 0.4rem;
    font-size: 0.75rem;
  }

  .toolbar-right {
    flex-direction: column;
    width: 100%;
    gap: 0.45rem;
  }

  .filter-box {
    width: 100%;
  }

  .filter-box input {
    width: 100%;
    font-size: 0.8rem;
    padding: 0.5rem 0.75rem;
  }

  #btn-export-csv {
    width: 100%;
    justify-content: center;
    padding: 0.55rem 1rem;
    font-size: 0.825rem;
  }

  /* 5. Matrix Card & Table Container */
  .matrix-card {
    border-radius: 10px;
  }

  .matrix-header-bar {
    padding: 0.75rem 0.75rem;
    gap: 0.5rem;
  }

  .matrix-title {
    font-size: 0.9rem;
  }

  .matrix-desc {
    font-size: 0.725rem;
    line-height: 1.35;
  }

  .legend-bar {
    gap: 0.35rem 0.65rem;
    font-size: 0.65rem;
  }

  /* 6. Vertical Full-Height Natural Expansion (No Internal Scroll) */
  .table-scroll-wrapper {
    overflow-x: auto;
    overflow-y: visible !important;
    max-height: none !important;
    min-height: auto !important;
    -webkit-overflow-scrolling: touch;
  }

  /* 7. Mobile Table: Dedicated Portrait Column Optimization */
  /* Hide desktop separate Description and CID columns on mobile */
  .matrix-table th.col-desc,
  .matrix-table td.col-desc,
  .matrix-table th.col-cid,
  .matrix-table td.col-cid {
    display: none !important;
  }

  /* Display destination description inside col-port directly */
  .port-name {
    display: block;
    font-weight: 700;
    font-size: 0.72rem;
    letter-spacing: -0.2px;
    color: var(--primary);
    line-height: 1.2;
    word-break: break-word;
  }

  .port-desc-sub {
    display: block !important;
    font-size: 0.65rem;
    font-weight: 400;
    color: var(--text-muted);
    white-space: normal;
    word-break: break-word;
    line-height: 1.25;
    margin-top: 3px;
  }

  .port-cid-sub {
    display: block !important;
    font-size: 0.65rem;
    font-weight: 700;
    color: #0284c7;
    font-family: 'Inter', monospace;
    margin-top: 2px;
    letter-spacing: -0.1px;
  }

  /* Sticky Port column (130px) */
  .col-port {
    position: sticky;
    left: 0 !important;
    z-index: 30;
    width: 130px !important;
    min-width: 130px !important;
    max-width: 130px !important;
    padding: 0.45rem 0.45rem !important;
    white-space: normal !important;
  }

  /* Sticky Link status column right next to Port column (48px at left: 130px) */
  .col-status {
    position: sticky;
    left: 130px !important;
    z-index: 30;
    width: 48px !important;
    min-width: 48px !important;
    max-width: 48px !important;
    padding: 0.45rem 0.2rem !important;
    border-right: 2px solid var(--border-strong) !important;
  }

  .matrix-table th.col-port {
    z-index: 40;
    left: 0 !important;
    width: 130px !important;
    min-width: 130px !important;
    max-width: 130px !important;
    padding: 0.45rem 0.45rem !important;
  }

  .matrix-table th.col-status {
    z-index: 40;
    left: 130px !important;
    width: 48px !important;
    min-width: 48px !important;
    max-width: 48px !important;
    padding: 0.45rem 0.2rem !important;
  }

  /* Optical Power Columns: 130px wide, directly visible in portrait */
  .col-time-header {
    width: 130px !important;
    min-width: 130px !important;
    max-width: 130px !important;
    padding: 0.35rem 0.25rem !important;
  }

  .time-title {
    font-size: 0.725rem;
  }

  .time-label {
    font-size: 0.6rem;
  }

  .col-time-cell {
    width: 130px !important;
    min-width: 130px !important;
    max-width: 130px !important;
    padding: 0.35rem 0.25rem !important;
  }

  .power-matrix-cell {
    gap: 0.15rem;
  }

  .power-line {
    gap: 0.2rem;
  }

  .power-tag {
    font-size: 0.55rem;
    padding: 0.05rem 0.2rem;
    width: 22px;
  }

  .power-reading {
    font-size: 0.7rem;
    padding: 0.1rem 0.3rem;
  }

  .power-reading .num {
    font-size: 0.725rem;
  }

  .power-reading .unit {
    font-size: 0.575rem;
  }

  .diff-tag {
    font-size: 0.6rem;
    padding: 0.05rem 0.2rem;
  }

  .lock-modal-card {
    padding: 1.5rem 1.25rem;
    max-width: 95vw;
  }
}

/* Waiting for OTP Auto-Resume Animation */
.btn.waiting-otp {
  background: #f59e0b !important;
  color: #ffffff !important;
  border-color: #d97706 !important;
  cursor: wait !important;
  animation: pulse-otp 2s infinite ease-in-out;
}
@keyframes pulse-otp {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.88; transform: scale(0.99); }
}

/* Uplink Node Link in Description (Minimal & Clean) */
.node-link {
  color: #0284c7;
  text-decoration: underline;
  text-underline-offset: 2px;
  font-weight: 600;
  cursor: pointer;
  transition: color 0.15s ease;
}
.node-link:hover {
  color: #0369a1;
}

/* Site Information Display Box (Clean Light Theme) */
.site-info-container {
  display: flex;
  align-items: center;
  align-self: flex-end;
  background: #f0f9ff;
  border: 1px solid #bae6fd;
  border-radius: 8px;
  padding: 0.45rem 0.85rem;
  transition: all 0.2s ease;
  min-height: 42px;
}

.site-info-container.hidden {
  display: none !important;
}

.site-info-inner {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.site-info-pin {
  font-size: 1.15rem;
  line-height: 1;
}

.site-info-text-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.site-code-badge {
  background: #0284c7;
  color: #ffffff;
  font-weight: 700;
  font-size: 0.85rem;
  padding: 0.2rem 0.6rem;
  border-radius: 6px;
  letter-spacing: 0.3px;
  font-family: inherit;
  box-shadow: 0 1px 2px rgba(2, 132, 199, 0.2);
}

.site-name-text {
  color: #0f172a;
  font-weight: 600;
  font-size: 0.95rem;
  letter-spacing: 0.1px;
}

@media (max-width: 768px) {
  .site-info-container {
    width: 100%;
    align-self: stretch;
    justify-content: flex-start;
  }
}

/* --- OpticalCheckerAgent & Adaptive Matrix Design (v1.7.0) --- */
.badge-agent {
  background: #f0fdf4;
  color: #166534;
  border: 1px solid #bbf7d0;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  cursor: pointer;
  user-select: none;
  transition: all 0.2s ease;
}

.badge-agent:hover {
  filter: brightness(0.96);
  transform: translateY(-1px);
}

.badge-agent.shared {
  background: #f0fdfa;
  color: #0f766e;
  border-color: #99f6e4;
}

.badge-agent.standby {
  background: #fefce8;
  color: #854d0e;
  border-color: #fef08a;
}

.badge-agent.standby .agent-dot {
  background: #eab308;
  box-shadow: 0 0 0 2px rgba(234, 179, 8, 0.2);
}

.badge-agent.offline {
  background: #f8fafc;
  color: #64748b;
  border-color: #e2e8f0;
}

.badge-agent.offline .agent-dot {
  background: #94a3b8;
}

.badge-manual {
  display: inline-flex;
  align-items: center;
  font-size: 0.675rem;
  font-weight: 700;
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  background: #fef3c7;
  color: #b45309;
  border: 1px solid #fde68a;
  margin-left: 0.3rem;
  vertical-align: middle;
}

.agent-info-card {
  max-width: 520px;
  width: 92%;
  text-align: left;
}

.agent-status-panel {
  padding: 0.75rem;
  border-radius: 8px;
  margin-bottom: 0.75rem;
  font-size: 0.825rem;
  line-height: 1.4;
}

.btn-download-agent {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.35rem 0.65rem;
  font-size: 0.775rem;
  font-weight: 600;
  color: #0284c7;
  background: #f0f9ff;
  border: 1px solid #bae6fd;
  border-radius: 6px;
  text-decoration: none;
  transition: all 0.2s ease;
}

.btn-download-agent:hover {
  background: #e0f2fe;
  border-color: #7dd3fc;
  color: #0369a1;
}

/* SFP Type Badge */
.col-sfp {
  width: 115px;
  min-width: 115px;
  max-width: 115px;
  text-align: center;
}

.sfp-pill {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0.2rem 0.45rem;
  font-size: 0.72rem;
  font-weight: 700;
  border-radius: 6px;
  line-height: 1.15;
  white-space: nowrap;
  cursor: help;
  transition: all 0.15s ease;
}

.sfp-pill:hover {
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
}

.sfp-pill-1c {
  background: #ecfdf5;
  color: #065f46;
  border: 1px solid #a7f3d0;
}

.sfp-pill-1c:hover {
  background: #d1fae5;
  border-color: #6ee7b7;
}

.sfp-pill-2c {
  background: #eff6ff;
  color: #1e40af;
  border: 1px solid #bfdbfe;
}

.sfp-pill-2c:hover {
  background: #dbeafe;
  border-color: #93c5fd;
}

.sfp-pill-unknown {
  background: #f8fafc;
  color: #64748b;
  border: 1px solid #e2e8f0;
}

.sfp-pill-unknown:hover {
  background: #f1f5f9;
  border-color: #cbd5e1;
}

.sfp-wave-sub {
  font-size: 0.65rem;
  font-weight: 500;
  opacity: 0.85;
}

/* Matrix Metric Column (RX / TX row indicator) */
.col-metric {
  width: 38px;
  min-width: 38px;
  max-width: 38px;
  text-align: center;
  background: #f8fafc;
  border-right: 1px solid #e2e8f0;
  padding: 0.35rem 0.15rem !important;
}

.metric-lines {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  align-items: center;
  justify-content: center;
}

.metric-tag {
  font-size: 0.65rem;
  font-weight: 700;
  padding: 0.1rem 0.3rem;
  border-radius: 4px;
  line-height: 1;
}

.metric-tag.tag-rx {
  background: #e0f2fe;
  color: #0369a1;
}

.metric-tag.tag-tx {
  background: #f1f5f9;
  color: #475569;
}

/* Slim Group Headers */
.header-group-row th {
  border-bottom: 1px solid #cbd5e1 !important;
  text-align: center;
}

.header-sub-row th {
  padding: 0.25rem 0.4rem !important;
  font-size: 0.72rem !important;
  font-weight: 700 !important;
  text-align: center !important;
  background: #f8fafc;
  color: #475569;
  border-bottom: 2px solid #cbd5e1 !important;
}

.col-sub-header.col-node {
  border-right: 1px dashed #e2e8f0;
}

.col-sub-header.col-cpe {
  border-right: 1px solid #cbd5e1;
}

/* Slim Reading Cell */
.col-slim-reading {
  padding: 0.3rem 0.35rem !important;
  width: 72px;
  min-width: 72px;
  max-width: 85px;
  text-align: center;
  vertical-align: middle;
}

.col-slim-reading.col-node-cell {
  border-right: 1px dashed #e2e8f0;
}

.col-slim-reading.col-cpe-cell {
  border-right: 1px solid #cbd5e1;
}

.slim-reading-cell {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  align-items: center;
  justify-content: center;
}

.slim-line {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.2rem;
  font-size: 0.8rem;
  font-weight: 600;
  line-height: 1.1;
  width: 100%;
}

.slim-num {
  font-family: 'Inter', -apple-system, monospace;
  font-weight: 700;
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
}

.slim-diff {
  font-size: 0.62rem;
  font-weight: 700;
  line-height: 1;
}


