:root {
    --primary: #14B8A6;
    /* Teal */
    --primary-hover: #0D9488;
    --accent: #F43F5E;
    /* Rose */
    --accent-hover: #E11D48;

    --bg-main: #0A0E14;
    /* Deep tech dark */
    --bg-panel: rgba(15, 23, 42, 0.7);
    /* Slate transparent */
    --bg-panel-hover: rgba(30, 41, 59, 0.9);

    --text-main: #F8FAFC;
    --text-dim: #94A3B8;

    --border: rgba(255, 255, 255, 0.1);
    --border-highlight: rgba(20, 184, 166, 0.4);

    --radius: 12px;

    /* Treemap Colors - Array of distinct tech colors */
    --tm-1: rgba(20, 184, 166, 0.2);
    --tm-1-border: #14B8A6;

    --tm-2: rgba(56, 189, 248, 0.2);
    --tm-2-border: #38BDF8;

    --tm-3: rgba(167, 139, 250, 0.2);
    --tm-3-border: #A78BFA;

    --tm-4: rgba(251, 146, 60, 0.2);
    --tm-4-border: #FB923C;

    --tm-5: rgba(244, 63, 94, 0.2);
    --tm-5-border: #F43F5E;
}

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

body {
    font-family: 'Inter', system-ui, sans-serif;
    background-color: var(--bg-main);
    color: var(--text-main);
    line-height: 1.5;
    height: 100vh;
    overflow: hidden;

    /* Subtle grid background */
    background-image:
        linear-gradient(var(--border) 1px, transparent 1px),
        linear-gradient(90deg, var(--border) 1px, transparent 1px);
    background-size: 40px 40px;
    background-position: center;
}

.app-container {
    height: 100%;
    display: flex;
    flex-direction: column;
}

/* Glass Panels */
.glass-panel {
    background: var(--bg-panel);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

/* Header */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    background: rgba(10, 14, 20, 0.8);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--border);
    z-index: 10;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--primary);
}

.brand h1 {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--text-main);
}

.header-actions {
    display: flex;
    gap: 0.5rem;
}

/* Typography & Layout */
.text-sm {
    font-size: 0.85rem;
}

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

.hidden {
    display: none !important;
}

/* Main Layout */
.main-content {
    flex: 1;
    display: flex;
    gap: 1.5rem;
    padding: 1.5rem;
    min-height: 0;
}

.sidebar {
    width: 320px;
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
    gap: 2rem;
    overflow-y: auto;
}

.workspace {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
    min-width: 0;
}

/* Forms & Inputs */
.input-section h2 {
    font-size: 1rem;
    margin-bottom: 1rem;
    color: var(--primary);
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.5rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

label {
    font-size: 0.85rem;
    color: var(--text-dim);
    font-weight: 500;
}

input[type="text"] {
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.6rem 0.8rem;
    color: var(--text-main);
    font-family: 'Fira Code', monospace;
    font-size: 0.9rem;
    outline: none;
    transition: all 0.2s;
    width: 100%;
}

input[type="text"]:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(20, 184, 166, 0.2);
}

.input-wrapper {
    display: flex;
    gap: 0.5rem;
}

.input-wrapper input {
    flex: 1;
}

.error-text {
    color: var(--accent);
    font-size: 0.8rem;
    margin-top: 0.2rem;
}

/* Buttons */
.btn {
    border: none;
    background: transparent;
    color: var(--text-main);
    padding: 0.6rem 1rem;
    border-radius: 6px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
    font-size: 0.9rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

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

.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
}

.btn-outline {
    border: 1px solid var(--border);
}

.btn-outline:hover:not(:disabled) {
    border-color: var(--primary);
    color: var(--primary);
}

.btn-sm {
    padding: 0.4rem 0.8rem;
    font-size: 0.8rem;
}

.btn-ghost {
    background: transparent;
}

.btn-ghost:hover {
    background: rgba(255, 255, 255, 0.05);
}

/* Stats Grid */
.network-stats h3 {
    font-size: 1rem;
    color: var(--primary);
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.5rem;
}

.stat-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.75rem;
}

.stat-item {
    display: flex;
    flex-direction: column;
    background: rgba(0, 0, 0, 0.2);
    padding: 0.75rem;
    border-radius: 6px;
    border: 1px solid var(--border);
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-dim);
    margin-bottom: 0.2rem;
}

.stat-value {
    font-family: 'Fira Code', monospace;
    font-size: 0.9rem;
}

.text-small {
    font-size: 0.8rem;
}

/* Workspace Top */
.workspace-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

/* Visualization Treemap */
.visualization-container {
    flex: 1;
    position: relative;
    background: rgba(0, 0, 0, 0.4);
    border-radius: 8px;
    border: 1px solid var(--border);
    overflow: hidden;
    display: flex;
}

.empty-state {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-dim);
    font-style: italic;
    z-index: 1;
}

/* Flexbox based recursive treemap approach */
.treemap-root {
    flex: 1;
    display: flex;
    flex-direction: column;
    z-index: 2;
    padding: 4px;
    gap: 4px;
    overflow: auto;
}

.subnet-block {
    flex: 1;
    display: flex;
    border: 1px solid var(--border-highlight);
    border-radius: 4px;
    position: relative;
    cursor: pointer;
    transition: all 0.2s;
    overflow: hidden;
    min-height: 40px;
    min-width: 40px;
    background-color: var(--tm-1);
    border-color: var(--tm-1-border);
}

.subnet-block:hover {
    box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.3);
    z-index: 10;
}

.subnet-block.split-horz {
    flex-direction: row;
}

.subnet-block.split-vert {
    flex-direction: column;
}

.subnet-block.has-children {
    cursor: default;
    background-color: transparent !important;
    border-color: rgba(255, 255, 255, 0.05) !important;
    gap: 4px;
    padding: 0;
}

.subnet-info {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    pointer-events: none;
    width: 100%;
    padding: 0 4px;
}

.subnet-cidr {
    font-family: 'Fira Code', monospace;
    font-size: clamp(0.7rem, 1.5vw, 1.2rem);
    font-weight: 600;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
    display: block;
}

.subnet-size {
    font-size: clamp(0.5rem, 1vw, 0.8rem);
    color: rgba(255, 255, 255, 0.7);
    display: block;
}

.subnet-block.highlight {
    animation: pulse 1s infinite alternate;
}

@keyframes pulse {
    from {
        box-shadow: inset 0 0 10px 2px var(--accent);
        border-color: var(--accent);
    }

    to {
        box-shadow: inset 0 0 20px 5px var(--accent);
        border-color: var(--accent);
        background-color: rgba(244, 63, 94, 0.4);
    }
}

/* IP Lookup Result */
.lookup-result {
    margin-top: 0.5rem;
    padding: 0.75rem;
    background: rgba(20, 184, 166, 0.1);
    border-left: 3px solid var(--primary);
    border-radius: 4px;
    font-size: 0.85rem;
    font-family: 'Fira Code', monospace;
}

/* Modals */
.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
}

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

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.modal-content {
    width: 90%;
    max-width: 450px;
    padding: 1.5rem;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    color: var(--primary);
}

.modal-stat-grid {
    display: grid;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
}

.modal-stat-row {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border);
    border-radius: 4px;
}

.modal-stat-row span:last-child {
    font-family: 'Fira Code', monospace;
    font-weight: 500;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
}