/* ========================================================
   Terminal Services v2 - Retro style
   ======================================================== */

:root {
  --bg-color:      #000000;
  --text-color:    #00ff00;
  --text-dim:      #008800;
  --border-color:  #00ff00;
  --error-color:   #ff0000;
  --font-mono:     'JetBrains Mono', 'Fira Code', 'Courier New', monospace;
  --crt-glow: 0 0 12px rgba(0, 255, 0, 0.5);
}

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

/* GLOBAL SCROLLBAR STYLING */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--text-dim) #050505;
}

/* Chrome, Edge, and Safari */
*::-webkit-scrollbar {
    width: 10px;
}

*::-webkit-scrollbar-track {
    background: #050505;
    border-left: 1px solid var(--text-dim);
}

*::-webkit-scrollbar-thumb {
    background: var(--text-dim);
    border: 2px solid #050505;
}

*::-webkit-scrollbar-thumb:hover {
    background: var(--text-color);
}

html, body {
  height: 100%;
  background-color: var(--bg-color);
  color: var(--text-color);
  font-family: var(--font-mono);
  overflow: hidden;
  text-shadow: var(--crt-glow);
}

#bgMatrixCanvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  z-index: 0;
  opacity: 0.55; /* Slightly increased for better visibility */
  pointer-events: none;
}

/* GRID LAYOUT */
.terminal-body {
  display: grid;
  grid-template-columns: 200px 1fr;
  grid-template-rows: auto 1fr;
  grid-template-areas:
    "header header"
    "sidebar main";
  height: 100vh;
  background-color: rgba(0, 0, 0, 0.6); /* Semi-transparent background */
}

.top-header {
  grid-area: header;
  position: relative;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border-color);
  background: rgba(8, 8, 8, 0.4);
}

.term-title {
  font-weight: bold;
  font-size: 1.1rem;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 20px;
}

.btn-logout {
  color: var(--text-color);
  text-decoration: underline;
  font-size: 0.9rem;
}

.term-sidebar {
  grid-area: sidebar;
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  background: rgba(8, 8, 8, 0.4);
  border-right: 1px solid var(--border-color);
}

.term-nav {
  display: flex;
  flex-direction: column;
  padding: 10px 0;
}

.nav-item {
  padding: 12px 20px;
  color: var(--text-dim);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: bold;
}

.nav-item:hover, .nav-item.active {
  color: var(--text-color);
  background: #001100;
}

.nav-item.active {
  text-decoration: underline;
}

.sidebar-footer {
  margin-top: auto;
  padding: 20px;
  border-top: 1px solid var(--text-dim);
  display: flex;
  flex-direction: column;
  align-items: center;
}

.status-container {
  width: 100%;
  text-align: center;
}

.status-text {
  font-weight: bold;
  font-size: 0.8rem;
}

/* APP UPDATE BUTTON (sidebar footer) */
.btn-app-update {
  display: block;
  width: 100%;
  margin-top: 12px;
  padding: 6px 10px;
  background: transparent;
  border: 1px solid #333;
  color: #444;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: bold;
  cursor: default;
  text-align: center;
  letter-spacing: 0.05em;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}

.btn-app-update.update-available {
  border-color: var(--text-color);
  color: var(--text-color);
  cursor: pointer;
  animation: pulse-border 1.5s ease-in-out infinite;
}

.btn-app-update.update-available:hover {
  background: var(--text-color);
  color: var(--bg-color);
  animation: none;
}

.btn-app-update.update-running {
  border-color: #00ffff;
  color: #00ffff;
  cursor: not-allowed;
  animation: blink 1s infinite;
}

@keyframes pulse-border {
  0%, 100% { box-shadow: 0 0 0 0 rgba(0,255,0,0.5); }
  50%       { box-shadow: 0 0 0 4px rgba(0,255,0,0); }
}

.main-content {
  grid-area: main;
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  height: 100%;
}

/* VIEWS */
.dashboard-wrapper {
  padding: 30px;
  overflow: hidden; /* Scroll handled by children */
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.view-section {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

/* LOGS VIEW SPECIAL CASE: mostly handled by general rules now */
#logsView.dashboard-wrapper {
    flex: 1;
    min-height: 0;
}

.terminal-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  margin-bottom: 20px;
}

.terminal-chrome {
  padding: 5px 20px;
  font-size: 0.8rem;
  border-bottom: 1px solid var(--border-color);
  background: rgba(17, 17, 17, 0.4); /* Transparent chrome */
}

#terminal-container {
    padding: 10px;
}

/* Hide Xterm.js scrollbar */
.xterm-viewport::-webkit-scrollbar {
    display: none;
}
.xterm-viewport {
    scrollbar-width: none;
}

/* TABLES */
.table-responsive {
  width: 100%;
  flex: 1;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  border-bottom: 1px solid var(--text-dim);
}

.device-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 20px;
}

.device-table th, .device-table td {
  text-align: left;
  padding: 12px;
  border: 1px solid var(--text-dim);
}

/* STICKY TABLE HEADERS */
.device-table th {
  position: sticky;
  top: 0;
  background-color: var(--bg-color);
  z-index: 10;
  box-shadow: 0 1px 0 var(--text-dim); /* Adds border bottom without affecting sticky height */
}

.col-metrics {
  min-width: 160px;
}

.col-status {
  width: 100px;
  text-align: center !important;
}

.section-title {
  font-size: 1.2rem;
  text-transform: uppercase;
  border-bottom: 1px solid var(--text-dim);
  padding-bottom: 5px;
  display: inline-block;
}

.btn-update {
  background: transparent;
  border: 1px solid var(--text-color);
  color: var(--text-color);
  padding: 4px 10px;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  cursor: pointer;
}

.btn-update:hover {
  background: var(--text-color);
  color: var(--bg-color);
}

/* ADDITIONAL STYLES */

.reboot-tag {
  color: var(--error-color);
  border: 1px solid var(--error-color);
  padding: 2px 4px;
  font-size: 0.7rem;
  font-weight: bold;
  animation: blink 1s infinite;
  margin-top: 4px;
}

.usage-container {
  width: 100%;
  max-width: 140px;
}

.usage-info {
  display: flex;
  justify-content: space-between;
  font-size: 0.65rem;
  color: var(--text-dim);
  margin-bottom: 2px;
}

.progress-bar {
  width: 100%;
  height: 4px;
  background: #111;
  border: 1px solid #333;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--text-color);
  transition: width 0.3s ease;
}

.progress-fill.usage-low { background: #00ff00; }
.progress-fill.usage-medium { background: #ffff00; }
.progress-fill.usage-high { background: #ff0000; }

.info-metrics-cell {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: flex-start;
  gap: 4px;
  width: 100%;
}

.metrics-container {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.distro-text {
  font-size: 0.75rem;
  color: var(--text-dim);
}

.status-updating {
  color: #00ffff;
  animation: blink 1s infinite;
}

@keyframes blink {
  50% { opacity: 0.5; }
}

.status-badge {
  padding: 2px 8px;
  border-radius: 3px;
  font-size: 0.75rem;
  font-weight: bold;
  display: inline-block;
  min-width: 60px;
  text-align: center;
  border: 1px solid transparent;
}

.status-ok {
  color: var(--text-color);
  border-color: var(--text-color);
}

.status-error {
  color: var(--error-color);
  border-color: var(--error-color);
}

.status-na {
  color: var(--text-dim);
  border-color: var(--text-dim);
}

.status-disabled {
  color: #666;
  border-color: #444;
}

.action-buttons {
  display: flex;
  gap: 8px;
}

.device-icon {
  display: inline-block;
  width: 18px;
  height: 18px;
  vertical-align: middle;
  margin-right: 10px;
  background-color: currentColor;
  -webkit-mask-size: contain;
  mask-size: contain;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-position: center;
  mask-position: center;
}

/* TOAST NOTIFICATIONS */
#toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  min-width: 250px;
  max-width: 400px;
  padding: 15px;
  background: var(--bg-color);
  border: 1px solid var(--border-color);
  color: var(--text-color);
  font-family: var(--font-mono);
  font-size: 0.9rem;
  box-shadow: 0 4px 15px rgba(0, 255, 0, 0.2);
  display: flex;
  align-items: center;
  justify-content: space-between;
  animation: toast-in 0.3s ease-out forwards;
}

.toast.toast-error {
  border-color: var(--error-color);
  color: var(--error-color);
  box-shadow: 0 4px 15px rgba(255, 0, 0, 0.2);
}

.toast.toast-info {
  border-color: #00ffff;
  color: #00ffff;
  box-shadow: 0 4px 15px rgba(0, 255, 255, 0.2);
}

.toast-closing {
  animation: toast-out 0.3s ease-in forwards;
}

@keyframes toast-in {
  from { transform: translateX(120%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

@keyframes toast-out {
  from { transform: translateX(0); opacity: 1; }
  to { transform: translateX(120%); opacity: 0; }
}

/* LOGS VIEW */
.logs-container {
    flex: 1;
    margin-top: 20px;
    background: rgba(5, 5, 5, 0.1); /* Very transparent for logs */
    border: 1px solid var(--text-dim);
    display: flex;
    flex-direction: column;
    min-height: 0;
}

#logsContent {
    flex: 1;
    padding: 15px;
    font-size: 0.85rem;
    line-height: 1.4;
    white-space: pre-wrap;
    word-break: break-all;
    overflow-y: auto;
    color: var(--text-color);
    min-height: 0; /* Important for flex child with overflow to respect parent height */
}

.log-line {
    display: block;
    margin-bottom: 2px;
}

.log-timestamp {
    color: #555;
    font-size: 0.75rem;
}

.log-level {
    font-weight: bold;
    padding: 0 4px;
}

.log-info     { color: #00ff00; } /* Green */
.log-warn     { color: #ffff00; } /* Yellow */
.log-error    { color: #ff0000; } /* Red */
.log-debug    { color: #00ffff; } /* Cyan */
.log-status   { color: #00ff00; } /* Green */
.log-git      { color: #ff00ff; } /* Magenta */
.log-action   { color: #ffffff; background: #333; } /* Inverted */
.log-terminal { color: #888; }    /* Grey */

.log-message {
    color: #ccc;
}

.log-sid {
    color: #0088ff; /* Blue for Session ID */
}

.log-type {
    color: #ffaa00; /* Orange for IN/OUT */
}

.log-data {
    color: #aaa;
}



/* NOTIFICATION BELL & DROPDOWN */
.header-notification-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.notif-bell-btn {
    background: transparent;
    border: none;
    color: var(--text-color);
    cursor: pointer;
    padding: 5px;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s ease;
    outline: none;
}

.notif-bell-btn:hover {
    color: #ffffff;
}

.bell-icon {
    width: 22px;
    height: 22px;
}

.header-notif-badge {
    position: absolute;
    top: 2px;
    right: 2px;
    background: #ff0000;
    color: white;
    font-size: 0.65rem;
    font-weight: bold;
    padding: 1px 4px;
    border-radius: 10px;
    min-width: 15px;
    text-align: center;
    line-height: 1;
    border: 1px solid #000;
}

.notif-dropdown {
    position: absolute;
    top: calc(100% + 15px);
    right: -10px;
    width: 320px;
    background: rgba(10, 10, 10, 0.95);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border-color);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5), 0 0 15px rgba(0, 255, 0, 0.1);
    z-index: 1000;
    display: none;
    flex-direction: column;
    animation: dropdown-in 0.2s ease-out;
}

.notif-dropdown.show {
    display: flex;
}

@keyframes dropdown-in {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

.notif-dropdown::before {
    content: '';
    position: absolute;
    top: -6px;
    right: 18px;
    width: 10px;
    height: 10px;
    background: rgba(10, 10, 10, 0.95);
    border-top: 1px solid var(--border-color);
    border-left: 1px solid var(--border-color);
    transform: rotate(45deg);
}

.notif-dropdown-header {
    padding: 12px 15px;
    border-bottom: 1px solid #222;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.9rem;
    font-weight: bold;
    color: #fff;
}

.btn-clear-all {
    background: transparent;
    border: none;
    color: var(--text-dim);
    font-family: var(--font-mono);
    font-size: 0.75rem;
    cursor: pointer;
    text-decoration: underline;
}

.btn-clear-all:hover {
    color: var(--text-color);
}

.notif-dropdown-list {
    max-height: 400px;
    overflow-y: auto;
}

.notif-item {
    padding: 12px 15px;
    border-bottom: 1px solid #1a1a1a;
    display: flex;
    gap: 12px;
    transition: background 0.2s ease;
    cursor: default;
}

.notif-item:hover {
    background: rgba(0, 255, 0, 0.05);
}

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

.notif-item-icon {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    background: rgba(255, 255, 255, 0.1);
}

.notif-item-success .notif-item-icon { color: #00ff00; background: rgba(0, 255, 0, 0.1); }
.notif-item-error .notif-item-icon { color: #ff0000; background: rgba(255, 0, 0, 0.1); }
.notif-item-info .notif-item-icon { color: #00ffff; background: rgba(0, 255, 255, 0.1); }

.notif-item-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.notif-item-title {
    font-size: 0.85rem;
    font-weight: bold;
    color: #eee;
}

.notif-item-msg {
    font-size: 0.8rem;
    color: #aaa;
    line-height: 1.3;
}

.notif-item-time {
    font-size: 0.7rem;
    color: var(--text-dim);
    margin-top: 4px;
}

.notif-item-delete {
    opacity: 0;
    cursor: pointer;
    color: #666;
    transition: opacity 0.2s, color 0.2s;
}

.notif-item:hover .notif-item-delete {
    opacity: 1;
}

.notif-item-delete:hover {
    color: #ff0000;
}

.notif-dropdown-empty {
    padding: 30px 20px;
    text-align: center;
    color: var(--text-dim);
    font-size: 0.85rem;
}

/* UPDATE LOADING OVERLAY */
.update-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: #000;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

#matrixCanvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0.75;
}

.overlay-content {
    position: relative;
    z-index: 1;
    width: 90%;
    max-width: 500px;
}

.terminal-loader {
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 2px solid var(--border-color);
    padding: 30px;
    box-shadow: 0 0 40px rgba(0, 255, 0, 0.25), inset 0 0 20px rgba(0, 0, 0, 0.5);
    position: relative;
}

.terminal-loader::before {
    display: none; /* Removed in favor of global .crt-overlay */
}

.loader-header {
    display: flex;
    justify-content: space-between;
    border-bottom: 1px solid var(--text-dim);
    padding-bottom: 10px;
    margin-bottom: 20px;
    font-weight: bold;
    letter-spacing: 2px;
}

.loader-label {
    color: var(--text-color);
    text-shadow: 0 0 10px rgba(0, 255, 0, 0.5);
}

.loader-dots {
    animation: blink 1s infinite;
}

.loader-body {
    text-align: center;
    padding: 20px 0;
}

#updateStatusText {
    font-size: 1.1rem;
    color: var(--text-color);
    margin-bottom: 15px;
    text-transform: uppercase;
}

.loader-subtext {
    font-size: 0.75rem;
    color: var(--text-dim);
    letter-spacing: 1px;
}

.loader-footer {
    display: flex;
    justify-content: space-between;
    margin-top: 25px;
    padding-top: 10px;
    border-top: 1px solid #1a1a1a;
    font-size: 0.7rem;
    color: #444;
}

.reconnect-status {
    color: #00ffff;
    animation: blink 1.5s infinite;
}

/* GLOBAL CRT OVERLAY */
.crt-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.18) 50%), 
                linear-gradient(90deg, rgba(255, 0, 0, 0.06), rgba(0, 255, 0, 0.02), rgba(0, 0, 255, 0.06)),
                radial-gradient(circle, rgba(0,0,0,0) 60%, rgba(0,0,0,0.3) 100%);
    background-size: 100% 3px, 3px 100%, 100% 100%;
    z-index: 20000;
    pointer-events: none;
    opacity: 0.85;
}

.crt-overlay::after {
    content: " ";
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    background: rgba(18, 16, 16, 0.1);
    opacity: 0;
    z-index: 20001;
    pointer-events: none;
    animation: flicker 0.15s infinite;
}

@keyframes flicker {
    0% { opacity: 0.0278; }
    5% { opacity: 0.0347; }
    10% { opacity: 0.0236; }
    15% { opacity: 0.0506; }
    20% { opacity: 0.0181; }
    25% { opacity: 0.0438; }
    30% { opacity: 0.0355; }
    35% { opacity: 0.0378; }
    40% { opacity: 0.0265; }
    45% { opacity: 0.0446; }
    50% { opacity: 0.0500; }
    55% { opacity: 0.0085; }
    60% { opacity: 0.0203; }
    65% { opacity: 0.0419; }
    70% { opacity: 0.0334; }
    75% { opacity: 0.0272; }
    80% { opacity: 0.0414; }
    85% { opacity: 0.0404; }
    90% { opacity: 0.0400; }
    95% { opacity: 0.0261; }
    100% { opacity: 0.0243; }
}

/* We want flicker to be very subtle */
.crt-overlay::after {
    animation: flicker 4s infinite; /* Significantly increased duration */
    opacity: 0.02; /* Lower base opacity */
}

/* ========================================================
   RESPONSIVE LAYOUT (MOBILE PREPARATION)
   ======================================================== */

@media (max-width: 768px) {
    /* Adjust grid layout for mobile devices */
    .terminal-body {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto 1fr;
        grid-template-areas:
            "header"
            "sidebar"
            "main";
        height: 100dvh;
        overflow: hidden;
    }

    /* Shrink Header elements to fit screen */
    .top-header {
        padding: 5px 10px;
    }

    .term-title {
        font-size: 0.9rem;
    }
    
    .session-info {
        display: none; /* Hide admin name on mobile to save horizontal space */
    }
    
    .btn-logout {
        font-size: 0.8rem;
    }

    /* Keep sidebar functional but adapt for mobile */
    .term-sidebar {
        flex-direction: row;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    
    .term-sidebar::-webkit-scrollbar {
        display: none;
    }

    .sidebar-footer {
        flex-direction: row;
        border-top: none;
        border-left: 1px solid var(--text-dim);
        padding: 5px 10px;
        margin-top: 0;
        align-items: center;
        min-width: max-content;
    }

    .term-nav {
        flex-direction: row;
        padding: 0 5px;
        min-width: max-content;
    }

    .nav-item {
        padding: 8px 12px;
        white-space: nowrap;
        font-size: 0.85rem;
    }
    
    /* Reposition update button on mobile */
    .btn-app-update {
        margin-top: 0;
        margin-left: 10px;
        width: auto;
        padding: 4px 10px;
    }

    /* Reduce main content padding */
    .dashboard-wrapper {
        padding: 10px;
    }

    .section-title {
        font-size: 1rem;
    }

    .device-table {
        width: 100%;
    }

    .col-jump-host, .col-ip-address {
        display: none;
    }
    
    .device-table th, .device-table td {
        padding: 4px;
        font-size: 0.7rem;
    }

    .col-metrics {
        min-width: 65px;
    }

    .col-status {
        width: 65px;
    }
    
    .status-badge {
        min-width: 55px;
        padding: 2px 4px;
        font-size: 0.65rem;
    }

    .device-icon {
        display: none;
    }

    #logsContent {
        padding: 5px;
        font-size: 0.6rem;
    }

    #terminal-container {
        padding: 2px;
    }

    /* Adapt notification dropdown width */
    .notif-dropdown {
        position: fixed;
        width: 90vw;
        right: 5vw;
        top: 50px;
        max-width: 320px;
    }
    
    .notif-dropdown::before {
        display: none; /* Remove pointer arrow since it's centered */
    }

    /* Reposition Toasts to fit bottom screen neatly */
    #toast-container {
        top: auto;
        bottom: 20px;
        left: 5vw;
        right: 5vw;
        align-items: center;
    }
    
    .toast {
        min-width: 0;
        width: 100%;
        max-width: 100%;
        font-size: 0.8rem;
        padding: 10px;
    }
}

/* PULL TO REFRESH */
.pull-to-refresh {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    color: var(--text-color);
    font-size: 0.8rem;
    z-index: 50;
    transform: translateY(-100%);
    transition: transform 0.2s ease-out;
    background: rgba(8, 8, 8, 0.9);
    border-bottom: 1px solid var(--border-color);
    pointer-events: none;
}
.pull-to-refresh.ptr-refreshing {
    transform: translateY(0);
}
.ptr-icon {
    font-size: 1.4rem;
    margin-bottom: 2px;
    transition: transform 0.2s;
    line-height: 1;
}
.pull-to-refresh.ptr-release .ptr-icon {
    transform: rotate(180deg);
}
.pull-to-refresh.ptr-refreshing .ptr-icon {
    animation: spin-ptr 1s linear infinite;
}
@keyframes spin-ptr { 100% { transform: rotate(360deg); } }
.ptr-text {
    font-weight: bold;
    letter-spacing: 1px;
}
