:root {
  --bg: #0b1220;
  --panel: #0f1724;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --card: #0b1320;
  --card-2: #0f1728;
  --success: #22c55e;
  --danger: #ef4444;
  --glass: rgba(255, 255, 255, 0.03);
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial;
  color-scheme: dark;
}

html,
body {
  height: 100%;
  margin: 0;
  background: linear-gradient(180deg, var(--bg), #07101a 120%);
  color: #e6eef8;
}

.app {
  display: flex;
  height: 100vh;
  gap: 18px;
  padding: 20px;
  box-sizing: border-box;
  overflow: hidden;
}

/* --- Sidebar --- */
.sidebar {
  width: 300px;
  background: linear-gradient(180deg, var(--panel), #071226);
  border-radius: 12px;
  padding: 18px;
  box-shadow: 0 8px 30px rgba(2, 6, 23, 0.6);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
}

.logo {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), #7dd3fc);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #052024;
  font-weight: 700;
  font-size: 18px;
}

.brand h1 {
  margin: 0;
  font-size: 16px;
}

.brand p {
  margin: 0;
  margin-top: 3px;
  font-size: 12px;
  color: var(--muted);
}

.scan-box {
  background: var(--glass);
  padding: 12px;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  border: 1px solid rgba(255, 255, 255, 0.5);
}

.scan-box label {
  font-size: 13px;
  color: var(--muted);
}

.scan-box input {
  width: 100%;
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.04);
  background: transparent;
  color: inherit;
  font-size: 14px;
}

.scan-box .row {
  display: flex;
  gap: 8px;
}

.btn {
  background: var(--accent);
  color: #04202a;
  padding: 8px 10px;
  border-radius: 8px;
  border: none;
  font-weight: 600;
  cursor: pointer;
}

.networks {
  margin-top: 6px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.network-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.5);
  background: linear-gradient(180deg, var(--card), var(--card-2));
}

aside>.networks>.network-item:hover {
  background: linear-gradient(180deg, #1c2f4d, #2e4e93);
  cursor: pointer;
}

.network-item .left {
  display: flex;
  gap: 10px;
  align-items: center;
}

.network-item .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: linear-gradient(180deg, #84cc16, #16a34a);
}

.network-item .meta {
  display: flex;
  flex-direction: column;
  font-size: 13px;
}

.footer {
  margin-top: auto;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
}

/* --- Main --- */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 14px;
  height: 100%;
  min-height: 0;
  position: relative;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.search {
  display: flex;
  gap: 8px;
  align-items: center;
}

.search input {
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.04);
  background: transparent;
  color: inherit;
  min-width: 260px;
}

.stats {
  display: flex;
  gap: 12px;
  align-items: center;
  color: var(--muted);
  font-size: 13px;
}

/* --- Content container --- */
.content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

/* --- Cards --- */
.cards {
  overflow-y: auto;
  overflow-x: hidden;
  padding: 1rem;
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-content: flex-start;
  flex: 1;
  min-height: 0;
}

.device-card {
  flex: 0 1 calc(33.333% - 14px);
  display: flex;
  align-items: flex-start;
  gap: 16px;
  padding: 16px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.5);
  min-width: 280px;
  box-sizing: border-box;
  transition: background 0.2s, transform 0.2s, box-shadow 0.2s;
}

.device-card:hover {
  background: rgba(255, 255, 255, 0.06);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  cursor: pointer;
}

.device-avatar {
  width: 60px;
  height: 60px;
  border-radius: 10px;
  background: #08121a;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: var(--accent);
  flex-shrink: 0;
}

.device-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 6px;
}

.top-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
}

.top-row .name {
  font-size: 15px;
  background: none;
  border: none;
  font-weight: bolder;
  color: white;
}

.top-row .ip {
  font-size: 13px;
  color: var(--muted);
}

.os {
  font-size: 13px;
  color: var(--muted);
  background: none;
  border: none;
}

.ping {
  font-size: 13px;
  color: var(--muted);
  font-weight: bold;
}

.bottom-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 6px;
}

.status {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  padding: 5px 10px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 13px;
}

.status.up {
  background: rgba(34, 197, 94, 0.12);
  color: var(--success);
}

.status.down {
  background: rgba(239, 68, 68, 0.08);
  color: var(--danger);
}

.card-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.btn-ghost {
  background: transparent;
  color: var(--accent);
  border: 1px solid rgba(56, 189, 248, 0.08);
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.shown {
  display: flex;
}

.editing {
  border: 1px rgba(180, 177, 177, 0.781) solid !important;
  border-radius: 2px;
}

/* --- Responsive --- */
@media (max-width: 1400px) {
  .device-card {
    flex: 0 1 calc(50% - 14px);
  }
}

@media (max-width: 900px) {
  .app {
    padding: 14px;
  }

  .device-card {
    flex: 0 1 100%;
    flex-direction: column;
    align-items: flex-start;
  }
}

@media (max-width: 1600px) {
  .device-avatar {
    display: none;
    opacity: 0;
  }
}

/* --- Scan in progress overlay --- */
#scan-in-progress {
  position: absolute;
  left: 50%;
  top: 35%;
  transform: translate(-50%, -50%);
  background: linear-gradient(180deg, #1b2b46, #111c2d);
  box-shadow: 0 0 25px rgba(0, 0, 0, 0.6), inset 0 0 10px rgba(0, 140, 255, 0.2);
  border: 2px solid #0a84ff;
  width: 620px;
  height: 310px;
  border-radius: 18px;
  color: #e0e6f0;
  z-index: 100;
  padding-top: 10px;
  animation: fadeIn 0.6s ease-out;
}

#scan-in-progress p {
  text-align: center;
  font-weight: 600;
  margin: 8px 0;
}

#scan-msg {
  font-size: 22px;
  letter-spacing: 1px;
  color: #79b8ff;
  text-shadow: 0 0 10px rgba(121, 184, 255, 0.5);
}

#scan-interfaces {
  font-size: 15px;
  font-weight: 200 !important;
  color: #c8e4ff;
}

#scan-completed {
  font-size: 14px;
  margin-top: 35%;
  color: #9be07e;
  text-shadow: 0 0 5px rgba(155, 224, 126, 0.5);
  z-index: 10;
}

#wait-for-scan {
  z-index: 9;
  position: absolute;
  left: 50%;
  top: 58%;
  transform: translate(-50%, -50%);
  background: rgba(52, 162, 212, 0.2);
  backdrop-filter: blur(4px);
  border-radius: 20px;
  border: 1px solid rgba(0, 140, 255, 0.4);
  width: 430px;
  height: 70px;
  box-shadow: 0 0 10px rgba(0, 140, 255, 0.2);
}

#scan-host {
  text-align: center;
  font-size: 15px;
  color: #d6efff;
  margin-bottom: 10px;
}

#wait-animation {
  position: relative;
  height: 25px;
}

#mail-icon,
#pc-icon {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(0, 140, 255, 0.15);
  border: 2px solid rgba(0, 140, 255, 0.6);
  border-radius: 8px;
  padding: 8px;
  font-size: 24px;
  box-shadow: 0 0 10px rgba(0, 140, 255, 0.3);
}

#mail-icon {
  left: 5%;
}

#pc-icon {
  right: 5%;
}

#progress-bar {
  position: absolute;
  left: 19%;
  top: 0%;
  transform: translateY(-50%);
  width: 75%;
  height: 8px;
  color: white;
  font-size: 25px;
  font-weight: bold;
  z-index: -1;
}

#cover {
  position: absolute;
  width: 100vw;
  height: 100vh;
  background-color: rgba(24, 24, 39, 0.575);
  z-index: -0;
}

/* --- Selected card --- */
.selected {
  border: 4px white solid;
}

/* --- OS icons --- */
.Linux {
  background-image: url('../media/LinuxICON.png');
  background-size: 100%;
}

.Windows {
  background-image: url('../media/WindowsICON.png');
  background-size: 100%;
}

.Android {
  background-image: url('../media/AndroidICON.png');
  background-size: 100%;
}

/* --- Bottom bar --- */
.bottom-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 64px;
  background: rgba(10, 17, 30, 0.9);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0 20px;
  backdrop-filter: blur(8px);
  z-index: 500;
}

.bottom-bar .btn {
  padding: 10px 18px;
  font-size: 15px;
  border-radius: 10px;
}

#connect-btn {
  margin-right: 3%;
}

.connect-menu {
  position: absolute;
  bottom: 70px;
  right: 6%;
  background: rgba(15, 22, 38, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  padding: 6px 0;
  width: 140px;
  display: flex;
  flex-direction: column;
  backdrop-filter: blur(6px);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

.connect-menu.hidden {
  display: none;
}

.connect-menu .menu-item {
  padding: 10px 14px;
  font-size: 14px;
  color: #e6eef8;
  cursor: pointer;
}

.connect-menu .menu-item:hover {
  background: rgba(56, 189, 248, 0.12);
  color: var(--accent);
}

/* --- SFTP Login Modal --- */
#loginBox {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

#loginBox.visible {
  display: flex;
}

#loginBox .modal-card {
  background: #1e1e2e;
  padding: 28px;
  border-radius: 10px;
  width: 340px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  border: 1px solid #444;
  color: #cdd6f4;
  font-family: 'Consolas', 'JetBrains Mono', monospace;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.7);
}

#loginBox .modal-title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  color: #cdd6f4;
}

#loginBox .modal-title span {
  color: #89b4fa;
}

#loginBox input[type="text"],
#loginBox input[type="password"] {
  width: 100%;
  padding: 9px 11px;
  border-radius: 6px;
  border: 1px solid #555;
  background: #313244;
  color: #cdd6f4;
  font-family: inherit;
  font-size: 13px;
  box-sizing: border-box;
  transition: border-color 0.15s;
}

#loginBox input[type="text"]:focus,
#loginBox input[type="password"]:focus {
  outline: none;
  border-color: #89b4fa;
}

#loginBox .modal-remember {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85em;
  color: #cdd6f4;
  cursor: pointer;
}

#loginBox .modal-error {
  color: #f38ba8;
  font-size: 0.85em;
  min-height: 1em;
}

#loginBox .modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 4px;
}

#loginBox .modal-actions .btn-cancel {
  padding: 8px 16px;
  background: #45475a;
  border: none;
  border-radius: 6px;
  color: #cdd6f4;
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
}

#loginBox .modal-actions .btn-cancel:hover {
  background: #585b70;
}

#loginBox .modal-actions .btn-connect {
  padding: 8px 16px;
  background: #89b4fa;
  border: none;
  border-radius: 6px;
  color: #1e1e2e;
  cursor: pointer;
  font-weight: 700;
  font-family: inherit;
  font-size: 13px;
}

#loginBox .modal-actions .btn-connect:hover {
  background: #b4d0fa;
}

/* ============================================================
   Detail panel
   ============================================================ */

.detail-panel {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 0;
  background: #0d1929;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: height 0.22s ease;
  z-index: 50;
}

.detail-panel.peek {
  height: 160px;
}

.detail-panel.dragging {
  transition: none;
}

.detail-handle {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 14px 4px;
  cursor: ns-resize;
  user-select: none;
  flex-shrink: 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.detail-handle-bar {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.15);
  flex-shrink: 0;
}

.detail-panel-title {
  flex: 1;
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.detail-close-btn {
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 6px;
  flex-shrink: 0;
  line-height: 1;
}

.detail-tabs {
  display: flex;
  gap: 2px;
  padding: 6px 14px 0;
  flex-shrink: 0;
}

.detail-tab {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  font-size: 13px;
  padding: 4px 10px 6px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}

.detail-tab:hover {
  color: #e6eef8;
}

.detail-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.detail-body {
  flex: 1;
  overflow: hidden;
  position: relative;
}

.tab-content {
  display: none;
  height: 100%;
  overflow-y: auto;
  padding: 10px 14px 14px;
  box-sizing: border-box;
}

.tab-content.active {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-content: flex-start;
}

.detail-empty {
  font-size: 13px;
  color: var(--muted);
  margin: 0;
}

.detail-panel .port {
  background: rgba(56, 189, 248, 0.08);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 13px;
  color: #d0eaff;
  white-space: nowrap;
}

.log-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 12px;
  padding: 5px 8px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.03);
  width: 100%;
  box-sizing: border-box;
}

.log-row .log-time {
  color: var(--muted);
  flex-shrink: 0;
  font-size: 11px;
}

.log-row .log-action {
  color: var(--accent);
  flex-shrink: 0;
  font-weight: 600;
  text-transform: uppercase;
  font-size: 11px;
}

.log-row .log-msg {
  color: #c8d8e8;
  flex: 1;
}

.log-row.type-error {
  border-left: 2px solid var(--danger);
}

.log-row.type-info {
  border-left: 2px solid var(--accent);
}

.log-row.type-warning {
  border-left: 2px solid #f59e0b;
}