:root {
    --bg-dark: #0a0b10;
    --card-bg: rgba(255, 255, 255, 0.05);
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --accent: #60a5fa;
    --text-main: #f8fafc;
    --text-dim: #94a3b8;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;

    /* Signal Gradients */
    --gradient-card: linear-gradient(135deg, #fff 0%, #cbd5e1 100%);
    --gradient-success: linear-gradient(135deg, #60a5fa 0%, #3b82f6 100%);
    --gradient-normal: linear-gradient(135deg, #10b981 0%, #34d399 100%);
    --gradient-warning: linear-gradient(135deg, #f59e0b 0%, #fbbf24 100%);
    --gradient-danger: linear-gradient(135deg, #ef4444 0%, #f87171 100%);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Outfit', sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-main);
    min-height: 100vh;
    overflow-x: hidden;
}

.glass-bg {
    position: fixed;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle at center, #1e293b 0%, #0a0b10 70%);
    z-index: -1;
    animation: rotate 60s linear infinite;
}

@keyframes rotate {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

.container {
    width: 95%;
    max-width: 1200px;
    margin: 0 auto;
    padding-bottom: 2rem;
}

.header-container {
    width: 95%;
    max-width: 1200px;
    margin: 0 auto;
    padding-top: 2rem;
    position: relative;
}

.global-logout {
    position: absolute;
    top: 2rem;
    right: 0;
    background: transparent;
    color: var(--text-dim);
    border: none;
    padding: 0.5rem;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    -webkit-appearance: none;
    appearance: none;
    outline: none;
    -webkit-tap-highlight-color: transparent;
}

.global-logout:hover {
    color: var(--danger);
    transform: scale(1.1);
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    flex-wrap: wrap;
    gap: 1rem;
    padding-right: 3.5rem;
    /* Reserve space for absolute logout X */
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo .icon {
    font-size: 2rem;
    filter: drop-shadow(0 0 10px var(--primary));
}

.logo h1 {
    font-size: 1.8rem;
    font-weight: 800;
}

.logo span {
    color: var(--primary);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    color: var(--text-dim);
    background: rgba(255, 255, 255, 0.03);
    padding: 0.5rem 1rem;
    border-radius: 2rem;
}

.pulse {
    width: 8px;
    height: 8px;
    background-color: var(--success);
    border-radius: 50%;
    box-shadow: 0 0 10px var(--success);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    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 10px rgba(16, 185, 129, 0);
    }

    100% {
        transform: scale(0.95);
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0);
    }
}

/* Buttons */
.primary-btn {
    background: var(--primary);
    color: white;
    border: none;
    padding: 0.6rem 1.2rem;
    border-radius: 0.5rem;
    font-family: 'Outfit';
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.primary-btn:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
}

.btn-full {
    width: 100%;
    margin-top: 1rem;
    padding: 0.8rem;
}

.action-btn,
.secondary-btn {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-main);
    border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
    font-size: 0.9rem;
    -webkit-appearance: none;
    appearance: none;
}

.action-btn:hover,
.upload-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: var(--primary);
}

.btn-remove {
    background: transparent;
    color: var(--danger);
    border: none;
    cursor: pointer;
    font-size: 1.2rem;
    opacity: 0.5;
    transition: opacity 0.2s;
    position: absolute;
    top: 1rem;
    right: 1rem;
}

.btn-remove:hover {
    opacity: 1;
    text-shadow: 0 0 8px rgba(239, 68, 68, 0.5);
}

/* Dashboard 3-Column Layout */
.dashboard-columns {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.5rem;
    align-items: start;
}

@media (max-width: 900px) {
    .dashboard-columns {
        grid-template-columns: 1fr;
    }
}

.col-section {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 1.5rem;
    padding: 1.5rem;
    min-height: 500px;
    display: flex;
    flex-direction: column;
}

.col-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.col-header h2 {
    font-size: 1.2rem;
    font-weight: 600;
}

.col-header .count {
    background: var(--primary);
    color: white;
    padding: 0.2rem 0.6rem;
    border-radius: 1rem;
    font-size: 0.8rem;
    font-weight: 800;
}

.list-container {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* List Item (Horizonal Card) */
.list-item {
    background: var(--card-bg);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 1rem;
    padding: 0.8rem 1rem;
    transition: transform 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
    display: flex;
    align-items: center;
    position: relative;
    gap: 0.8rem;
}

/* Drag & Drop Styles when Edit Mode is active */
body.edit-mode .list-item {
    cursor: grab;
    border: 1px dashed rgba(255, 255, 255, 0.4);
}

body.edit-mode .list-item:active {
    cursor: grabbing;
}

.list-item.dragging {
    opacity: 0.5;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.5);
    border-color: var(--primary);
}

.col-section.drag-over {
    background: rgba(59, 130, 246, 0.1);
    border: 1px dashed var(--primary);
}

.list-item:hover {
    transform: translateX(5px);
    border-color: rgba(255, 255, 255, 0.3);
}

.list-item-info {
    display: flex;
    flex-direction: column;
    flex: 1 1 0%;
    /* Force flex basis to 0 so it honors truncation */
    min-width: 0;
    overflow: hidden;
    /* Ensure it cannot push boundaries */
}

/* Editable Name */
.editable-name {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-main);
    display: inline-block;
    padding: 0.2rem 0.4rem;
    border-radius: 0.3rem;
    border: 1px solid transparent;
    transition: all 0.2s;
    outline: none;
    cursor: text;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-left: -0.4rem;
    /* offset padding */
}

.editable-name:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.2);
}

.editable-name:focus {
    background: rgba(0, 0, 0, 0.5);
    border-color: var(--primary);
    white-space: normal;
}

.list-item .ip {
    font-size: 0.85rem;
    color: var(--text-dim);
    margin-top: 0.2rem;
}

.link-ip {
    text-decoration: none;
    transition: color 0.2s ease, text-shadow 0.2s ease;
    display: inline-block;
    max-width: max-content;
}

.link-ip:hover {
    color: var(--primary);
    text-shadow: 0 0 8px rgba(59, 130, 246, 0.4);
}

.signal-display {
    display: flex;
    align-items: baseline;
    gap: 0.2rem;
    min-width: 80px;
    justify-content: flex-end;
}

.signal-display .value {
    font-size: 2rem;
    font-weight: 800;
    letter-spacing: -1px;
    line-height: 1;
    background: linear-gradient(135deg, #fff 0%, #cbd5e1 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    transition: all 0.5s ease;
}

.signal-display .unit {
    font-size: 0.8rem;
    color: var(--text-dim);
    font-weight: 400;
}

.list-item-actions {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    padding-left: 0.8rem;
    border-left: 1px solid rgba(255, 255, 255, 0.1);
}

.status-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
}

.status-dot.online {
    background-color: var(--success);
    box-shadow: 0 0 8px var(--success);
}

.status-dot.offline {
    background-color: var(--danger);
    box-shadow: 0 0 8px var(--danger);
}

.status-dot.error {
    background-color: var(--warning);
    box-shadow: 0 0 8px var(--warning);
}

.btn-remove-list {
    background: transparent;
    color: var(--text-dim);
    border: none;
    cursor: pointer;
    font-size: 1.1rem;
    transition: all 0.2s;
    padding: 0.4rem;
    border-radius: 0.3rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-remove-list:hover {
    color: var(--danger);
    background: rgba(239, 68, 68, 0.1);
    transform: scale(1.1);
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(5px);
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
    z-index: 100;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    background: #1e293b;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 1rem;
    width: 90%;
    max-width: 500px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    transform: translateY(20px);
    transition: transform 0.3s;
}

.modal-overlay.active .modal-content {
    transform: translateY(0);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.modal-header h2 {
    font-size: 1.2rem;
}

.close-btn {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 1.5rem;
    cursor: pointer;
    transition: color 0.2s;
}

.close-btn:hover {
    color: white;
}

.modal-body {
    padding: 1.5rem;
}

.modal-body h3 {
    font-size: 1rem;
    margin-bottom: 1rem;
    color: var(--text-dim);
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.form-grid input,
.custom-select {
    width: 100%;
    padding: 0.8rem;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 0.5rem;
    color: white;
    font-family: 'Outfit';
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

.custom-select {
    background-image: url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%2394a3b8%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.5-12.8z%22%2F%3E%3C%2Fsvg%3E");
    background-repeat: no-repeat, repeat;
    background-position: right .7em top 50%, 0 0;
    background-size: .65em auto, 100%;
}

.custom-select option {
    background-color: var(--bg-dark);
}

.form-grid input:focus,
.custom-select:focus {
    outline: none;
    border-color: var(--primary);
}

.import-export-section {
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.action-buttons {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.upload-btn {
    display: inline-block;
    cursor: pointer;
}

/* --- Login Screen --- */
#login-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-color);
    background-image: radial-gradient(circle at top right, rgba(59, 130, 246, 0.15) 0%, transparent 40%),
        radial-gradient(circle at bottom left, rgba(59, 130, 246, 0.1) 0%, transparent 40%);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

#login-overlay.active {
    display: flex;
}

.login-card {
    background: var(--card-bg);
    backdrop-filter: blur(30px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 1.5rem;
    padding: 3rem 2.5rem;
    width: 90%;
    max-width: 400px;
    text-align: center;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    animation: scaleIn 0.4s ease-out;
}

@keyframes scaleIn {
    from {
        transform: scale(0.9);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

.login-card .logo {
    margin-bottom: 0.5rem;
    justify-content: center;
}

.login-card .logo h1 {
    font-size: 2.2rem;
}

.login-subtitle {
    color: var(--text-dim);
    margin-bottom: 2rem;
    font-size: 0.95rem;
}

#login-form {
    display: flex;
    flex-direction: column;
    gap: 1.2rem;
}

.input-group input {
    width: 100%;
    padding: 1rem;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 0.5rem;
    color: white;
    font-family: 'Outfit';
    font-size: 1rem;
    transition: border-color 0.3s ease;
}

.input-group input:focus {
    outline: none;
    border-color: var(--primary);
}

.w-full {
    width: 100%;
    margin-top: 1rem;
}

.login-error {
    color: var(--danger);
    font-size: 0.9rem;
    min-height: 1.2rem;
    margin-top: 0.5rem;
}

/* --- Responsive Media Queries --- */
@media (max-width: 900px) {
    .dashboard-columns {
        grid-template-columns: 1fr;
        gap: 2rem;
    }
}

@media (max-width: 768px) {
    .container {
        padding-bottom: 1.5rem;
    }

    .header-container {
        padding-top: 1.5rem;
    }

    .global-logout {
        top: 1.5rem;
    }

    header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
        padding-right: 0;
        /* Remove right buffer on mobile, actions stack below X */
    }

    .header-actions {
        width: 100%;
        flex-direction: column;
        gap: 0.5rem;
        display: flex;
    }

    .primary-btn,
    .secondary-btn {
        width: 100%;
        text-align: center;
        justify-content: center;
        padding: 0.8rem;
        font-size: 0.95rem;
    }

    .list-item {
        padding: 0.6rem;
        gap: 0.4rem;
    }

    .btn-remove-list {
        padding: 0.2rem;
        font-size: 1rem;
    }
}