/* SmartDns NetOps Theme */
:root[data-theme="dark"], :root {
    --bg-dark: #0f172a;
    --bg-card: #1e293b;
    --primary: #3b82f6;
    --accent: #06b6d4;
    --danger: #ef4444;
    --success: #10b981;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --border-color: #334155;
    --border-card: #334155;
    --bg-card-hover: rgba(59, 130, 246, 0.1);
    --header-bg: rgba(15, 23, 42, 0.8);
    --sidebar-bg: rgba(30, 41, 59, 0.95);
    --input-bg: #0f172a;
    --input-focus-bg: #1e293b;
    --hover-bg: rgba(59, 130, 246, 0.1);
    --inner-bg: rgba(0, 0, 0, 0.2);
    --toast-bg: #1e293b;
}

:root[data-theme="light"] {
    --bg-dark: #f1f5f9;
    --bg-card: #ffffff;
    --primary: #2563eb;
    --accent: #0891b2;
    --danger: #dc2626;
    --success: #059669;
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --border-color: #e2e8f0;
    --border-card: #e2e8f0;
    --bg-card-hover: rgba(37, 99, 235, 0.05);
    --header-bg: rgba(255, 255, 255, 0.8);
    --sidebar-bg: rgba(255, 255, 255, 0.95);
    --input-bg: #f8fafc;
    --input-focus-bg: #ffffff;
    --hover-bg: rgba(37, 99, 235, 0.1);
    --inner-bg: rgba(0, 0, 0, 0.03);
    --toast-bg: #ffffff;
}

:root[data-theme="forest"] {
    --bg-dark: #0f1c15;
    --bg-card: #162a20;
    --primary: #10b981;
    --accent: #34d399;
    --danger: #ef4444;
    --success: #059669;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #6b7280;
    --border-color: #244233;
    --border-card: #244233;
    --bg-card-hover: rgba(16, 185, 129, 0.1);
    --header-bg: rgba(15, 28, 21, 0.8);
    --sidebar-bg: rgba(22, 42, 32, 0.95);
    --input-bg: #0f1c15;
    --input-focus-bg: #162a20;
    --hover-bg: rgba(16, 185, 129, 0.1);
    --inner-bg: rgba(0, 0, 0, 0.2);
    --toast-bg: #162a20;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
}

body {
    background-color: var(--bg-dark);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
header {
    background: var(--header-bg);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
}

.brand {
    font-size: 1.5rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Main Container */
main {
    flex: 1;
    padding: 2rem;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
}

/* Dashboard Grid */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.card {
    background: var(--bg-card);
    border-radius: 1rem;
    padding: 1.5rem;
    border: 1px solid var(--border-card);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    transition: transform 0.2s;
}

.card:hover {
    transform: translateY(-2px);
    border-color: var(--bg-card-hover);
}

.input:checked+.slider:before {
    transform: translateX(26px);
}

/* Helper Classes Refactor */
.live-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 1.5rem;
}

.live-card {
    height: 450px;
    display: flex;
    flex-direction: column;
}

.live-header {
    margin-bottom: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.status-disconnected {
    font-size: 0.7em;
    color: var(--text-muted);
}

.log-placeholder {
    color: var(--text-muted);
    text-align: center;
    margin-top: 20px;
}

.card-inner {
    background: var(--inner-bg);
    padding: 1rem;
    border-radius: 8px;
    margin-bottom: 1rem;
}

.section-subtitle {
    color: var(--text-muted);
    margin-bottom: 0.5rem;
    font-size: 0.9em;
}

.input-row {
    display: flex;
    gap: 10px;
}

.input-field {
    flex: 1;
}

/* Inputs already styled globally but flex needs helper */
.card-title {
    color: var(--text-secondary);
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.5rem;
}

.card-value {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--text-primary);
}

.card-icon {
    float: right;
    font-size: 1.5rem;
    background: var(--border-card);
    padding: 8px;
    border-radius: 8px;
}

.card-clickable {
    cursor: pointer;
}

.icon-red {
    color: var(--danger);
}

.icon-blue {
    color: var(--primary);
}

.mb-1 {
    margin-bottom: 1rem;
}

/* Actions Section */
.actions-section {
    background: var(--bg-card);
    border-radius: 1rem;
    padding: 2rem;
    border: 1px solid var(--border-card);
}

.btn {
    padding: 0.75rem 1.5rem;
    border-radius: 0.5rem;
    border: none;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-primary);
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--accent));
}

.btn-primary:hover {
    opacity: 0.9;
    box-shadow: 0 0 15px rgba(59, 130, 246, 0.4);
}

.btn-danger {
    background: linear-gradient(135deg, #ef4444, #b91c1c);
}

.btn:active {
    transform: scale(0.98);
}

/* Status Indicator */
.status-pill {
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
    background: rgba(16, 185, 129, 0.2);
    color: var(--success);
    border: 1px solid rgba(16, 185, 129, 0.3);
}

/* --- Sidebar Layout --- */
.app-container {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 260px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border-card);
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
    position: fixed;
    height: 100%;
    overflow: hidden;
}

.sidebar-header {
    margin-bottom: 2rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
}

.sidebar nav {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

.nav-item {
    padding: 0.75rem 1rem;
    margin-bottom: 0.5rem;
    border-radius: 0.5rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 10px;
}

.sidebar-footer {
    margin-top: auto;
    border-top: 1px solid var(--border-color);
    padding-top: 1rem;
    flex-shrink: 0;
}

/* Inputs - Fixed for Dark Mode (V18) */
input,
select,
textarea {
    width: 100%;
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 0.75rem;
    border-radius: 6px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--hover-bg);
    background: var(--input-focus-bg);
}

/* User Info */
.user-info {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.user-role {
    color: var(--primary);
}

.nav-logout {
    color: var(--danger);
}

.nav-item:hover,
.nav-item.active {
    background: var(--hover-bg);
    color: var(--primary);
}

.nav-icon {
    width: 20px;
    text-align: center;
}

.main-content {
    flex: 1;
    margin-left: 260px;
    /* Width of sidebar */
    padding: 2rem;
    background: var(--bg-dark);
}

.view-section {
    display: none;
    animation: fadeIn 0.3s ease;
}

.view-section.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* =============================================
   MOBILE RESPONSIVE (≤ 768px)
   ============================================= */

/* Hamburger Button (hidden on desktop) */
.hamburger-btn {
    display: none;
    background: none;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.3rem 0.6rem;
    border-radius: 6px;
    line-height: 1;
    transition: background 0.2s;
}

.hamburger-btn:hover {
    background: var(--border-card);
}

/* Sidebar Overlay */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    z-index: 998;
    backdrop-filter: blur(2px);
}

.sidebar-overlay.active {
    display: block;
}

@media (max-width: 768px) {

    /* --- Hamburger visible --- */
    .hamburger-btn {
        display: inline-flex;
    }

    /* --- Sidebar: slide-in drawer --- */
    .sidebar {
        width: 260px;
        padding: 1.5rem;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        z-index: 999;
        overflow-y: auto;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    /* --- Main content: full width --- */
    .main-content {
        margin-left: 0;
        padding: 1rem;
    }

    /* --- Header bar: stack vertically --- */
    .main-content>div:first-child {
        flex-direction: column;
        gap: 0.75rem;
        align-items: flex-start !important;
        margin-bottom: 1rem !important;
    }

    .main-content>div:first-child>div {
        width: 100%;
        justify-content: space-between;
    }

    /* --- Dashboard grid: 2 per row on mobile --- */
    .dashboard-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
    }

    /* --- Card values smaller --- */
    .card-value {
        font-size: 1.5rem;
    }

    .card {
        padding: 1rem;
        border-radius: 0.75rem;
    }

    /* --- Live grid: single column --- */
    .live-grid {
        grid-template-columns: 1fr;
    }

    .live-card {
        height: 300px;
    }

    /* --- Tab bar: horizontal scroll --- */
    .tab-bar {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        flex-wrap: nowrap;
        white-space: nowrap;
        padding-bottom: 2px;
    }

    .tab-bar::-webkit-scrollbar {
        display: none;
    }

    .tab-btn {
        padding: 0.5rem 1rem;
        font-size: 0.8rem;
        flex-shrink: 0;
    }

    /* --- All 2-column grids → 1 column --- */
    [style*="grid-template-columns: 1fr 1fr"],
    [style*="grid-template-columns:1fr 1fr"] {
        grid-template-columns: 1fr !important;
    }

    /* --- Input rows: stack on mobile --- */
    .input-row {
        flex-direction: column;
    }

    /* --- Buttons: full width on mobile --- */
    .btn {
        font-size: 0.8rem;
        padding: 0.6rem 1rem;
    }

    /* --- Tables: proper horizontal scroll --- */
    .styled-table,
    table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        font-size: 0.75rem;
    }

    .styled-table thead,
    .styled-table tbody,
    table thead,
    table tbody {
        display: table;
        width: max-content;
        min-width: 500px;
    }

    .styled-table th,
    .styled-table td,
    table th,
    table td {
        padding: 6px 8px !important;
        white-space: nowrap;
        font-size: 0.72rem;
    }

    /* --- Toasts: full width on mobile --- */
    .toast-container {
        top: 0.75rem;
        right: 0.75rem;
        left: 0.75rem;
    }

    .toast {
        min-width: unset;
        max-width: unset;
        width: 100%;
        font-size: 0.8rem;
    }

    /* --- Flex justify-between: don't break --- */
    .flex-justify-between {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    /* --- Config cards: less padding --- */
    .config-card-green,
    .config-card-pink,
    .config-card-blue,
    .config-card-purple {
        padding: 1rem;
        margin-bottom: 1rem;
    }

    /* --- Page title smaller --- */
    #page-title {
        font-size: 1.2rem;
    }

    /* --- Inline stats grids (3-4 col → 2 col) --- */
    [style*="grid-template-columns:1fr 1fr 1fr 1fr"],
    [style*="grid-template-columns: 1fr 1fr 1fr 1fr"] {
        grid-template-columns: 1fr 1fr !important;
    }

    [style*="grid-template-columns:1fr 1fr 1fr"],
    [style*="grid-template-columns: 1fr 1fr 1fr"] {
        grid-template-columns: 1fr 1fr !important;
    }

    /* --- Auto-fill/auto-fit grids: ensure 2 cols min --- */
    [style*="repeat(auto-fill"] {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    [style*="repeat(auto-fit"] {
        grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)) !important;
    }

    /* --- Smaller text for mobile readability --- */
    h3 {
        font-size: 1.1rem;
    }

    h4 {
        font-size: 0.95rem;
    }

    p, label {
        font-size: 0.82rem;
    }

    /* --- Flex displays that overflow: allow wrapping --- */
    [style*="display:flex"],
    [style*="display: flex"] {
        flex-wrap: wrap;
    }

    /* --- Force gap reduction on tight layouts --- */
    [style*="gap:1.5rem"],
    [style*="gap: 1.5rem"] {
        gap: 0.75rem !important;
    }
}

/* Tablet adjustments (769px - 1024px) */
@media (min-width: 769px) and (max-width: 1024px) {
    .sidebar {
        width: 200px;
        padding: 1rem;
    }

    .main-content {
        margin-left: 200px;
        padding: 1.5rem;
    }

    .nav-item {
        font-size: 0.85rem;
        padding: 0.6rem 0.75rem;
    }

    .dashboard-grid {
        grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    }
}

/* Flex Utilities */
.flex-1 {
    flex: 1;
}

.flex-2 {
    flex: 2;
}

.flex-gap-5 {
    display: flex;
    gap: 5px;
}

.flex-align-start {
    align-items: start;
}

.flex-align-center {
    align-items: center;
}

.flex-justify-between {
    display: flex;
    justify-content: space-between;
}

/* Config Cards */
.config-card-green {
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid rgba(16, 185, 129, 0.2);
    margin-bottom: 2rem;
    padding: 1.5rem;
    border-radius: 12px;
}

.config-card-pink {
    background: rgba(236, 72, 153, 0.1);
    border: 1px solid rgba(236, 72, 153, 0.2);
    margin-bottom: 2rem;
    padding: 1.5rem;
    border-radius: 12px;
}

.config-card-blue {
    border: 1px solid #3b82f6;
    background: rgba(59, 130, 246, 0.05);
    margin-top: 2rem;
    padding: 1.5rem;
    border-radius: 12px;
}

.config-card-purple {
    border: 1px solid #8b5cf6;
    background: rgba(139, 92, 246, 0.05);
    margin-top: 2rem;
    padding: 1.5rem;
    border-radius: 12px;
}

.doh-options {
    margin-top: 1rem;
    display: none;
    border-top: 1px dashed rgba(236, 72, 153, 0.3);
    padding-top: 10px;
}

.doh-list {
    display: flex;
    flex-direction: column;
    gap: 5px;
    background: var(--bg-card);
    padding: 10px;
    border-radius: 4px;
    border: 1px solid var(--border-color);
}

.input-group {
    margin-bottom: 1.5rem;
}

.label-muted {
    display: block;
    color: var(--text-muted);
    margin-bottom: 5px;
}

/* === Toast Notification System === */
.toast-container {
    position: fixed;
    top: 1.5rem;
    right: 1.5rem;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    pointer-events: none;
}

.toast {
    pointer-events: auto;
    min-width: 300px;
    max-width: 420px;
    padding: 1rem 1.25rem;
    border-radius: 12px;
    background: var(--toast-bg);
    backdrop-filter: blur(16px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    color: var(--text-primary);
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 10px;
    animation: toastIn 0.35s cubic-bezier(0.21, 1.02, 0.73, 1) forwards;
    cursor: pointer;
    transition: opacity 0.3s, transform 0.3s;
}

.toast.toast-out {
    animation: toastOut 0.3s ease forwards;
}

.toast-icon {
    font-size: 1.2rem;
    flex-shrink: 0;
}

.toast-message {
    flex: 1;
    line-height: 1.4;
}

.toast-progress {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 3px;
    border-radius: 0 0 12px 12px;
    animation: toastProgress 3.5s linear forwards;
}

.toast.success {
    border-left: 3px solid #10b981;
}

.toast.success .toast-progress {
    background: #10b981;
}

.toast.error {
    border-left: 3px solid #ef4444;
}

.toast.error .toast-progress {
    background: #ef4444;
}

.toast.warning {
    border-left: 3px solid #f59e0b;
}

.toast.warning .toast-progress {
    background: #f59e0b;
}

.toast.info {
    border-left: 3px solid #3b82f6;
}

.toast.info .toast-progress {
    background: #3b82f6;
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateX(100%);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes toastOut {
    from {
        opacity: 1;
        transform: translateX(0);
    }

    to {
        opacity: 0;
        transform: translateX(100%);
    }
}

@keyframes toastProgress {
    from {
        width: 100%;
    }

    to {
        width: 0%;
    }
}

/* === Tab System === */
.tab-bar {
    display: flex;
    gap: 0;
    border-bottom: 2px solid rgba(255, 255, 255, 0.06);
    margin-bottom: 1.5rem;
}

.tab-btn {
    padding: 0.75rem 1.5rem;
    background: none;
    border: none;
    color: #64748b;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    position: relative;
    transition: color 0.25s;
    font-family: inherit;
}

.tab-btn:hover {
    color: #94a3b8;
}

.tab-btn.active {
    color: var(--primary);
}

.tab-btn.active::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    width: 100%;
    height: 2px;
    background: linear-gradient(90deg, var(--primary), var(--accent));
    border-radius: 2px 2px 0 0;
}

.tab-panel {
    display: none;
    animation: fadeIn 0.3s ease;
}

.tab-panel.active {
    display: block;
}