@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@300;400;500;600;700;800&family=Outfit:wght@300;400;500;600;700;800&family=Space+Grotesk:wght@400;500;600;700&display=swap');

:root {
    --bg-main: #0a0b10;
    --bg-sidebar: #11131a;
    --bg-card: rgba(22, 25, 34, 0.55);
    --bg-surface: #1e2230;
    --text-primary: #ffffff;
    --text-secondary: #94a3b8;
    --accent: #3b82f6;
    --accent-gradient: linear-gradient(135deg, #3b82f6, #8b5cf6);
    --accent-glow: rgba(59, 130, 246, 0.3);
    --border: rgba(255, 255, 255, 0.06);
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --sidebar-width: 260px;
    --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.4), 0 8px 10px -6px rgba(0, 0, 0, 0.4);
}

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

.hidden {
    display: none !important;
}

.bottom-nav {
    display: none;
}

body {
    font-family: 'Plus Jakarta Sans', 'Inter', -apple-system, sans-serif;
    background-color: var(--bg-main);
    color: var(--text-primary);
    overflow-x: hidden;
}

.app-container {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    z-index: 1000; /* v34.5: Always on top */
}

.sidebar-header {
    padding: 30px 24px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-icon {
    font-size: 24px;
    background: linear-gradient(135deg, #3b82f6, #8b5cf6);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.logo-text {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.sidebar-nav {
    padding: 0 12px;
    flex: 1;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: 8px;
    margin-bottom: 4px;
    transition: all 0.2s ease;
    font-weight: 500;
}

.nav-item:hover {
    background-color: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
}

.nav-item.active {
    background-color: var(--accent);
    color: white;
    box-shadow: 0 4px 12px var(--accent-glow);
}

.sidebar-footer {
    padding: 24px;
    border-top: 1px solid var(--border);
}

.admin-info {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}

.admin-avatar {
    width: 36px;
    height: 36px;
    background: var(--accent);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
}

.admin-details {
    display: flex;
    flex-direction: column;
}

.admin-name {
    font-size: 14px;
    font-weight: 600;
}

.admin-role {
    font-size: 11px;
    color: var(--text-secondary);
}

.logout-btn {
    display: block;
    width: 100%;
    padding: 8px;
    text-align: center;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 12px;
    transition: all 0.2s;
}

.logout-btn:hover {
    background-color: var(--danger);
    color: white;
    border-color: var(--danger);
}

/* Main Content */
.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0; /* v34.7: Prevent content from blowing out width */
}

.top-bar {
    padding: 20px 40px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: rgba(10, 11, 16, 0.8);
    backdrop-filter: blur(10px);
    position: sticky;
    top: 0;
    z-index: 500; /* v34.5: Above content, below sidebar */
}

.page-title {
    font-size: 18px;
    font-weight: 600;
}

.system-badge {
    font-size: 12px;
    padding: 4px 12px;
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid rgba(16, 185, 129, 0.2);
    border-radius: 20px;
    color: var(--success);
}

.system-badge span {
    font-weight: 700;
}

.content-body {
    padding: 30px 40px;
    transition: padding 0.3s ease;
}

/* Telegram Mini App (TMA) Mode Overrides */
body.tma-mode .sidebar {
    display: none !important;
}

body.tma-mode .top-bar {
    display: none !important;
}

body.tma-mode .main-content {
    margin-left: 0 !important;
}

body.tma-mode .content-body {
    padding: 15px !important;
    padding-bottom: 100px !important;
}

body.tma-mode .stats-grid {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
}

body.tma-mode .stat-card {
    padding: 16px !important;
}

body.tma-mode .stat-value {
    font-size: 24px !important;
}

body.tma-mode .fleet-grid {
    grid-template-columns: 1fr !important;
    gap: 10px !important;
}

body.tma-mode .table-container {
    margin-top: 15px !important;
    border-radius: 8px !important;
    box-shadow: none !important;
}

body.tma-mode table th, 
body.tma-mode table td {
    padding: 12px 10px !important;
    font-size: 13px !important;
}

/* System URLs Card and Quick Actions responsiveness rules */
/* Premium Connection Gateways Card */
.system-urls-card {
    background: linear-gradient(135deg, rgba(22, 25, 34, 0.6), rgba(17, 19, 26, 0.8)) !important;
    border: 1px solid rgba(255, 255, 255, 0.05) !important;
    border-radius: 16px;
    padding: 24px;
    margin-bottom: 30px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.3);
}

.urls-card-header {
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--text-secondary);
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 8px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 12px;
}

.urls-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 32px;
}

.url-section {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.url-section.border-left {
    border-left: 1px solid var(--border);
    padding-left: 32px;
}

.url-section .section-title {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

.url-section .dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    display: inline-block;
}
.url-section .dot.admin-dot { background: var(--accent); box-shadow: 0 0 8px var(--accent); }
.url-section .dot.app-dot { background: var(--success); box-shadow: 0 0 8px var(--success); }

.gateway-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.03);
    padding: 10px 16px;
    border-radius: 10px;
    transition: background 0.2s;
}

.gateway-row:hover {
    background: rgba(255, 255, 255, 0.04);
}

.gateway-label {
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 500;
}

.gateway-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.gateway-btn {
    text-decoration: none;
    font-size: 11px;
    font-weight: 700;
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
    outline: none;
}

.gateway-btn.local {
    background: rgba(16, 185, 129, 0.1);
    color: var(--success);
    border: 1px solid rgba(16, 185, 129, 0.2);
}
.gateway-btn.local:hover {
    background: var(--success);
    color: white;
}

.gateway-btn.public {
    background: rgba(59, 130, 246, 0.1);
    color: var(--accent);
    border: 1px solid rgba(59, 130, 246, 0.2);
}
.gateway-btn.public:hover {
    background: var(--accent);
    color: white;
}

.gateway-btn.copy-btn {
    background: rgba(255, 255, 255, 0.03);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}
.gateway-btn.copy-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

.quick-actions-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
}

body.tma-mode .urls-grid {
    grid-template-columns: 1fr !important;
    gap: 24px !important;
}

body.tma-mode .url-section.border-left {
    border-left: none !important;
    border-top: 1px solid var(--border) !important;
    padding-left: 0 !important;
    padding-top: 24px !important;
}

body.tma-mode .quick-actions-grid {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
}

/* Dashboard Cards */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 24px;
    margin-bottom: 30px;
}

.dashboard-grid {
    display: grid; 
    grid-template-columns: 2fr 1fr; 
    gap: 30px; 
    margin-top: 40px;
}

@media (max-width: 1024px) {
    .dashboard-grid {
        grid-template-columns: 1fr;
        gap: 20px;
    }
}

.stat-card {
    background: rgba(22, 25, 34, 0.55);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    padding: 24px;
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.05);
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.2);
}

.stat-card:hover {
    transform: translateY(-4px);
    border-color: var(--accent);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.4), 0 0 15px rgba(59, 130, 246, 0.15);
}

.stat-label {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 8px;
    position: relative;
    z-index: 1;
    display: flex;
    align-items: center;
}

.stat-value {
    font-family: 'Outfit', sans-serif;
    font-size: 30px;
    font-weight: 700;
    position: relative;
    z-index: 1;
    background: linear-gradient(180deg, #ffffff 0%, #cbd5e1 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* Fleet Grid */
.fleet-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
    margin-top: 20px;
}

.fleet-item {
    background-color: var(--bg-card);
    padding: 20px;
    border-radius: 12px;
    border: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.3s;
}

.fleet-item:hover {
    border-color: var(--accent);
    background: var(--bg-surface);
}

.fleet-name {
    font-size: 15px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.fleet-status {
    font-size: 12px;
    margin-top: 4px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.section-title {
    margin-top: 40px;
    font-size: 14px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 10px;
}

.section-title::after {
    content: "";
    flex: 1;
    height: 1px;
    background: var(--border);
}

/* Tables */
.table-container {
    background-color: var(--bg-card);
    border-radius: 12px;
    border: 1px solid var(--border);
    overflow: hidden;
    margin-top: 20px;
}

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

th {
    text-align: left;
    padding: 16px 24px;
    background-color: rgba(255, 255, 255, 0.02);
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border);
}

td {
    padding: 16px 24px;
    font-size: 14px;
    border-bottom: 1px solid var(--border);
}

tr:last-child td {
    border-bottom: none;
}

tr:hover td {
    background-color: rgba(255, 255, 255, 0.02);
}

.badge {
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
}

.badge-success { background: rgba(16, 185, 129, 0.1); color: var(--success); }
.badge-danger { background: rgba(239, 68, 68, 0.1); color: var(--danger); }
.badge-warning { background: rgba(245, 158, 11, 0.1); color: var(--warning); }
.badge-info { background: rgba(59, 130, 246, 0.1); color: var(--accent); }

/* Buttons */
.btn-primary {
    padding: 12px;
    background-color: var(--accent);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    text-decoration: none;
}

.btn-primary:hover {
    background-color: #2563eb;
    transform: scale(1.02);
    box-shadow: 0 4px 15px var(--accent-glow);
}

.btn-primary:active {
    transform: scale(0.98);
}

/* Forms */
.form-input {
    width: 100%;
    padding: 12px 16px;
    background-color: var(--bg-main);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: white;
    font-size: 14px;
    transition: border-color 0.2s;
}

.form-input:focus {
    outline: none;
    border-color: var(--accent);
}

/* Login Page */
.login-page {
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(circle at top right, #1e293b, var(--bg-main));
}

.login-card {
    width: 100%;
    max-width: 400px;
    background-color: var(--bg-card);
    padding: 40px;
    border-radius: 16px;
    border: 1px solid var(--border);
    box-shadow: 0 20px 40px rgba(0,0,0,0.4);
    text-align: center;
}

body.tma-mode .login-card {
    padding: 30px 20px !important;
    max-width: 90% !important;
    border-radius: 12px !important;
}

/* Pagination */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 30px;
    padding: 10px;
}

.page-link {
    min-width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.page-link:hover:not(.active) {
    border-color: var(--accent);
    color: var(--text-primary);
    transform: translateY(-2px);
    background: rgba(255, 255, 255, 0.05);
}

.page-link.active {
    background: var(--accent-gradient);
    color: white;
    border-color: transparent;
    box-shadow: 0 4px 12px var(--accent-glow);
}

.page-link.dots {
    border: none;
    background: transparent;
    cursor: default;
}

/* Side Panel / Detail Overlay */
.side-panel {
    position: fixed;
    top: 0;
    right: -100%;
    width: 500px;
    max-width: 100%;
    height: 100vh;
    background: var(--bg-sidebar);
    border-left: 1px solid var(--border);
    z-index: 1000;
    transition: right 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: -10px 0 30px rgba(0,0,0,0.5);
    display: flex;
    flex-direction: column;
}

.side-panel.open {
    right: 0;
}

.side-panel-header {
    padding: 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(255,255,255,0.02);
}

.side-panel-body {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

.close-panel {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 24px;
    cursor: pointer;
    transition: color 0.2s;
}

.close-panel:hover {
    color: var(--text-primary);
}

/* Glassmorphism elements */
.glass {
    background: rgba(255, 255, 255, 0.03);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.05);
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: var(--bg-main);
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* Responsiveness Improvements */
@media (max-width: 1024px) {
    .sidebar { width: 80px; }
    .sidebar .logo-text, .sidebar .nav-item span:not(.icon), .sidebar .admin-details, .sidebar .logout-btn { display: none; }
    .sidebar .nav-item { justify-content: center; padding: 15px; }
    .main-content { margin-left: 80px; }
    .side-panel { width: 100%; }
}

@media (max-width: 768px) {
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .table-container { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: 0; }
    .top-bar { padding: 15px 20px; }
    .content-body { padding: 15px; }
    
    .pagination {
        gap: 4px !important;
        margin-top: 20px !important;
    }
    
    .pagination .page-link {
        min-width: 32px !important;
        height: 32px !important;
        font-size: 12px !important;
    }
}

@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr; }
}

/* Bottom Navigation (Mobile/TMA Only) */
body.tma-mode .bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 65px;
    background: var(--bg-sidebar);
    border-top: 1px solid var(--border);
    z-index: 2000;
    justify-content: space-around;
    align-items: center;
    padding-bottom: env(safe-area-inset-bottom);
    backdrop-filter: blur(10px);
}

body.tma-mode .bottom-nav .nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 8px;
    margin-bottom: 0;
    font-size: 10px;
}

/* Bottom Sheet Modal (Drawer) */
.bottom-sheet {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 3000;
    visibility: hidden;
    transition: visibility 0.3s ease;
}

.bottom-sheet.open {
    visibility: visible;
}

.bottom-sheet-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.bottom-sheet.open .bottom-sheet-overlay {
    opacity: 1;
}

.bottom-sheet-content {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    max-height: 80%;
    background: var(--bg-sidebar);
    border-top: 1px solid var(--border);
    border-radius: 20px 20px 0 0;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    display: flex;
    flex-direction: column;
    padding-bottom: env(safe-area-inset-bottom);
}

.bottom-sheet.open .bottom-sheet-content {
    transform: translateY(0);
}

.bottom-sheet-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 12px 16px 8px;
    position: relative;
    border-bottom: 1px solid var(--border);
}

.bottom-sheet-indicator {
    width: 36px;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin-bottom: 8px;
}

.bottom-sheet-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    margin: 0;
}

.bottom-sheet-close {
    position: absolute;
    top: 8px;
    right: 16px;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 28px;
    cursor: pointer;
    line-height: 1;
}

.bottom-sheet-body {
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.bottom-sheet-item {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px 16px;
    border-radius: 12px;
    color: var(--text-main);
    text-decoration: none;
    transition: background 0.2s ease;
}

.bottom-sheet-item:hover, .bottom-sheet-item.active {
    background: var(--bg-main);
}

.bottom-sheet-item.active {
    border-left: 3px solid var(--accent);
}

.bottom-sheet-item .icon {
    font-size: 22px;
    width: 24px;
    display: flex;
    justify-content: center;
}

.bottom-sheet-item .item-text {
    display: flex;
    flex-direction: column;
}

.bottom-sheet-item .title {
    font-size: 15px;
    font-weight: 500;
}

.bottom-sheet-item .desc {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 2px;
}

.bottom-sheet-divider {
    border: none;
    border-top: 1px solid var(--border);
    margin: 8px 0;
}

.bottom-sheet-item.logout {
    color: #ff4d4d;
}
.bottom-sheet-item.logout:hover {
    background: rgba(255, 77, 77, 0.1);
}

body.tma-mode .bottom-nav .nav-item.active {
    color: var(--accent);
    background: transparent;
    box-shadow: none;
}

body.tma-mode .bottom-nav .icon {
    font-size: 20px;
}

/* Mobile Card System for Tables */
@media (max-width: 768px) {
    .table-container {
        border: none !important;
        background: transparent !important;
    }

    table, thead, tbody, th, td, tr {
        display: block;
    }

    thead tr {
        position: absolute;
        top: -9999px;
        left: -9999px;
    }

    tr {
        background: var(--bg-card);
        margin-bottom: 15px;
        border-radius: 12px;
        border: 1px solid var(--border);
        padding: 10px;
        box-shadow: var(--shadow-lg);
    }

    td {
        border: none !important;
        position: relative;
        padding: 10px 10px 10px 45% !important;
        text-align: right;
        min-height: 40px;
        border-bottom: 1px solid rgba(255,255,255,0.05);
    }

    td:last-child {
        border-bottom: none;
        text-align: center;
        padding-left: 10px !important;
    }

    td:before {
        position: absolute;
        left: 12px;
        width: 40%;
        text-align: left;
        font-weight: 700;
        color: var(--text-secondary);
        content: attr(data-label);
        font-size: 11px;
        text-transform: uppercase;
    }

    /* Hide redundant elements in cards */
    body.tma-mode .top-bar, body.tma-mode .sidebar {
        display: none !important;
    }
}

.spin {
    animation: admin-spin 1s linear infinite;
    display: inline-block;
}

@keyframes admin-spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}
