/* ═══════════════════════════════════════════════════════════
   MikroTik Manager - Main Stylesheet
   ═══════════════════════════════════════════════════════════ */

:root {
    --primary: #1a73e8;
    --primary-dark: #1557b0;
    --primary-light: #e8f0fe;
    --success: #0f9d58;
    --danger: #ea4335;
    --warning: #f9ab00;
    --info: #4285f4;
    --dark: #202124;
    --gray-900: #3c4043;
    --gray-700: #5f6368;
    --gray-500: #9aa0a6;
    --gray-300: #dadce0;
    --gray-100: #f1f3f4;
    --gray-50: #f8f9fa;
    --white: #ffffff;
    --sidebar-width: 260px;
    --header-height: 56px;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 25px rgba(0,0,0,0.15);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--gray-100);
    color: var(--gray-900);
    display: flex;
    min-height: 100vh;
}

/* ─── Sidebar ──────────────────────────────────────────── */

.sidebar {
    width: var(--sidebar-width);
    background: var(--dark);
    color: var(--white);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    transition: transform 0.3s;
}

.sidebar-header {
    padding: 16px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    display: flex;
    align-items: center;
    gap: 12px;
}

.sidebar-header .logo {
    width: 36px;
    height: 36px;
    background: var(--primary);
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: 700;
}

.sidebar-header h1 {
    font-size: 16px;
    font-weight: 600;
}

.sidebar-header .sub {
    font-size: 11px;
    color: var(--gray-500);
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
}

.nav-section {
    padding: 12px 20px 4px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--gray-500);
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 20px;
    color: var(--gray-300);
    cursor: pointer;
    transition: all 0.15s;
    border-left: 3px solid transparent;
    font-size: 14px;
}

.nav-item:hover {
    background: rgba(255,255,255,0.05);
    color: var(--white);
}

.nav-item.active {
    background: rgba(26,115,232,0.15);
    color: var(--primary);
    border-left-color: var(--primary);
}

.nav-item .icon {
    width: 20px;
    text-align: center;
    font-size: 16px;
}

.nav-item .badge {
    margin-left: auto;
    background: var(--primary);
    color: white;
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 10px;
    min-width: 20px;
    text-align: center;
}

.sidebar-footer {
    padding: 12px 20px;
    border-top: 1px solid rgba(255,255,255,0.1);
}

.router-status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--gray-500);
    cursor: pointer;
    padding: 6px 0;
}

.router-status .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--danger);
    flex-shrink: 0;
}

.router-status .dot.connected {
    background: var(--success);
    box-shadow: 0 0 6px var(--success);
    animation: pulse-dot 2s ease-in-out infinite;
}

@keyframes pulse-dot {
    0%, 100% { box-shadow: 0 0 4px var(--success); }
    50% { box-shadow: 0 0 12px var(--success); }
}

.status-indicator {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 600;
}

.status-indicator .dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.status-indicator.online .dot {
    background: var(--success);
    box-shadow: 0 0 6px var(--success);
    animation: pulse-dot 2s ease-in-out infinite;
}

.status-indicator.online { color: var(--success); }

.status-indicator.offline .dot {
    background: var(--danger);
}

.status-indicator.offline { color: var(--danger); }

/* ─── Main Content ─────────────────────────────────────── */

.main {
    margin-left: var(--sidebar-width);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.header {
    height: var(--header-height);
    background: var(--white);
    border-bottom: 1px solid var(--gray-300);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 50;
}

.header h2 {
    font-size: 18px;
    font-weight: 600;
    color: var(--dark);
}

.header-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.content {
    flex: 1;
    padding: 24px;
}

/* ─── Cards ────────────────────────────────────────────── */

.card {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}

.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--gray-300);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-header h3 {
    font-size: 15px;
    font-weight: 600;
}

.card-body {
    padding: 20px;
}

.card-footer {
    padding: 12px 20px;
    border-top: 1px solid var(--gray-300);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
    color: var(--gray-700);
}

/* ─── Stat Cards ───────────────────────────────────────── */

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 16px;
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
}

.stat-icon.blue { background: var(--primary-light); color: var(--primary); }
.stat-icon.green { background: #e6f4ea; color: var(--success); }
.stat-icon.orange { background: #fef7e0; color: var(--warning); }
.stat-icon.red { background: #fce8e6; color: var(--danger); }

.stat-info h4 {
    font-size: 24px;
    font-weight: 700;
    color: var(--dark);
}

.stat-info p {
    font-size: 13px;
    color: var(--gray-700);
}

.stat-card.clickable {
    cursor: pointer;
    transition: all 0.2s;
    border: 2px solid transparent;
}

.stat-card.clickable:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow-lg);
    transform: translateY(-2px);
}

.stat-card.clickable:active {
    transform: translateY(0);
}

/* ─── Tables ───────────────────────────────────────────── */

.table-wrapper {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

thead th {
    background: var(--gray-50);
    padding: 10px 14px;
    text-align: left;
    font-weight: 600;
    color: var(--gray-700);
    border-bottom: 2px solid var(--gray-300);
    white-space: nowrap;
    position: sticky;
    top: 0;
}

tbody td {
    padding: 10px 14px;
    border-bottom: 1px solid var(--gray-100);
    vertical-align: middle;
}

tbody tr:hover {
    background: var(--gray-50);
}

.table-actions {
    display: flex;
    gap: 4px;
}

/* ─── Buttons ──────────────────────────────────────────── */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    text-decoration: none;
    white-space: nowrap;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }

.btn-success { background: var(--success); color: white; }
.btn-success:hover:not(:disabled) { background: #0b8043; }

.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover:not(:disabled) { background: #c5221f; }

.btn-warning { background: var(--warning); color: var(--dark); }
.btn-warning:hover:not(:disabled) { background: #e69900; }

.btn-secondary { background: var(--gray-100); color: var(--gray-900); border: 1px solid var(--gray-300); }
.btn-secondary:hover:not(:disabled) { background: var(--gray-300); }

.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-lg { padding: 12px 24px; font-size: 15px; }

.btn-icon {
    width: 32px;
    height: 32px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
}

/* ─── Modals ───────────────────────────────────────────── */

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s;
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal {
    background: var(--white);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    width: 90%;
    max-width: 600px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    transform: translateY(20px);
    transition: transform 0.2s;
}

.modal-overlay.active .modal {
    transform: translateY(0);
}

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--gray-300);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-header h3 {
    font-size: 18px;
    font-weight: 600;
}

.modal-close {
    width: 32px;
    height: 32px;
    border: none;
    background: none;
    cursor: pointer;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    color: var(--gray-700);
    transition: background 0.15s;
}

.modal-close:hover {
    background: var(--gray-100);
}

.modal-body {
    padding: 24px;
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--gray-300);
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

/* ─── Forms ────────────────────────────────────────────── */

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 4px;
    color: var(--gray-700);
}

.form-group .hint {
    font-size: 11px;
    color: var(--gray-500);
    margin-top: 2px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="email"],
select,
textarea {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--gray-300);
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
    transition: border-color 0.15s;
    background: var(--white);
    color: var(--dark);
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(26,115,232,0.15);
}

textarea { resize: vertical; min-height: 60px; }

/* ─── Tags / Badges ────────────────────────────────────── */

.tag {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
}

.tag-blue { background: var(--primary-light); color: var(--primary); }
.tag-green { background: #e6f4ea; color: var(--success); }
.tag-red { background: #fce8e6; color: var(--danger); }
.tag-orange { background: #fef7e0; color: var(--warning); }
.tag-gray { background: var(--gray-100); color: var(--gray-700); }

/* ─── Alerts / Toast ───────────────────────────────────── */

.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 12px 20px;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    font-size: 14px;
    min-width: 280px;
    display: flex;
    align-items: center;
    gap: 10px;
    animation: slideIn 0.3s ease;
}

.toast-success { background: var(--success); color: white; }
.toast-error { background: var(--danger); color: white; }
.toast-info { background: var(--info); color: white; }
.toast-warning { background: var(--warning); color: var(--dark); }

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* ─── Search / Filter Bar ──────────────────────────────── */

.toolbar {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.search-box {
    position: relative;
    flex: 1;
    min-width: 200px;
}

.search-box input {
    padding-left: 36px;
}

.search-box .search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--gray-500);
}

/* ─── Loading ──────────────────────────────────────────── */

.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--gray-300);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    display: inline-block;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-overlay {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(255,255,255,0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

/* ─── Empty State ──────────────────────────────────────── */

.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--gray-500);
}

.empty-state .icon {
    font-size: 48px;
    margin-bottom: 12px;
}

.empty-state h4 {
    font-size: 16px;
    color: var(--gray-700);
    margin-bottom: 4px;
}

/* ─── Responsive ───────────────────────────────────────── */

/* List modal table styling */
#list-modal-content table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

#list-modal-content thead th {
    background: var(--gray-50);
    padding: 8px 12px;
    text-align: left;
    font-weight: 600;
    color: var(--gray-700);
    border-bottom: 2px solid var(--gray-300);
    white-space: nowrap;
    position: sticky;
    top: 0;
}

#list-modal-content tbody td {
    padding: 8px 12px;
    border-bottom: 1px solid var(--gray-100);
}

#list-modal-content tbody tr:hover {
    background: var(--gray-50);
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .main {
        margin-left: 0;
    }
    .form-row {
        grid-template-columns: 1fr;
    }
    .stats-grid {
        grid-template-columns: 1fr 1fr;
    }
}

/* ═══════════════════════════════════════════════════════════
   Firewall Toggle Styles
   ═══════════════════════════════════════════════════════════ */
.firewall-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 12px;
}

.firewall-toggle-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    border-radius: var(--radius);
    border: 1px solid var(--gray-300);
    background: var(--white);
    transition: all 0.2s ease;
}

.firewall-toggle-item:hover {
    box-shadow: var(--shadow);
}

.firewall-toggle-item.blocked {
    border-left: 3px solid var(--danger);
    background: #fef2f2;
}

.firewall-toggle-item.allowed {
    border-left: 3px solid var(--success);
    background: #f0fdf4;
}

.firewall-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.firewall-info strong {
    font-size: 14px;
    color: var(--dark);
}

.firewall-info small {
    font-size: 11px;
}

.toggle-label {
    font-size: 11px;
    font-weight: 600;
    min-width: 52px;
    text-align: center;
}

.text-red { color: var(--danger); }
.text-green { color: var(--success); }

/* Toggle Switch */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
    flex-shrink: 0;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: var(--success);
    border-radius: 24px;
    transition: 0.3s;
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    border-radius: 50%;
    transition: 0.3s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

input:checked + .toggle-slider {
    background-color: var(--danger);
}

input:checked + .toggle-slider:before {
    transform: translateX(20px);
}

.tag-orange {
    background: #fff7ed;
    color: #c2410c;
    border: 1px solid #fed7aa;
}

@media (max-width: 600px) {
    .firewall-grid {
        grid-template-columns: 1fr;
    }
}

/* ═══ Pagination ═══════════════════════════════════════════ */
.pagination-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    font-size: 13px;
    color: var(--text-muted);
}
.pagination-btns {
    display: flex;
    gap: 6px;
}
.pagination-btns .btn[disabled] {
    opacity: 0.4;
    cursor: not-allowed;
}

/* ═══ Filter select (supplement existing toolbar) ═════════ */
.filter-select {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    padding: 6px 10px;
    font-size: 13px;
    cursor: pointer;
}

/* ═══ Router Details ═══════════════════════════════════════ */
.router-details-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 8px;
    padding: 12px 16px 4px;
    border-top: 1px solid var(--border);
}
.router-detail-item {
    display: flex;
    flex-direction: column;
}
.detail-label {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.detail-value {
    font-size: 13px;
    color: var(--text-primary);
    font-weight: 500;
}
.router-meters {
    padding: 8px 16px 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.detail-meter {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.detail-meter-label {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: var(--text-muted);
}
.meter-track {
    height: 8px;
    background: var(--bg-primary);
    border-radius: 4px;
    overflow: hidden;
}
.meter-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.5s ease;
}
.meter-fill.green  { background: #22c55e; }
.meter-fill.orange { background: #f59e0b; }
.meter-fill.red    { background: #ef4444; }
.meter-fill.blue   { background: #3b82f6; }

/* ═══ Clickable stat cards ════════════════════════════════ */
.stat-card.clickable {
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
}
.stat-card.clickable:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0,0,0,0.15);
}

/* ═══ Sidebar dynamic title ═══════════════════════════════ */
.sidebar-header h1#sidebar-title {
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 170px;
}
