/* ============================================
   SubNet Calculator — Professional Stylesheet
   Compact layout optimized for mobile
   ============================================ */

@import url('/assets/fonts/inter.css');
@import url('/assets/fonts/jetbrains-mono.css');

/* --- CSS Custom Properties (Dark Theme — default) --- */
:root {
    --bg-primary: #0b1120;
    --bg-secondary: #111827;
    --bg-card: #1a2332;
    --bg-card-hover: #1f2b3e;
    --bg-input: #0f1923;
    --bg-input-focus: #131f2e;
    --border-subtle: rgba(99, 179, 237, 0.08);
    --border-default: rgba(99, 179, 237, 0.15);
    --border-focus: rgba(56, 189, 248, 0.5);
    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --text-accent: #38bdf8;
    --text-heading: #f1f5f9;
    --accent-primary: #0ea5e9;
    --accent-primary-hover: #38bdf8;
    --accent-gradient: linear-gradient(135deg, #0ea5e9, #6366f1);
    --accent-glow: rgba(14, 165, 233, 0.25);
    --accent-soft: rgba(14, 165, 233, 0.08);
    --success: #10b981;
    --warning: #f59e0b;
    --error: #ef4444;
    --info: #6366f1;
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.3);
    --shadow-glow: 0 0 20px var(--accent-glow);
    --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-default: 250ms cubic-bezier(0.4, 0, 0.2, 1);

    /* Visual map colors */
    --map-network: #0ea5e9;
    --map-host: #6366f1;
    --map-bg: rgba(255,255,255,0.05);

    /* Toast */
    --toast-bg: #1e293b;
    --toast-text: #e2e8f0;
}

/* --- Light Theme --- */
[data-theme="light"] {
    --bg-primary: #f1f5f9;
    --bg-secondary: #e2e8f0;
    --bg-card: #ffffff;
    --bg-card-hover: #f8fafc;
    --bg-input: #f8fafc;
    --bg-input-focus: #ffffff;
    --border-subtle: rgba(15, 23, 42, 0.08);
    --border-default: rgba(15, 23, 42, 0.15);
    --border-focus: rgba(14, 165, 233, 0.5);
    --text-primary: #1e293b;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --text-accent: #0284c7;
    --text-heading: #0f172a;
    --accent-primary: #0284c7;
    --accent-primary-hover: #0ea5e9;
    --accent-gradient: linear-gradient(135deg, #0284c7, #4f46e5);
    --accent-glow: rgba(14, 165, 233, 0.15);
    --accent-soft: rgba(14, 165, 233, 0.06);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.08);
    --shadow-glow: 0 0 20px rgba(14, 165, 233, 0.1);
    --map-bg: rgba(0,0,0,0.04);
    --toast-bg: #1e293b;
    --toast-text: #f1f5f9;
}

/* --- Reset --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }

body {
    font-family: var(--font-sans);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
    overflow-x: hidden;
    transition: background var(--transition-default), color var(--transition-default);
}

body::before {
    content: '';
    position: fixed;
    inset: 0;
    background-image:
        radial-gradient(circle at 25% 25%, rgba(14, 165, 233, 0.03) 0%, transparent 50%),
        radial-gradient(circle at 75% 75%, rgba(99, 102, 241, 0.03) 0%, transparent 50%);
    pointer-events: none;
    z-index: 0;
}

[data-theme="light"] body::before { opacity: 0.5; }

/* --- Layout --- */
.app-container {
    position: relative;
    z-index: 1;
    max-width: 960px;
    margin: 0 auto;
    padding: 16px 16px 48px;
}

/* --- Header --- */
.app-header {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-bottom: 12px;
    padding: 12px 0 0;
}

.app-header h1 {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--text-heading);
    letter-spacing: -0.03em;
}

.app-header h1 span {
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.header-actions {
    display: flex;
    gap: 6px;
    margin-left: auto;
}

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: var(--bg-card);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 16px;
    cursor: pointer;
    transition: all var(--transition-fast);
    padding: 0;
    line-height: 1;
}

.icon-btn:hover { background: var(--bg-card-hover); color: var(--text-accent); border-color: var(--border-focus); }
.icon-btn.active { background: var(--accent-soft); color: var(--text-accent); border-color: var(--border-focus); }

/* --- Tool Tabs (top-level navigation) --- */
.tool-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 12px;
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    padding: 3px;
    border: 1px solid var(--border-subtle);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.tool-tabs::-webkit-scrollbar { display: none; }

.tool-tab {
    font-family: var(--font-sans);
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-muted);
    background: transparent;
    border: none;
    border-radius: 6px;
    padding: 8px 14px;
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
    flex-shrink: 0;
}

.tool-tab:hover { color: var(--text-secondary); background: rgba(255, 255, 255, 0.03); }

.tool-tab.active {
    color: var(--text-heading);
    background: var(--accent-soft);
    box-shadow: var(--shadow-sm);
}

[data-theme="light"] .tool-tab.active {
    background: var(--bg-primary);
}

.tool-panel { display: none; }
.tool-panel.active { display: block; animation: slideUp 0.3s ease-out; }

/* --- Card --- */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 20px;
    margin-bottom: 12px;
    box-shadow: var(--shadow-sm);
    transition: border-color var(--transition-default), background var(--transition-default);
}

.card:hover { border-color: var(--border-default); }

.card-title {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-heading);
    margin-bottom: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.card-title .icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    background: var(--accent-soft);
    border-radius: 6px;
    font-size: 14px;
}

/* --- Form --- */
.input-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 12px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

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

.form-label {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.form-input, .form-select {
    font-family: var(--font-mono);
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-primary);
    background: var(--bg-input);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    outline: none;
    transition: all var(--transition-fast);
    width: 100%;
}

.form-input::placeholder { color: var(--text-muted); font-weight: 400; }
.form-input:focus, .form-select:focus { background: var(--bg-input-focus); border-color: var(--border-focus); box-shadow: 0 0 0 3px var(--accent-glow); }

.form-select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%2394a3b8' viewBox='0 0 16 16'%3E%3Cpath d='M4.646 5.646a.5.5 0 0 1 .708 0L8 8.293l2.646-2.647a.5.5 0 0 1 .708.708l-3 3a.5.5 0 0 1-.708 0l-3-3a.5.5 0 0 1 0-.708z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 32px;
}

.form-select option { background: var(--bg-secondary); color: var(--text-primary); }

/* --- Buttons --- */
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

.btn {
    font-family: var(--font-sans);
    font-size: 0.82rem;
    font-weight: 600;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all var(--transition-fast);
}

.btn-primary {
    background: var(--accent-gradient);
    color: #fff;
    box-shadow: var(--shadow-sm);
}

.btn-primary:hover { box-shadow: var(--shadow-md), var(--shadow-glow); transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0); }

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

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

.btn-sm { padding: 6px 12px; font-size: 0.75rem; }

/* --- Quick Masks --- */
.quick-masks {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border-subtle);
}

.quick-masks-label {
    font-size: 0.68rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    width: 100%;
    margin-bottom: 2px;
}

.quick-mask-btn {
    font-family: var(--font-mono);
    font-size: 0.72rem;
    font-weight: 500;
    padding: 4px 10px;
    background: var(--accent-soft);
    color: var(--text-accent);
    border: 1px solid transparent;
    border-radius: 16px;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.quick-mask-btn:hover { background: rgba(14, 165, 233, 0.15); border-color: var(--border-focus); }

/* --- Results --- */
.results-container { display: none; animation: slideUp 0.35s ease-out; }
.results-container.visible { display: block; }

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

/* --- Result Sub-Tabs --- */
.sub-tabs {
    display: flex;
    gap: 3px;
    margin-bottom: 12px;
    background: var(--bg-input);
    border-radius: 6px;
    padding: 3px;
    border: 1px solid var(--border-subtle);
}

.sub-tab {
    flex: 1;
    font-family: var(--font-sans);
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-muted);
    background: transparent;
    border: none;
    border-radius: 4px;
    padding: 7px 8px;
    cursor: pointer;
    transition: all var(--transition-fast);
    text-align: center;
}

.sub-tab:hover { color: var(--text-secondary); }
.sub-tab.active { color: var(--text-heading); background: var(--bg-card); box-shadow: var(--shadow-sm); }

.sub-panel { display: none; }
.sub-panel.active { display: block; animation: slideUp 0.25s ease-out; }

/* --- Result Grid --- */
.result-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 8px;
}

.result-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 10px 12px;
    background: var(--bg-input);
    border-radius: 6px;
    border: 1px solid var(--border-subtle);
    transition: all var(--transition-fast);
    position: relative;
    cursor: pointer;
}

.result-item:hover { border-color: var(--border-default); background: var(--bg-input-focus); }

.result-item::after {
    content: '📋';
    position: absolute;
    top: 6px;
    right: 8px;
    font-size: 11px;
    opacity: 0;
    transition: opacity var(--transition-fast);
}

.result-item:hover::after { opacity: 0.6; }

.result-item.copied::after { content: '✓'; opacity: 1; color: var(--success); font-size: 13px; font-weight: 700; }

.result-label {
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.result-value {
    font-family: var(--font-mono);
    font-size: 0.92rem;
    font-weight: 600;
    color: var(--text-heading);
    word-break: break-all;
}

.result-value.highlight { color: var(--text-accent); }
.result-value.success { color: var(--success); }

.result-sub {
    font-family: var(--font-mono);
    font-size: 0.65rem;
    color: var(--text-muted);
    word-break: break-all;
}

/* --- Badge --- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.68rem;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 16px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.badge-private { background: rgba(16, 185, 129, 0.12); color: var(--success); border: 1px solid rgba(16, 185, 129, 0.2); }
.badge-public { background: rgba(245, 158, 11, 0.12); color: var(--warning); border: 1px solid rgba(245, 158, 11, 0.2); }

/* --- Visual Subnet Map --- */
.subnet-map {
    margin: 12px 0;
    padding: 12px;
    background: var(--bg-input);
    border-radius: 6px;
    border: 1px solid var(--border-subtle);
}

.subnet-map-label {
    font-size: 0.68rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 8px;
}

.subnet-map-bar {
    height: 28px;
    border-radius: 6px;
    overflow: hidden;
    display: flex;
    position: relative;
    background: var(--map-bg);
}

.subnet-map-network {
    background: var(--map-network);
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.65rem;
    font-weight: 700;
    color: #fff;
    transition: width var(--transition-default);
    min-width: 24px;
}

.subnet-map-host {
    background: var(--map-host);
    height: 100%;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.65rem;
    font-weight: 700;
    color: #fff;
    min-width: 24px;
}

.subnet-map-legend {
    display: flex;
    gap: 16px;
    margin-top: 6px;
    font-size: 0.65rem;
    color: var(--text-secondary);
}

.legend-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 4px;
    vertical-align: middle;
}

/* --- Binary Display --- */
.binary-display {
    background: var(--bg-input);
    border: 1px solid var(--border-subtle);
    border-radius: 6px;
    padding: 12px;
    overflow-x: auto;
}

.binary-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 0;
    font-family: var(--font-mono);
    font-size: 0.75rem;
    white-space: nowrap;
}

.binary-label {
    color: var(--text-secondary);
    font-weight: 600;
    min-width: 80px;
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.binary-value { color: var(--text-accent); letter-spacing: 0.04em; }

/* --- Tables --- */
.table-container {
    overflow-x: auto;
    border: 1px solid var(--border-subtle);
    border-radius: 6px;
    max-height: 350px;
    overflow-y: auto;
}

.data-table { width: 100%; border-collapse: collapse; font-size: 0.78rem; }

.data-table thead { position: sticky; top: 0; z-index: 2; }

.data-table th {
    background: var(--bg-secondary);
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 8px 10px;
    text-align: left;
    border-bottom: 1px solid var(--border-default);
}

.data-table td {
    padding: 7px 10px;
    border-bottom: 1px solid var(--border-subtle);
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--text-primary);
}

.data-table tbody tr { transition: background var(--transition-fast); }
.data-table tbody tr:hover { background: var(--accent-soft); }

.table-info {
    text-align: center;
    padding: 8px;
    font-size: 0.72rem;
    color: var(--text-muted);
    background: var(--bg-input);
    border-top: 1px solid var(--border-subtle);
}

/* --- Subdivision --- */
.subdivision-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.subdivision-controls label {
    font-size: 0.78rem;
    font-weight: 500;
    color: var(--text-secondary);
}

/* --- Tools shared layout --- */
.tool-form {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 12px;
}

/* --- Tool Result Card --- */
.tool-result {
    padding: 14px;
    background: var(--bg-input);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    margin-top: 12px;
    animation: slideUp 0.3s ease-out;
}

.tool-result-title {
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--text-heading);
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.tool-result p {
    font-size: 0.82rem;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.tool-result .mono {
    font-family: var(--font-mono);
    color: var(--text-accent);
    font-weight: 500;
}

.result-yes { color: var(--success) !important; font-weight: 700; }
.result-no { color: var(--error) !important; font-weight: 700; }

/* --- History Panel --- */
.history-panel {
    display: none;
    animation: slideUp 0.3s ease-out;
}

.history-panel.visible { display: block; }

.history-list {
    list-style: none;
    max-height: 300px;
    overflow-y: auto;
}

.history-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border-subtle);
    cursor: pointer;
    transition: background var(--transition-fast);
    gap: 8px;
}

.history-item:hover { background: var(--accent-soft); }
.history-item:last-child { border-bottom: none; }

.history-ip {
    font-family: var(--font-mono);
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-heading);
}

.history-time {
    font-size: 0.68rem;
    color: var(--text-muted);
    white-space: nowrap;
}

.history-empty {
    text-align: center;
    padding: 20px;
    font-size: 0.82rem;
    color: var(--text-muted);
}

/* --- CIDR Reference Toggle --- */
.ref-toggle { text-align: center; margin-top: 16px; }

.ref-toggle-btn {
    font-family: var(--font-sans);
    font-size: 0.78rem;
    font-weight: 500;
    color: var(--text-accent);
    background: transparent;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-sm);
    padding: 8px 20px;
    cursor: pointer;
    transition: all var(--transition-fast);
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.ref-toggle-btn:hover { background: var(--accent-soft); border-color: var(--border-focus); }

.ref-table-container { display: none; margin-top: 12px; animation: slideUp 0.3s ease-out; }
.ref-table-container.visible { display: block; }

/* --- Toast notification --- */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--toast-bg);
    color: var(--toast-text);
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 0.82rem;
    font-weight: 500;
    box-shadow: 0 8px 32px rgba(0,0,0,0.3);
    z-index: 1000;
    opacity: 0;
    transition: all 0.3s ease;
    pointer-events: none;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* --- Error --- */
.error-container {
    display: none;
    background: rgba(239, 68, 68, 0.08);
    border: 1px solid rgba(239, 68, 68, 0.2);
    border-radius: 6px;
    padding: 10px 14px;
    margin-bottom: 10px;
    color: var(--error);
    font-size: 0.82rem;
    font-weight: 500;
    animation: slideUp 0.25s ease-out;
}

.error-container.visible { display: flex; align-items: center; gap: 8px; }

/* --- Export bar --- */
.export-bar {
    display: flex;
    gap: 6px;
    justify-content: flex-end;
    margin-bottom: 8px;
}

/* --- Footer --- */
.app-footer {
    text-align: center;
    padding: 20px 16px;
    margin-top: 24px;
    border-top: 1px solid var(--border-subtle);
    color: var(--text-muted);
    font-size: 0.72rem;
}

/* --- Spinner --- */
.spinner {
    display: none;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* --- Responsive --- */
@media (max-width: 768px) {
    .app-container { padding: 10px 10px 36px; }
    .app-header { padding: 8px 0 0; margin-bottom: 8px; }
    .app-header h1 { font-size: 1.25rem; }
    .card { padding: 14px; margin-bottom: 10px; }
    .card-title { font-size: 0.88rem; margin-bottom: 10px; }
    .input-grid { gap: 8px; }
    .form-input, .form-select { padding: 8px 10px; font-size: 0.85rem; }
    .result-grid { grid-template-columns: repeat(2, 1fr); gap: 6px; }
    .result-item { padding: 8px 10px; }
    .result-label { font-size: 0.6rem; }
    .result-value { font-size: 0.82rem; }
    .btn-row { flex-direction: row; }
    .btn { padding: 8px 16px; font-size: 0.78rem; }
    .tool-form { grid-template-columns: 1fr; }
    .binary-row { flex-direction: column; align-items: flex-start; gap: 1px; }
    .binary-label { min-width: unset; }
    .subdivision-controls { flex-direction: column; align-items: stretch; }
    .data-table th, .data-table td { padding: 6px 8px; font-size: 0.7rem; }
}

@media (max-width: 400px) {
    .app-header h1 { font-size: 1.1rem; }
    .tool-tab { padding: 6px 10px; font-size: 0.72rem; }
    .result-grid { grid-template-columns: repeat(2, 1fr); }
    .result-value { font-size: 0.78rem; }
}

/* --- Scrollbar --- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-secondary); }
::-webkit-scrollbar-thumb { background: var(--text-muted); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-secondary); }
::selection { background: rgba(14, 165, 233, 0.3); color: var(--text-heading); }
.brand-wrap { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.brand-home { font-size: 12px; font-weight: 700; color: var(--text-muted, #8795a0); text-decoration: none; white-space: nowrap; }
