/* ==========================================================================
   VARIABLES & THEMES
   ========================================================================== */
:root {
    --font-main: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --font-mono: 'Fira Code', monospace, Courier;

    /* Base Palette (Dark Theme Default) */
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --bg-card: #1e293b;
    --border-color: #334155;
    --border-light: #475569;

    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;

    --accent-blue: #38bdf8;
    --accent-blue-hover: #0284c7;
    --accent-green: #4ade80;
    --accent-purple: #c084fc;
    --accent-amber: #fbbf24;
    --accent-red: #f87171;

    /* Bit Colors */
    --bit-net-bg: #1e3a8a;
    --bit-net-text: #93c5fd;
    --bit-sub-bg: #581c87;
    --bit-sub-text: #e9d5ff;
    --bit-host-bg: #064e3b;
    --bit-host-text: #a7f3d0;

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --shadow-card: 0 4px 6px -1px rgba(0, 0, 0, 0.2), 0 2px 4px -2px rgba(0, 0, 0, 0.2);
    --shadow-hover: 0 10px 15px -3px rgba(0, 0, 0, 0.3), 0 4px 6px -4px rgba(0, 0, 0, 0.3);
}

body.light-theme {
    --bg-primary: #f1f5f9;
    --bg-secondary: #ffffff;
    --bg-tertiary: #e2e8f0;
    --bg-card: #ffffff;
    --border-color: #cbd5e1;
    --border-light: #94a3b8;

    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #64748b;

    --accent-blue: #0284c7;
    --accent-blue-hover: #0369a1;
    --accent-green: #16a34a;
    --accent-purple: #9333ea;
    --accent-amber: #d97706;
    --accent-red: #dc2626;

    /* Bit Colors (Light) */
    --bit-net-bg: #dbeafe;
    --bit-net-text: #1e40af;
    --bit-sub-bg: #f3e8ff;
    --bit-sub-text: #6b21a8;
    --bit-host-bg: #dcfce7;
    --bit-host-text: #166534;

    --shadow-card: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
}

/* ==========================================================================
   RESET & GLOBAL STYLES
   ========================================================================== */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-main);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
}

.app-container {
    max-width: 1280px;
    margin: 0 auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

/* Typography Helpers */
.font-mono {
    font-family: var(--font-mono);
}

.text-accent {
    color: var(--accent-blue);
}

code {
    font-family: var(--font-mono);
    background: var(--bg-tertiary);
    padding: 0.15rem 0.4rem;
    border-radius: var(--radius-sm);
    font-size: 0.9em;
}

/* ==========================================================================
   HEADER
   ========================================================================== */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-card);
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.logo-icon {
    background: linear-gradient(135deg, var(--accent-blue), var(--accent-purple));
    color: #ffffff;
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(56, 189, 248, 0.3);
}

.header h1 {
    font-size: 1.35rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.subtitle {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.btn-icon {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    transition: all 0.2s ease;
}

.btn-icon:hover {
    background: var(--border-light);
    transform: translateY(-2px);
}

/* ==========================================================================
   NAVIGATION TABS
   ========================================================================== */
.nav-tabs {
    display: flex;
    gap: 0.5rem;
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 0.5rem;
    overflow-x: auto;
}

.tab-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 0.65rem 1.25rem;
    font-size: 0.95rem;
    font-weight: 500;
    border-radius: var(--radius-md);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.tab-btn:hover {
    color: var(--text-primary);
    background: var(--bg-secondary);
}

.tab-btn.active {
    color: var(--accent-blue);
    background: var(--bg-secondary);
    font-weight: 600;
    box-shadow: inset 0 -2px 0 var(--accent-blue);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    animation: fadeIn 0.25s ease-in-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ==========================================================================
   CARDS & LAYOUTS
   ========================================================================== */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow-card);
}

.grid-2-col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

@media (max-width: 900px) {
    .grid-2-col {
        grid-template-columns: 1fr;
    }
}

.card-title {
    font-size: 1.15rem;
    font-weight: 600;
    margin-bottom: 0.4rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.card-subtitle {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 1.25rem;
}

.card-header-flex {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 0.75rem;
}

/* ==========================================================================
   CLASS PRESETS
   ========================================================================== */
.class-presets-card {
    padding: 1rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.presets-label {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.preset-buttons {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.btn-preset {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 0.45rem 0.85rem;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 0.85rem;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.2s ease;
    font-family: var(--font-mono);
}

.btn-preset:hover {
    border-color: var(--accent-blue);
    transform: translateY(-2px);
    box-shadow: var(--shadow-hover);
}

.badge {
    padding: 0.2rem 0.5rem;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
}

.class-a-badge { background: #0369a1; color: #e0f2fe; }
.class-b-badge { background: #7e22ce; color: #fae8ff; }
.class-c-badge { background: #047857; color: #d1fae5; }
.class-pub-badge { background: #b45309; color: #fef3c7; }

/* ==========================================================================
   FORMS & INPUTS
   ========================================================================== */
.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.4rem;
}

.label-with-value {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.4rem;
}

.highlight-val {
    font-family: var(--font-mono);
    font-weight: 600;
    color: var(--accent-blue);
    font-size: 0.85rem;
}

.input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

input[type="text"],
input[type="number"],
.form-select {
    width: 100%;
    padding: 0.75rem 1rem;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 1rem;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

input[type="text"]:focus,
input[type="number"]:focus,
.form-select:focus {
    outline: none;
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.2);
}

.validation-badge {
    position: absolute;
    right: 10px;
    font-size: 0.75rem;
    padding: 0.2rem 0.5rem;
    border-radius: var(--radius-sm);
    font-weight: 600;
}

.validation-badge.valid {
    background: rgba(74, 222, 128, 0.15);
    color: var(--accent-green);
    border: 1px solid rgba(74, 222, 128, 0.3);
}

.validation-badge.invalid {
    background: rgba(248, 113, 113, 0.15);
    color: var(--accent-red);
    border: 1px solid rgba(248, 113, 113, 0.3);
}

/* Segmented Control */
.segmented-control {
    display: flex;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 0.25rem;
    gap: 0.25rem;
}

.segment-btn {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.segment-btn.active {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-weight: 600;
}

.mode-container {
    display: none;
    margin-top: 1rem;
}

.mode-container.active {
    display: block;
}

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

.input-number-group input {
    flex: 1;
}

.form-hint {
    display: block;
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 0.35rem;
}

/* Slider */
.slider-wrapper {
    margin-top: 0.75rem;
}

input[type="range"] {
    width: 100%;
    accent-color: var(--accent-blue);
    cursor: pointer;
}

.slider-ticks {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
    margin-top: 0.25rem;
}

/* ==========================================================================
   BUTTONS
   ========================================================================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.65rem 1.25rem;
    font-size: 0.9rem;
    font-weight: 600;
    border-radius: var(--radius-md);
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-primary {
    background: var(--accent-blue);
    color: #0f172a;
}

.btn-primary:hover {
    background: var(--accent-blue-hover);
    transform: translateY(-1px);
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--border-light);
}

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

.btn-lg {
    padding: 0.85rem 1.75rem;
    font-size: 1rem;
    width: 100%;
}

.btn-danger-sm {
    background: rgba(248, 113, 113, 0.15);
    color: var(--accent-red);
    border: 1px solid rgba(248, 113, 113, 0.3);
    padding: 0.35rem 0.6rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
}

.btn-danger-sm:hover {
    background: var(--accent-red);
    color: #fff;
}

/* ==========================================================================
   SUMMARY CARD & CLASS BANNER
   ========================================================================== */
.class-banner {
    display: flex;
    align-items: center;
    gap: 1.25rem;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    padding: 1.25rem;
    border-radius: var(--radius-md);
    margin-bottom: 1.25rem;
}

.class-avatar {
    width: 54px;
    height: 54px;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, #059669, #10b981);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
    font-weight: 800;
    font-family: var(--font-mono);
    box-shadow: 0 4px 10px rgba(16, 185, 129, 0.3);
}

.class-avatar.class-a {
    background: linear-gradient(135deg, #0284c7, #38bdf8);
    box-shadow: 0 4px 10px rgba(56, 189, 248, 0.3);
}

.class-avatar.class-b {
    background: linear-gradient(135deg, #7c3aed, #a855f7);
    box-shadow: 0 4px 10px rgba(168, 85, 247, 0.3);
}

.class-avatar.class-c {
    background: linear-gradient(135deg, #059669, #10b981);
    box-shadow: 0 4px 10px rgba(16, 185, 129, 0.3);
}

.class-details h3 {
    font-size: 1.1rem;
    margin-bottom: 0.2rem;
}

.class-details p {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.class-tags {
    display: flex;
    gap: 0.4rem;
    flex-wrap: wrap;
}

.tag {
    font-size: 0.72rem;
    padding: 0.2rem 0.5rem;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-weight: 500;
}

.quick-stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
}

.stat-box {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    padding: 0.85rem;
    border-radius: var(--radius-md);
    display: flex;
    flex-direction: column;
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 500;
    margin-bottom: 0.25rem;
}

.stat-value {
    font-size: 1.25rem;
    font-weight: 700;
}

/* ==========================================================================
   TABLES & DETAILS
   ========================================================================== */
.table-scroll-container {
    overflow-x: auto;
    width: 100%;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table td {
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.9rem;
}

.td-label {
    font-weight: 600;
    color: var(--text-secondary);
    width: 35%;
}

.td-val {
    font-size: 1rem;
    font-weight: 600;
    width: 40%;
}

.td-desc {
    color: var(--text-muted);
    font-size: 0.82rem;
    width: 25%;
}

.highlight-blue { color: var(--accent-blue); }
.highlight-green { color: var(--accent-green); }
.highlight-red { color: var(--accent-red); }

/* Subnets list table */
.subnets-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
    font-family: var(--font-mono);
}

.subnets-table th {
    background: var(--bg-primary);
    color: var(--text-secondary);
    padding: 0.75rem 1rem;
    text-align: left;
    font-weight: 600;
    border-bottom: 2px solid var(--border-color);
    font-family: var(--font-main);
}

.subnets-table td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-color);
}

.subnets-table tr:hover td {
    background: rgba(255, 255, 255, 0.02);
}

.pagination-bar {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 1rem;
}

/* ==========================================================================
   BINARY BREAKDOWN
   ========================================================================== */
.binary-legend {
    display: flex;
    gap: 1rem;
    font-size: 0.8rem;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.dot-net { background: var(--accent-blue); }
.dot-sub { background: var(--accent-purple); }
.dot-host { background: var(--accent-green); }

.binary-display-group {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
    background: var(--bg-primary);
    padding: 1.25rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
}

.binary-row {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.binary-row-label {
    width: 170px;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.binary-bits {
    display: flex;
    gap: 0.5rem;
    font-family: var(--font-mono);
    font-size: 0.9rem;
    letter-spacing: 0.05em;
    flex-wrap: wrap;
}

.octet-group {
    display: flex;
    gap: 2px;
}

.bit-box {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 28px;
    border-radius: 3px;
    font-weight: 600;
    font-size: 0.85rem;
}

.bit-box.net {
    background: var(--bit-net-bg);
    color: var(--bit-net-text);
}

.bit-box.sub {
    background: var(--bit-sub-bg);
    color: var(--bit-sub-text);
}

.bit-box.host {
    background: var(--bit-host-bg);
    color: var(--bit-host-text);
}

/* ==========================================================================
   VLSM STYLES
   ========================================================================== */
.vlsm-top-controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

@media (max-width: 768px) {
    .vlsm-top-controls {
        grid-template-columns: 1fr;
    }
}

.req-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 1rem;
}

.req-table th,
.req-table td {
    padding: 0.65rem 0.75rem;
    border-bottom: 1px solid var(--border-color);
}

.req-table th {
    text-align: left;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.req-table input {
    font-size: 0.9rem;
    padding: 0.45rem 0.75rem;
}

.vlsm-calc-action {
    margin-top: 1rem;
}

.capacity-bar-container {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 1rem;
    margin-bottom: 1.5rem;
}

.capacity-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
    margin-bottom: 0.5rem;
}

.capacity-bar {
    height: 18px;
    background: var(--bg-tertiary);
    border-radius: 9px;
    overflow: hidden;
    display: flex;
}

.capacity-segment {
    height: 100%;
    transition: width 0.3s ease;
}

/* ==========================================================================
   REFERENCE / CHEAT SHEET
   ========================================================================== */
.styled-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
    font-size: 0.9rem;
}

.styled-list li {
    padding-left: 1.25rem;
    position: relative;
}

.styled-list li::before {
    content: "•";
    color: var(--accent-blue);
    font-size: 1.4rem;
    position: absolute;
    left: 0;
    top: -4px;
}

.formula-box {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.formula-item {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    padding: 1rem;
    border-radius: var(--radius-md);
}

.formula-name {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.35rem;
}

.formula-code {
    font-family: var(--font-mono);
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--accent-amber);
    margin-bottom: 0.35rem;
}

.formula-desc {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.cheat-table th, .cheat-table td {
    padding: 0.6rem 0.8rem;
}

/* ==========================================================================
   FOOTER
   ========================================================================== */
.footer {
    text-align: center;
    font-size: 0.8rem;
    color: var(--text-muted);
    padding: 1rem;
    border-top: 1px solid var(--border-color);
}
