/* ── Diagnostics Grid ── */
.diag-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.diag-col {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ── Terminals (Serial Console & Logs) ── */
.term {
  flex: 1;
  min-height: 320px;
  max-height: 480px;
  overflow-y: auto;
  padding: 12px 14px;
  background: var(--bg-term);
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  line-height: 1.8;
  word-break: break-all;
  color: var(--txt);
}
.term::-webkit-scrollbar { width: 5px; }
.term::-webkit-scrollbar-track { background: transparent; }
.term::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.08); border-radius: 3px; }
.term::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.16); }

/* ── Console Input ── */
.c-input {
  display: flex;
  border-top: 1px solid var(--brd);
}
.c-input input {
  flex: 1;
  padding: 10px 14px;
  background: rgba(0, 0, 0, 0.35);
  border: none;
  color: var(--txt);
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  outline: none;
}
.c-input input::placeholder { color: var(--txt3); }
.c-input button {
  padding: 10px 18px;
  background: linear-gradient(135deg, var(--blue), var(--cyan));
  color: #000;
  border: none;
  font-weight: 600;
  font-size: 11px;
  cursor: pointer;
  transition: opacity 0.15s;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.c-input button:hover { opacity: 0.85; }

/* ── Log Controls Toolbar ── */
.l-ctrl {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.l-ctrl select, .l-ctrl input[type=text] {
  padding: 3px 7px;
  font-size: 10px;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--brd);
  border-radius: 5px;
  color: var(--txt);
  outline: none;
}
.l-ctrl select { cursor: pointer; }
.l-ctrl label {
  font-size: 10px;
  color: var(--txt2);
  display: flex;
  align-items: center;
  gap: 3px;
  white-space: nowrap;
}
.l-ctrl input[type=checkbox] { accent-color: var(--blue); }

/* ── Log & Console Line Elements ── */
.rx { color: var(--green); }
.tx { color: var(--blue); }
.sys { color: var(--cyan); font-style: italic; }
.ota-line { color: var(--purple); }
.ll {
  padding: 3px 6px;
  border-radius: 4px;
  transition: background 0.15s, border-color 0.15s;
  display: flex;
  align-items: flex-start;
  flex-wrap: nowrap;
  gap: 8px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11.5px;
  line-height: 1.5;
}
.ll:hover { background: rgba(255, 255, 255, 0.03); }
.ll.WARNING { border-left: 3px solid var(--amber); background: rgba(251, 191, 36, 0.03); padding-left: 6px; }
.ll.ERROR { border-left: 3px solid var(--red); background: rgba(248, 113, 113, 0.03); padding-left: 6px; }
.lt { color: #94a3b8; display: inline-block; min-width: 170px; max-width: 170px; flex-shrink: 0; font-size: 11px; white-space: nowrap; }
.ln { font-weight: 600; display: inline-block; min-width: 100px; max-width: 150px; flex-shrink: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11px; }
.lv { font-weight: 700; display: inline-block; min-width: 54px; max-width: 54px; flex-shrink: 0; text-align: center; font-size: 10px; border-radius: 3px; }
.lv.DEBUG { color: #a0aec0; background: rgba(160, 174, 192, 0.1); padding: 1px 4px; }
.lv.INFO { color: var(--cyan); background: rgba(34, 211, 238, 0.1); padding: 1px 4px; }
.lv.WARNING { color: var(--amber); background: rgba(251, 191, 36, 0.1); padding: 1px 4px; }
.lv.ERROR { color: var(--red); background: rgba(248, 113, 113, 0.1); padding: 1px 4px; }
.lm { flex: 1 1 auto; min-width: 0; word-break: normal; overflow-wrap: break-word; white-space: pre-wrap; color: var(--txt); }
.l-dup {
  color: var(--amber);
  background: rgba(251, 191, 36, 0.12);
  border: 1px solid rgba(251, 191, 36, 0.18);
  font-weight: 600;
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 10px;
  flex-shrink: 0;
  align-self: center;
}

/* ── Panel Zoom / Full-Screen Mode ── */
.panel.maximized {
  position: fixed !important;
  inset: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  z-index: 99999 !important;
  background: var(--bg) !important;
  border-radius: 0 !important;
  border: none !important;
  display: flex !important;
  flex-direction: column !important;
  padding: 0 !important;
  margin: 0 !important;
  box-shadow: 0 0 60px rgba(0, 0, 0, 0.95) !important;
}

.panel.maximized .p-head {
  background: var(--bg2) !important;
  padding: 12px 20px !important;
  border-bottom: 1px solid var(--brd) !important;
  flex-shrink: 0 !important;
  border-radius: 0 !important;
}

.panel.maximized .term {
  flex: 1 1 auto !important;
  max-height: none !important;
  height: 100% !important;
  border-radius: 0 !important;
  border: none !important;
  padding: 14px 20px !important;
  overflow-y: auto !important;
}

.panel.maximized .c-input {
  flex-shrink: 0 !important;
  border-radius: 0 !important;
  border-left: none !important;
  border-right: none !important;
  border-bottom: none !important;
  padding: 10px 20px !important;
  background: var(--bg2) !important;
}

.panel.maximized .builder-sec {
  flex-shrink: 0 !important;
  border-radius: 0 !important;
}

body.has-maximized-panel {
  overflow: hidden !important;
}

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

@media (max-width: 768px) {
  .panel.maximized .p-head {
    padding: 10px 14px !important;
  }
  .panel.maximized .term {
    padding: 10px 14px !important;
  }
  .panel.maximized .c-input {
    padding: 8px 14px !important;
  }
}

/* ── Searchable Log Source Dropdown ── */
.log-src-wrap {
  position: relative;
  display: inline-block;
}
.log-src-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: 170px;
  padding: 3px 8px;
  background: var(--bg2);
  color: var(--txt);
  border: 1px solid var(--brd);
  border-radius: var(--rs);
  font-size: 11px;
  cursor: pointer;
  transition: all 0.15s;
}
.log-src-btn:hover {
  border-color: var(--brd-h);
  background: rgba(255, 255, 255, 0.05);
}
.log-src-label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  font-weight: 500;
}
.log-src-menu {
  position: absolute;
  left: 0;
  top: calc(100% + 4px);
  width: 280px;
  max-width: calc(100vw - 24px);
  box-sizing: border-box;
  background: rgba(17, 24, 39, 0.98);
  border: 1px solid var(--brd-h);
  border-radius: var(--r);
  padding: 8px;
  z-index: 2000;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(16px);
}
.log-src-menu.drop-up {
  top: auto;
  bottom: calc(100% + 4px);
  box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.7);
}
.log-src-menu.align-right {
  left: auto;
  right: 0;
}
.log-src-search {
  width: 100%;
  padding: 6px 10px;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--brd);
  border-radius: var(--rs);
  color: var(--txt);
  font-size: 11px;
  margin-bottom: 6px;
  outline: none;
  box-sizing: border-box;
}
.log-src-search:focus {
  border-color: var(--cyan);
}
.log-src-list {
  max-height: min(280px, calc(100vh - 160px));
  max-height: min(280px, calc(100dvh - 160px));
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.log-src-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 8px;
  border-radius: 4px;
  font-size: 11px;
  color: var(--txt2);
  cursor: pointer;
  transition: all 0.1s;
  font-family: 'JetBrains Mono', monospace;
  user-select: none;
}
.log-src-item:hover {
  background: rgba(56, 189, 248, 0.12);
  color: var(--txt);
}
.log-src-item.active {
  background: rgba(56, 189, 248, 0.2);
  color: var(--cyan);
  font-weight: 600;
}
.log-src-badge {
  font-size: 9px;
  padding: 1px 4px;
  border-radius: 3px;
  background: rgba(0, 0, 0, 0.35);
  color: var(--txt3);
}
.log-src-group-title {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--txt3);
  padding: 6px 8px 2px;
  margin-top: 4px;
  border-top: 1px solid rgba(255, 255, 255, 0.04);
}
.log-src-group-title:first-child {
  margin-top: 0;
  border-top: none;
}

/* ── File Manager Modal & Elements ── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  animation: modalFadeIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalFadeIn {
  from { opacity: 0; transform: scale(0.98); }
  to { opacity: 1; transform: scale(1); }
}

.modal-window {
  background: rgba(17, 24, 39, 0.98);
  border: 1px solid var(--brd-h);
  border-radius: var(--r);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.8), 0 0 30px rgba(56, 189, 248, 0.1);
  display: flex;
  flex-direction: column;
  max-height: 90vh;
  max-height: calc(100dvh - 32px);
  overflow: hidden;
}

.file-mgr-modal {
  width: 920px;
  max-width: calc(100vw - 24px);
  height: min(680px, calc(100dvh - 32px));
}

.modal-header {
  padding: 14px 20px;
  background: var(--bg2);
  border-bottom: 1px solid var(--brd);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.modal-close-btn {
  background: none;
  border: none;
  color: var(--txt2);
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--rs);
  transition: all 0.15s;
}
.modal-close-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--txt);
}

.file-mgr-stats {
  font-size: 11px;
  color: var(--txt3);
  margin-top: 2px;
}

.file-mgr-body {
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 1;
  overflow: hidden;
}

.file-mgr-tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--brd);
  padding-bottom: 8px;
}

.file-tab {
  padding: 6px 12px;
  font-size: 11px;
  font-weight: 500;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--brd);
  border-radius: var(--rs);
  color: var(--txt2);
  cursor: pointer;
  transition: all 0.15s;
}
.file-tab:hover {
  background: rgba(56, 189, 248, 0.08);
  color: var(--txt);
}
.file-tab.active {
  background: rgba(56, 189, 248, 0.15);
  color: var(--cyan);
  border-color: rgba(34, 211, 238, 0.4);
  font-weight: 600;
}

.file-mgr-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

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

.file-mgr-search {
  width: 100%;
  padding: 6px 28px 6px 10px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--brd);
  border-radius: var(--rs);
  color: var(--txt);
  font-size: 11px;
  outline: none;
  box-sizing: border-box;
}
.file-mgr-search:focus {
  border-color: var(--cyan);
}

.file-mgr-search-clear {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--txt3);
  cursor: pointer;
  font-size: 12px;
}

.file-mgr-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.btn-danger {
  background: rgba(248, 113, 113, 0.15) !important;
  color: var(--red) !important;
  border: 1px solid rgba(248, 113, 113, 0.3) !important;
}
.btn-danger:hover:not(:disabled) {
  background: rgba(248, 113, 113, 0.3) !important;
  border-color: var(--red) !important;
}
.btn-danger:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.file-mgr-table-wrap {
  flex: 1;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--brd);
  border-radius: var(--rs);
}

.file-mgr-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11.5px;
  text-align: left;
}

.file-mgr-table th {
  position: sticky;
  top: 0;
  background: var(--bg2);
  color: var(--txt3);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 9.5px;
  letter-spacing: 0.5px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--brd);
  z-index: 1;
}

.file-mgr-table td {
  padding: 7px 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
  color: var(--txt2);
  vertical-align: middle;
}

.file-mgr-table tr:hover td {
  background: rgba(255, 255, 255, 0.02);
  color: var(--txt);
}

.file-mgr-table tr.selected td {
  background: rgba(56, 189, 248, 0.08);
}

.file-name-cell {
  font-family: 'JetBrains Mono', monospace;
  color: var(--txt);
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 6px;
  word-break: break-all;
}

.file-badge {
  font-size: 9.5px;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 600;
  display: inline-block;
}
.file-badge.device {
  background: rgba(56, 189, 248, 0.12);
  color: var(--blue);
}
.file-badge.system {
  background: rgba(167, 139, 250, 0.12);
  color: var(--purple);
}
.file-badge.rotated {
  background: rgba(251, 191, 36, 0.12);
  color: var(--amber);
}
.file-badge.other {
  background: rgba(255, 255, 255, 0.08);
  color: var(--txt3);
}

.file-size-badge {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  color: var(--txt2);
  font-weight: 500;
}
.file-size-badge.empty {
  color: var(--txt3);
  opacity: 0.7;
}
.file-size-badge.large {
  color: var(--amber);
  font-weight: 700;
}

.file-date-cell {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10.5px;
  color: var(--txt3);
}

.file-actions-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.file-act-btn {
  padding: 3px 6px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--brd);
  border-radius: 4px;
  color: var(--txt2);
  font-size: 11px;
  cursor: pointer;
  transition: all 0.15s;
}
.file-act-btn:hover {
  background: rgba(56, 189, 248, 0.15);
  color: var(--cyan);
  border-color: var(--cyan);
}
.file-act-btn.delete:hover {
  background: rgba(248, 113, 113, 0.2);
  color: var(--red);
  border-color: var(--red);
}

.modal-footer {
  padding: 12px 20px;
  background: var(--bg2);
  border-top: 1px solid var(--brd);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

/* ── Log dropdown quick delete icon ── */
.log-src-item .log-src-quick-del {
  opacity: 0;
  margin-left: 6px;
  padding: 1px 4px;
  border-radius: 3px;
  background: transparent;
  border: none;
  color: var(--txt3);
  font-size: 10px;
  cursor: pointer;
  transition: all 0.15s;
}
.log-src-item:hover .log-src-quick-del {
  opacity: 0.8;
}
.log-src-item .log-src-quick-del:hover {
  opacity: 1;
  color: var(--red);
  background: rgba(248, 113, 113, 0.2);
}

/* ── Log Search Highlights & Input Styling ── */
.log-mark {
  background: rgba(251, 191, 36, 0.45);
  color: #fff;
  font-weight: 600;
  border-radius: 2px;
  padding: 0 2px;
  box-shadow: 0 0 4px rgba(251, 191, 36, 0.5);
}

.log-search-wrap input {
  transition: all 0.15s ease;
}

.log-search-wrap input:focus {
  border-color: var(--cyan) !important;
  box-shadow: 0 0 6px rgba(34, 211, 238, 0.3);
}

.log-search-wrap button:hover {
  color: var(--txt) !important;
}

