/* CrumbForest v0.1 - Styles */

/* Print / PDF Styles */
@media print {
    body {
        background: white;
        color: black;
    }

    .no-print,
    .app-header,
    .tab-nav,
    .action-buttons,
    #scanner-tab,
    #stats-tab,
    #history-tab,
    #toast-container,
    #chat-widget {
        display: none !important;
    }

    #inventory-tab {
        display: block !important;
    }

    .inventory-list {
        font-size: 12pt;
    }

    .inventory-item {
        border-bottom: 1px solid #ddd;
        page-break-inside: avoid;
    }

    .item-actions {
        display: none;
    }

    h2,
    h3 {
        color: black;
    }
}

/* Original CSS */
:root {
    --primary: #16a085;
    --secondary: #3498db;
    --danger: #e74c3c;
    --success: #27ae60;
    --dark: #1a1a2e;
    --dark-light: #16213e;
    --text: #ecf0f1;
    --text-muted: #95a5a6;
    --border: #34495e;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: var(--dark);
    color: var(--text);
    line-height: 1.6;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

/* Screens */
.screen {
    display: none;
    min-height: 100vh;
}

.screen.active {
    display: block;
}

/* Login Screen */
#login-screen {
    display: flex;
    align-items: center;
    justify-content: center;
}

.logo {
    text-align: center;
    margin-bottom: 40px;
}

.logo h1 {
    font-size: 3em;
    margin-bottom: 10px;
}

.subtitle {
    color: var(--text-muted);
    font-size: 0.9em;
}

/* Cards */
.card {
    background: var(--dark-light);
    border-radius: 12px;
    padding: 30px;
    border: 1px solid var(--border);
    max-width: 400px;
    margin: 0 auto;
}

/* Forms */
/* Forms */
.form-group {
    margin-bottom: 20px;
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.full-width {
    grid-column: 1 / -1;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    color: var(--text-muted);
    font-size: 0.9em;
    font-weight: 500;
}

.form-control {
    width: 100%;
    padding: 12px;
    background: var(--dark);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 1em;
    transition: border-color 0.3s ease;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(22, 160, 133, 0.2);
}

textarea.form-control {
    resize: vertical;
    min-height: 80px;
}

.action-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    margin-top: 30px;
}

#new-scan-btn {
    grid-column: 1 / -1;
}

input[type="text"],
input[type="password"],
input[type="number"],
select {
    width: 100%;
    padding: 12px;
    background: var(--dark);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 1em;
}

/* Buttons */
.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 6px;
    font-size: 1em;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 500;
}

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

.btn-primary:hover {
    background: #138f75;
}

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

.btn-secondary:hover {
    background: #2980b9;
}

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

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

.btn-small {
    padding: 8px 16px;
    font-size: 0.9em;
}

.btn-large {
    width: 100%;
    padding: 16px;
    font-size: 1.1em;
    margin-bottom: 15px;
}

/* Header */
.app-header {
    background: var(--dark-light);
    border-bottom: 1px solid var(--border);
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.app-header h1 {
    font-size: 1.5em;
}

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

/* Navigation Tabs */
.tab-nav {
    background: var(--dark-light);
    border-bottom: 1px solid var(--border);
    display: flex;
    padding: 0 20px;
}

.tab-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    padding: 15px 20px;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.3s ease;
}

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

.tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

/* Tab Content */
.tab-content {
    display: none;
    padding: 20px 0;
}

.tab-content.active {
    display: block;
}

/* Scanner */
.scanner-controls {
    margin: 30px 0;
}

.scanner-view {
    background: var(--dark-light);
    border-radius: 12px;
    padding: 20px;
    margin: 20px 0;
}

.scanner-wrapper {
    position: relative;
    width: 100%;
    max-width: 640px;
    margin: 0 auto 20px;
    background: black;
    border-radius: 8px;
    overflow: hidden;
}

#scanner-container {
    width: 100%;
}

#scanner-container video {
    width: 100%;
    display: block;
}

#scanner-container canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    /* Align with video if possible, though video might be object-fit: contain */
}

/* Scanner Overlay */
.scanner-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    /* Darken outer area using a massive border hack or box-shadow */
    /* Simple approach: 4 divs or a clip-path. Let's use box-shadow inset hack for simplicity */
    box-shadow: inset 0 0 0 1000px rgba(0, 0, 0, 0.5);
    /* Wait, box-shadow inset covers everything. We need a "hole". */
    /* Better: Border method */
    pointer-events: none;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
}

.scanner-box {
    width: 80%;
    height: 40%;
    position: relative;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.5);
    border: 2px solid rgba(255, 255, 255, 0.5);
    border-radius: 4px;
}

.scanner-laser {
    position: absolute;
    top: 50%;
    left: 0;
    width: 100%;
    height: 2px;
    background: red;
    box-shadow: 0 0 4px red;
    animation: scan-laser 2s infinite linear;
}

@keyframes scan-laser {
    0% {
        transform: translateY(-20px);
        opacity: 0.5;
    }

    50% {
        opacity: 1;
    }

    100% {
        transform: translateY(20px);
        opacity: 0.5;
    }
}

/* Scan Result */
#scan-result {
    margin: 30px 0;
}

#scan-result h3 {
    margin-bottom: 20px;
    color: var(--success);
}

#scan-result-content {
    background: var(--dark);
    padding: 20px;
    border-radius: 8px;
    margin-bottom: 20px;
}

.scan-info-row {
    display: flex;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
}

.scan-info-row:last-child {
    border-bottom: none;
}

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

.scan-info-value {
    font-weight: 500;
}

/* History List */
.history-list {
    display: grid;
    gap: 15px;
}

.history-item {
    background: var(--dark-light);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 20px;
    transition: transform 0.2s ease;
}

.history-item:hover {
    transform: translateY(-2px);
    border-color: var(--primary);
}

.history-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 10px;
}

.history-serial {
    font-size: 1.2em;
    font-weight: 500;
}

.history-date {
    color: var(--text-muted);
    font-size: 0.9em;
}

.history-details {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 10px;
    margin-top: 10px;
}

.history-detail {
    font-size: 0.9em;
}

.history-detail-label {
    color: var(--text-muted);
    display: block;
}

.status-badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 0.85em;
    font-weight: 500;
}

.status-synced {
    background: var(--success);
    color: white;
}

.status-pending {
    background: var(--secondary);
    color: white;
}

/* Stats */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-top: 30px;
}

.stat-card {
    background: var(--dark-light);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 30px;
    text-align: center;
}

.stat-value {
    font-size: 3em;
    font-weight: bold;
    color: var(--primary);
    margin-bottom: 10px;
}

.stat-label {
    color: var(--text-muted);
    font-size: 0.9em;
}

/* Toast Notifications */
#toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
}

.toast {
    background: var(--dark-light);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 15px 20px;
    margin-bottom: 10px;
    min-width: 300px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        transform: translateX(400px);
        opacity: 0;
    }

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.toast-success {
    border-left: 4px solid var(--success);
}

.toast-error {
    border-left: 4px solid var(--danger);
}

.toast-info {
    border-left: 4px solid var(--secondary);
}

/* Error Messages */
.error-message {
    color: var(--danger);
    margin-top: 15px;
    display: none;
}

.error-message.show {
    display: block;
}

/* Loading */
.loading {
    text-align: center;
    padding: 40px;
    color: var(--text-muted);
}

/* Responsive */
@media (max-width: 768px) {
    .container {
        padding: 15px;
    }

    /* Mobile Header Fix */
    .app-header {
        flex-direction: row;
        /* Force row */
        justify-content: space-between;
        align-items: center;
        padding: 10px 15px;
    }

    .app-header h1 {
        font-size: 1.2em;
        margin: 0;
    }

    .header-right {
        display: flex;
        gap: 10px;
    }

    .tab-nav {
        padding: 0 10px;
    }

    .tab-btn {
        padding: 12px 10px;
        font-size: 0.9em;
    }

    .stats-grid {
        grid-template-columns: 1fr 1fr;
    }

    .history-details {
        grid-template-columns: 1fr;
    }

    .form-grid {
        grid-template-columns: 1fr;
    }
}

/* Chat Widget */
#chat-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

#chat-toggle-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    border: none;
    font-size: 24px;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    transition: transform 0.2s;
}

#chat-toggle-btn:hover {
    transform: scale(1.1);
}

#chat-window {
    width: 350px;
    height: 450px;
    background: var(--dark-light);
    border: 1px solid var(--border);
    border-radius: 12px;
    margin-bottom: 20px;
    display: none;
    /* Hidden initially */
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 5px 25px rgba(0, 0, 0, 0.5);
}

#chat-window.active {
    display: flex;
}

.chat-header {
    background: var(--primary);
    padding: 15px;
    color: white;
    font-weight: bold;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#close-chat {
    background: none;
    border: none;
    color: white;
    font-size: 20px;
    cursor: pointer;
}

#chat-messages {
    flex: 1;
    padding: 15px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.message {
    max-width: 80%;
    padding: 10px 15px;
    border-radius: 10px;
    font-size: 0.9em;
    line-height: 1.4;
}

.message.bot {
    align-self: flex-start;
    background: #34495e;
    color: var(--text);
    border-bottom-left-radius: 2px;
}

.message.user {
    align-self: flex-end;
    background: var(--secondary);
    color: white;
    border-bottom-right-radius: 2px;
}

.chat-input-area {
    padding: 15px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 10px;
    background: var(--dark);
}

#chat-input {
    flex: 1;
    padding: 10px;
    border-radius: 5px;
    border: 1px solid var(--border);
    background: var(--dark-light);
    color: white;
}

#send-chat {
    background: var(--primary);
    border: none;
    color: white;
    padding: 0 15px;
    border-radius: 5px;
    cursor: pointer;
}

/* --- Inventory Polish --- */
.inventory-list {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

/* Base Item Structure */
.inventory-item {
    border-radius: 8px;
    overflow: hidden;
}

.item-header {
    padding: 12px 15px;
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    background: var(--dark-light);
    border: 1px solid var(--border);
    border-radius: 8px;
    transition: background 0.2s;
}

.item-header:hover {
    background: #2c3e50;
}

/* Toggle Rotation */
.item-toggle {
    display: inline-block;
    width: 20px;
    text-align: center;
    transition: transform 0.2s;
    font-size: 0.8em;
}

.inventory-item.expanded>.item-header .item-toggle {
    transform: rotate(90deg);
}

/* Level 0: Root Nodes (Servers) */
.inventory-level-0 {
    margin-bottom: 25px;
    /* Significant gap between roots */
}

.inventory-level-0>.item-header {
    background: #26384a;
    /* Distinct darker/blueish background */
    border: 1px solid #4b6584;
    padding: 15px 20px;
    /* Larger header */
}

.inventory-level-0>.item-header .item-title {
    font-size: 1.1em;
    font-weight: bold;
    color: var(--secondary);
}

/* Level 1+: Children */
.inventory-level-1,
.inventory-level-2 {
    margin-top: 5px;
    margin-left: 5px;
    /* Slight indent context */
}

.inventory-level-1>.item-header {
    background: transparent;
    border: none;
    border-bottom: 1px solid #34495e;
    border-radius: 0;
    padding: 8px 15px;
}

/* Children Container (Tree Lines) */
.item-children {
    display: none;
    /* Hidden by default? Or user wants to see them? Let's hide by default to be collapsible */
    margin-left: 18px;
    padding-left: 10px;
    border-left: 2px solid #34495e;
    margin-top: 5px;
    margin-bottom: 10px;
}

.inventory-item.expanded>.item-children {
    display: block;
}

/* Actions in Header (Right aligned) */
.item-actions {
    margin-left: auto;
    display: flex;
    gap: 10px;
    align-items: center;
}

.item-qr {
    font-size: 0.8em;
    background: white;
    color: black;
    padding: 2px 5px;
    border-radius: 4px;
}

/* --- Cluster & Rack Polish --- */
.cluster-section,
.rack-section {
    margin-bottom: 20px;
    border-radius: 8px;
    overflow: hidden;
}

/* Cluster Header (Green as requested) */
.cluster-header {
    background: var(--primary);
    /* "Benutztes Grün" */
    color: white;
    padding: 15px 20px;
    font-size: 1.2em;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    border-radius: 8px;
    /* If section closed */
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

.cluster-section.expanded>.cluster-header {
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
}

/* Rack Header */
.rack-header {
    background: #34495e;
    /* Secondary dark */
    color: #ecf0f1;
    padding: 12px 20px;
    font-size: 1.1em;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid #2c3e50;
    margin-top: 5px;
    /* Gap from previous rack/cluster start */
}

.cluster-content,
.rack-content {
    display: none;
    padding: 10px;
}

.cluster-section.expanded>.cluster-content,
.rack-section.expanded>.rack-content {
    display: block;
}

/* 🌲 Network Topology Styles */
.network-tree-container {
    background: #1a1a1a;
    border: 1px solid #333;
    border-radius: 8px;
    overflow: hidden;
}

.network-tree-view {
    min-height: 200px;
    max-height: 70vh;
    overflow-y: auto;
}

.network-tree-ascii {
    font-family: 'Courier New', monospace;
    font-size: 13px;
    line-height: 1.8;
    white-space: pre;
    overflow-x: auto;
    padding: 15px;
    background: #0a0a0a;
    border-radius: 4px;
}

/* Force Mobile View */
.network-tree-ascii.force-mobile {
    font-size: 11px !important;
    line-height: 1.6 !important;
    padding: 10px !important;
}

.network-tree-ascii.force-mobile span:last-child {
    display: none !important;
}

/* Force Desktop View */
.network-tree-ascii.force-desktop {
    font-size: 14px !important;
    line-height: 1.9 !important;
    padding: 20px !important;
}

.network-tree-ascii div {
    transition: background-color 0.2s;
}

.network-tree-ascii div:hover {
    background-color: #1a1a1a;
    border-radius: 3px;
}

.network-tree-ascii a {
    text-decoration: none;
    font-weight: bold;
    transition: opacity 0.2s;
}

.network-tree-ascii a:hover {
    opacity: 0.8;
    text-decoration: underline;
}

/* Mobile Responsive - Network Tab */
@media (max-width: 768px) {
    .network-tree-ascii {
        font-size: 11px;
        line-height: 1.6;
        padding: 10px;
    }

    .network-tree-view {
        max-height: 60vh;
    }

    /* Make datacenter select stack on mobile */
    #network-tab .container>div:first-child {
        flex-direction: column;
        align-items: stretch !important;
    }

    #network-tab .header-actions {
        width: 100%;
        margin-top: 10px;
        display: flex;
        gap: 10px;
    }

    #datacenter-select {
        flex: 1;
        width: 100% !important;
        margin-right: 0 !important;
    }

    /* Smaller stat cards on mobile */
    #network-health-stats .stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 10px;
    }

    .stat-card {
        padding: 10px;
    }

    .stat-value {
        font-size: 1.5em;
    }

    .stat-label {
        font-size: 0.75em;
    }

    /* Hide rack/HE info on very small screens */
    @media (max-width: 480px) {
        .network-tree-ascii span:last-child {
            display: none;
        }
    }
}


/* === 🔌 Cable Management - Custom Wrapper === */

/* Custom wrapper instead of .container - Full width by default */
.cables-wrapper {
    width: 100%;
    padding: 20px;
}

/* Fullscreen Mode */
.cables-wrapper.cables-fullscreen {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100vw;
    height: 100vh;
    margin: 0;
    padding: 20px;
    background: var(--dark);
    z-index: 9998;
    overflow-y: auto;
}

/* Mobile View Toggle - Restore centered container */
.cables-wrapper.cables-force-mobile {
    max-width: 1200px;
    margin: 0 auto;
}

.cables-wrapper.cables-force-mobile #cables-main-grid {
    grid-template-columns: 1fr !important;
}

/* Responsive - Auto switch to mobile on small screens */
@media (max-width: 1024px) {
    .cables-wrapper {
        max-width: 1200px;
        margin: 0 auto;
    }

    .cables-wrapper #cables-main-grid {
        grid-template-columns: 1fr !important;
    }
}

/* Modal Overlay & Styling */
.modal {
    display: none;
    /* Hidden by default */
    position: fixed;
    /* Stay in place */
    z-index: 10000;
    /* Sit on top */
    left: 0;
    top: 0;
    width: 100%;
    /* Full width */
    height: 100%;
    /* Full height */
    overflow: hidden;
    /* Prevent body scroll if needed, inner handles it */
    background-color: rgba(0, 0, 0, 0.7);
    /* Black w/ opacity */
    backdrop-filter: blur(4px);
    justify-content: center;
    align-items: center;
}

/* Flexbox centering context */
.modal[style*="display: block"],
.modal[style*="display: flex"] {
    display: flex !important;
}

.modal-content {
    background-color: var(--bg-card);
    margin: auto;
    padding: 24px;
    border: 1px solid var(--border-color);
    width: 90%;
    max-width: 1400px;
    border-radius: var(--radius-lg);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    position: relative;
    max-height: 90vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    animation: modalSlideIn 0.3s ease-out;
}

/* Close Button */
.close-btn,
.modal-close {
    color: var(--text-muted);
    float: right;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
    position: absolute;
    right: 24px;
    top: 16px;
    z-index: 100;
    line-height: 1;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    /* Button reset */
    background: none;
    border: none;
    padding: 0;
}

.close-btn:hover,
.modal-close:hover {
    color: var(--error);
    background: rgba(239, 68, 68, 0.1);
}

@keyframes modalSlideIn {
    from {
        transform: translateY(20px) scale(0.95);
        opacity: 0;
    }

    to {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
}

/* 🚑 CRITICAL FIX: Override global card limit for cables & modal content */
.cables-wrapper .card,
.modal-content .card {
    max-width: none !important;
    margin: 0 !important;
    box-shadow: none !important;
}

/* 🎮 IPCalc HUD */
.ipcalc-hud {
    background: #0f172a;
    border: 1px solid #1e293b;
    border-radius: var(--radius-md);
    padding: 0;
    overflow: hidden;
    font-family: 'Courier New', Courier, monospace;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.5);
    display: none;
    /* JS toggles this */
}

.hud-header {
    background: #1e293b;
    color: #94a3b8;
    font-size: 0.75rem;
    font-weight: bold;
    letter-spacing: 1px;
    padding: 6px 12px;
    text-transform: uppercase;
    border-bottom: 1px solid #334155;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.hud-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1px;
    background: #334155;
    /* Grid lines color */
}

.hud-item {
    background: #0f172a;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.hud-item.full {
    grid-column: span 3;
}

.hud-label {
    color: #64748b;
    font-size: 0.7rem;
    font-weight: bold;
    text-transform: uppercase;
}

.hud-value {
    color: #38bdf8;
    font-size: 1rem;
    font-weight: bold;
    white-space: nowrap;
}

.hud-value.small {
    font-size: 0.9rem;
    color: #e2e8f0;
}

.hud-value.error {
    color: #ef4444;
}

.hud-value.success {
    color: #22c55e;
}