/* =========================================================
   ISP PLATFORM - MASTER STYLESHEET
   ========================================================= */

:root {
    --bg-main: #10141c;
    --bg-sidebar: #151922;
    --bg-card: #171c25;
    --bg-hover: #202632;
    --bg-active: #242b38;

    --border: #272d38;
    --border-light: #303642;

    --primary: #3b82f6;
    --primary-hover: #2563eb;

    --success: #4ade80;
    --success-bg: #123c2a;

    --danger: #f87171;
    --danger-bg: #422020;

    --warning: #facc15;
    --warning-bg: #3d3513;

    --info: #60a5fa;
    --info-bg: #172d4d;

    --text: #ffffff;
    --text-secondary: #aeb5c1;
    --text-muted: #7f8796;
    --text-dark-muted: #687181;

    --sidebar-width: 245px;
}

/* =========================================================
   RESET
   ========================================================= */

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

html {
    width: 100%;
    min-height: 100%;
    background: var(--bg-main);
}

body {
    width: 100%;
    min-height: 100vh;

    font-family:
        Inter,
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        Roboto,
        Arial,
        sans-serif;

    background: var(--bg-main);
    color: var(--text);

    line-height: 1.5;
}

button,
input,
select,
textarea {
    font: inherit;
}

button {
    cursor: pointer;
}

a {
    color: inherit;
}

/* =========================================================
   MAIN APPLICATION
   ========================================================= */

.app {
    display: flex;

    width: 100%;
    min-height: 100vh;

    background: var(--bg-main);
}

/* =========================================================
   SIDEBAR
   ========================================================= */

.sidebar {
    position: fixed;

    top: 0;
    left: 0;
    bottom: 0;

    width: var(--sidebar-width);

    background: var(--bg-sidebar);

    border-right: 1px solid var(--border);

    padding: 22px 14px;

    overflow-y: auto;
    overflow-x: hidden;

    z-index: 100;
}

/* Scrollbar */

.sidebar::-webkit-scrollbar {
    width: 5px;
}

.sidebar::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar::-webkit-scrollbar-thumb {
    background: #303642;
    border-radius: 10px;
}

/* =========================================================
   SIDEBAR LOGO
   ========================================================= */

.sidebar > .logo {
    display: flex;

    align-items: center;

    height: 48px;

    padding: 0 13px;

    margin-bottom: 18px;

    color: #ffffff;

    font-size: 15px;

    font-weight: 800;

    letter-spacing: 0.5px;
}

.sidebar > .logo::before {
    content: "◉";

    width: 32px;
    height: 32px;

    margin-right: 10px;

    display: flex;

    align-items: center;
    justify-content: center;

    border-radius: 9px;

    background:
        linear-gradient(
            135deg,
            #3b82f6,
            #2563eb
        );

    color: white;

    font-size: 15px;

    box-shadow:
        0 8px 20px rgba(37, 99, 235, 0.25);
}

/* =========================================================
   MENU TITLE
   ========================================================= */

.menu-title {
    margin:

        22px 10px 8px;

    color: #687181;

    font-size: 10px;

    font-weight: 800;

    letter-spacing: 0.12em;
}

/* =========================================================
   MENU ITEMS
   ========================================================= */

.menu-item {
    width: 100%;

    min-height: 42px;

    display: flex;

    align-items: center;

    gap: 11px;

    padding: 10px 12px;

    margin-bottom: 3px;

    border: 1px solid transparent;

    border-radius: 8px;

    background: transparent;

    color: var(--text-secondary);

    text-decoration: none;

    font-size: 13px;

    font-weight: 500;

    transition:
        background 0.18s ease,
        color 0.18s ease,
        border-color 0.18s ease;
}

.menu-item > span:first-child {
    width: 20px;

    display: inline-flex;

    align-items: center;
    justify-content: center;

    color: #7f8796;

    font-size: 16px;
}

.menu-item:hover {
    background: var(--bg-hover);

    color: #ffffff;
}

.menu-item:hover > span:first-child {
    color: #ffffff;
}

.menu-item.active {
    background: var(--bg-active);

    border-color: var(--border-light);

    color: #ffffff;

    box-shadow:
        inset 3px 0 0 var(--primary);
}

.menu-item.active > span:first-child {
    color: #60a5fa;
}

/* =========================================================
   BADGES
   ========================================================= */

.badge {
    margin-left: auto;

    min-width: 22px;

    padding: 3px 7px;

    border-radius: 999px;

    text-align: center;

    font-size: 10px;

    font-weight: 700;
}

.badge.green {
    color: #4ade80;

    background: rgba(74, 222, 128, 0.10);
}

/* =========================================================
   DEVICES MENU
   ========================================================= */

.device-menu-wrapper {
    width: 100%;
}

.device-menu-toggle {
    width: 100%;

    text-align: left;

    outline: none;

    font-family: inherit;
}

.device-menu-toggle .device-arrow {
    width: auto;

    margin-left: auto;

    color: #687181;

    font-size: 9px;

    transition: transform 0.2s ease;
}

.device-menu-wrapper.open
.device-menu-toggle
.device-arrow {
    transform: rotate(180deg);
}

/* =========================================================
   DEVICE SUBMENU
   ========================================================= */

.device-submenu {
    display: none;

    margin:

        2px 0 5px 31px;

    padding-left: 8px;

    border-left: 1px solid var(--border);
}

.device-menu-wrapper.open .device-submenu {
    display: block;
}

.device-submenu a {
    min-height: 36px;

    display: flex;

    align-items: center;

    gap: 9px;

    padding: 8px 10px;

    color: var(--text-muted);

    border-radius: 7px;

    text-decoration: none;

    font-size: 12px;

    transition:
        background 0.18s ease,
        color 0.18s ease;
}

.device-submenu a:hover {
    background: var(--bg-hover);

    color: white;
}

.device-submenu a span {
    color: #687181;

    font-size: 13px;
}

/* =========================================================
   MAIN CONTENT
   ========================================================= */

.main {
    width: calc(100% - var(--sidebar-width));

    min-height: 100vh;

    margin-left: var(--sidebar-width);

    background: var(--bg-main);

    overflow-x: hidden;
}

/* =========================================================
   TOP BAR
   ========================================================= */

.topbar {
    min-height: 82px;

    display: flex;

    align-items: center;

    justify-content: space-between;

    gap: 20px;

    padding: 18px 28px;

    background: var(--bg-main);

    border-bottom: 1px solid var(--border);
}

.topbar h1 {
    color: #ffffff;

    font-size: 23px;

    font-weight: 700;

    letter-spacing: -0.5px;
}

.topbar p {
    margin-top: 4px;

    color: var(--text-muted);

    font-size: 12px;
}

/* =========================================================
   PROFILE
   ========================================================= */

.profile {
    display: flex;

    align-items: center;

    gap: 10px;

    padding: 6px 10px;

    border-radius: 10px;

    transition: background 0.2s ease;
}

.profile:hover {
    background: var(--bg-hover);
}

.avatar {
    width: 38px;
    height: 38px;

    display: flex;

    align-items: center;
    justify-content: center;

    border-radius: 10px;

    background:
        linear-gradient(
            135deg,
            #3b82f6,
            #2563eb
        );

    color: white;

    font-size: 14px;

    font-weight: 700;

    box-shadow:
        0 8px 20px rgba(37, 99, 235, 0.20);
}

.profile strong {
    display: block;

    color: #ffffff;

    font-size: 12px;

    font-weight: 700;
}

.profile small {
    display: block;

    margin-top: 2px;

    color: var(--text-muted);

    font-size: 10px;
}

/* =========================================================
   GENERAL CARD
   ========================================================= */

.card {
    background: var(--bg-card);

    border: 1px solid var(--border-light);

    border-radius: 12px;
}

/* =========================================================
   FORMS
   ========================================================= */

input,
select,
textarea {
    background: #10141c;

    border: 1px solid var(--border-light);

    color: #ffffff;

    border-radius: 8px;

    outline: none;

    transition:
        border-color 0.2s ease,
        box-shadow 0.2s ease;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--primary);

    box-shadow:
        0 0 0 3px rgba(59, 130, 246, 0.10);
}

input::placeholder,
textarea::placeholder {
    color: #596579;
}

/* =========================================================
   BUTTONS
   ========================================================= */

.btn {
    display: inline-flex;

    align-items: center;
    justify-content: center;

    gap: 8px;

    min-height: 38px;

    padding: 9px 14px;

    border: 1px solid var(--border-light);

    border-radius: 8px;

    background: var(--bg-card);

    color: var(--text-secondary);

    text-decoration: none;

    font-size: 12px;

    font-weight: 600;

    transition:
        background 0.2s ease,
        border-color 0.2s ease,
        transform 0.15s ease;
}

.btn:hover {
    background: var(--bg-hover);

    color: white;
}

.btn-primary {
    background: var(--primary);

    border-color: var(--primary);

    color: white;
}

.btn-primary:hover {
    background: var(--primary-hover);

    border-color: var(--primary-hover);
}

/* =========================================================
   STATUS
   ========================================================= */

.status {
    display: inline-flex;

    align-items: center;

    gap: 6px;

    padding: 5px 9px;

    border-radius: 999px;

    font-size: 10px;

    font-weight: 700;
}

.status.active,
.status.online {
    color: var(--success);

    background: var(--success-bg);
}

.status.warning {
    color: var(--warning);

    background: var(--warning-bg);
}

.status.danger,
.status.offline {
    color: var(--danger);

    background: var(--danger-bg);
}

/* =========================================================
   SEARCH
   ========================================================= */

.search-box {
    position: relative;

    width: 100%;
}

.search-box input {
    width: 100%;

    height: 42px;

    padding: 0 14px;
}

/* =========================================================
   TABLES
   ========================================================= */

.table-container {
    width: 100%;

    overflow-x: auto;

    background: var(--bg-card);

    border: 1px solid var(--border-light);

    border-radius: 12px;
}

table {
    width: 100%;

    border-collapse: collapse;
}

thead {
    background: rgba(255, 255, 255, 0.02);
}

th {
    padding: 13px 16px;

    text-align: left;

    color: var(--text-muted);

    border-bottom: 1px solid var(--border-light);

    font-size: 10px;

    font-weight: 700;

    text-transform: uppercase;

    letter-spacing: 0.04em;
}

td {
    padding: 14px 16px;

    color: var(--text-secondary);

    border-bottom: 1px solid rgba(255, 255, 255, 0.04);

    font-size: 12px;
}

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

tbody tr:hover {
    background: rgba(255, 255, 255, 0.018);
}

/* =========================================================
   MODAL
   ========================================================= */

.modal-overlay {
    position: fixed;

    inset: 0;

    display: none;

    align-items: center;
    justify-content: center;

    padding: 20px;

    background: rgba(0, 0, 0, 0.65);

    backdrop-filter: blur(5px);

    z-index: 1000;
}

.modal-overlay.show {
    display: flex;
}

.modal {
    width: min(600px, 100%);

    max-height: 90vh;

    overflow-y: auto;

    background: var(--bg-card);

    border: 1px solid var(--border-light);

    border-radius: 14px;

    box-shadow:
        0 30px 80px rgba(0, 0, 0, 0.45);
}

.modal-header {
    display: flex;

    align-items: center;

    justify-content: space-between;

    padding: 18px 20px;

    border-bottom: 1px solid var(--border-light);
}

.modal-header h2 {
    font-size: 17px;
}

.modal-close {
    width: 32px;
    height: 32px;

    border: none;

    border-radius: 7px;

    background: transparent;

    color: var(--text-muted);

    font-size: 18px;
}

.modal-close:hover {
    background: var(--bg-hover);

    color: white;
}

.modal-body {
    padding: 20px;
}

.modal-footer {
    display: flex;

    justify-content: flex-end;

    gap: 10px;

    padding: 15px 20px;

    border-top: 1px solid var(--border-light);
}

/* =========================================================
   NOTIFICATIONS / TOAST
   ========================================================= */

.toast {
    position: fixed;

    right: 25px;

    bottom: 25px;

    min-width: 280px;

    max-width: 400px;

    padding: 14px 17px;

    border-radius: 9px;

    background: #202632;

    border: 1px solid var(--border-light);

    color: white;

    box-shadow:
        0 15px 40px rgba(0, 0, 0, 0.30);

    z-index: 2000;

    font-size: 12px;
}

.toast.success {
    border-color: rgba(74, 222, 128, 0.25);
}

.toast.error {
    border-color: rgba(248, 113, 113, 0.25);
}

.toast.info {
    border-color: rgba(96, 165, 250, 0.25);
}

/* =========================================================
   SCROLLBAR
   ========================================================= */

::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

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

::-webkit-scrollbar-thumb {
    background: #303642;

    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: #3d4656;
}

/* =========================================================
   SELECTION
   ========================================================= */

::selection {
    background: rgba(59, 130, 246, 0.30);

    color: white;
}

/* =========================================================
   RESPONSIVE
   ========================================================= */

@media (max-width: 1000px) {

    :root {
        --sidebar-width: 220px;
    }

    .topbar {
        padding-left: 20px;
        padding-right: 20px;
    }
}

@media (max-width: 750px) {

    :root {
        --sidebar-width: 0px;
    }

    .sidebar {
        position: fixed;

        width: 245px;

        transform: translateX(-100%);

        transition: transform 0.25s ease;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .main {
        width: 100%;

        margin-left: 0;
    }

    .topbar {
        padding: 15px;
    }

    .topbar h1 {
        font-size: 19px;
    }

    .profile div:not(.avatar) {
        display: none;
    }
}

@media (max-width: 500px) {

    .topbar {
        min-height: 70px;
    }

    .topbar p {
        display: none;
    }

    .profile {
        padding: 0;
    }
}
/* =========================================================
   LOGOUT BUTTON
========================================================= */

.profile-info {
    display: flex;
    flex-direction: column;
}

.logout-button {
    margin-left: 10px;
    padding: 9px 14px;
    border: 1px solid var(--border-light);
    border-radius: 8px;
    background: var(--bg-hover);
    color: var(--danger);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease;
}

.logout-button:hover {
    background: var(--danger-bg);
    border-color: var(--danger);
}

/* =====================================================
   MOBILE HAMBURGER MENU (Phase 10.5)
   Auto-generates a menu button on small screens.
   No HTML changes needed.
===================================================== */

/* Hidden by default on desktop */
.mobile-menu-btn {
    display: none;
}

@media (max-width: 900px) {

    /* ---- Show the hamburger button ---- */
    .mobile-menu-btn {
        display: flex;
        align-items: center;
        justify-content: center;
        position: fixed;
        top: 16px;
        left: 16px;
        z-index: 10000;
        width: 44px;
        height: 44px;
        border-radius: 8px;
        background: var(--bg-card, #171c25);
        border: 1px solid var(--border-light, #303642);
        color: #fff;
        font-size: 22px;
        cursor: pointer;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
        padding: 0;
        line-height: 1;
    }

    .mobile-menu-btn:active {
        background: var(--bg-hover, #202938);
    }

    /* ---- Shift the topbar so it doesn't overlap the button ---- */
    .topbar {
        padding-left: 72px !important;
    }

    /* ---- Turn the sidebar into a slide-out drawer ---- */
    .sidebar {
        position: fixed !important;
        top: 0;
        left: 0;
        bottom: 0;
        width: 260px;
        max-width: 82vw;
        z-index: 9999;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        overflow-y: auto;
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.5);
    }

    /* When JS adds .mobile-open to <body>, slide it in */
    body.mobile-menu-open .sidebar {
        transform: translateX(0);
    }

    /* Dim overlay behind the sidebar */
    body.mobile-menu-open::after {
        content: "";
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.55);
        z-index: 9998;
        backdrop-filter: blur(2px);
    }

    /* Prevent the body from scrolling while the drawer is open */
    body.mobile-menu-open {
        overflow: hidden;
    }

    /* ---- Mobile tweaks for page content ---- */
    .dashboard,
    .routers-page,
    .subscribers-page,
    .mikrotik-page,
    .devices-page,
    .equipment-page,
    .fiber-page,
    .invoices-page,
    .payments-page,
    .vouchers-page,
    .agents-page,
    .analytics-page,
    .comm-page,
    .tickets-page,
    .expenses-page,
    .billing-page,
    .leads-page {
        padding: 18px !important;
    }

    /* ---- Tables: allow horizontal scroll on small screens ---- */
    .table-panel,
    .table-wrapper,
    .router-table-wrap,
    .subscriber-table-wrapper,
    .equipment-table-wrapper,
    .fiber-table-wrapper,
    .devices-table-wrap,
    .sessions-table-wrapper {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
    }

    /* ---- Cards stack nicely on mobile ---- */
    .stats-grid,
    .stats,
    .router-stats,
    .subscriber-stats,
    .equipment-summary-grid,
    .secondary-stats,
    .communication-stats {
        grid-template-columns: 1fr !important;
    }
}

/* Very small phones */
@media (max-width: 500px) {

    .topbar h1,
    .topbar p {
        font-size: 15px;
    }

    .profile {
        display: none !important;
    }

    .dashboard-actions,
    .fiber-action-buttons,
    .page-actions > div:last-child {
        flex-direction: column;
        align-items: stretch;
        width: 100%;
    }

    .dashboard-actions button,
    .fiber-action-buttons button,
    .page-actions button {
        width: 100%;
    }
}

/* =====================================================
   MOBILE TOPBAR — wrap so logout is visible
===================================================== */

@media (max-width: 900px) {

    /* Make the topbar wrap into rows */
    .topbar {
        display: flex !important;
        flex-wrap: wrap !important;
        align-items: center !important;
        justify-content: space-between !important;
        padding: 12px 16px 12px 68px !important;  /* 68px leaves room for ☰ */
        gap: 8px !important;
    }

    /* Title takes the full first row */
    .topbar h1,
    .topbar .page-title,
    .topbar > div:first-child {
        flex: 1 1 100% !important;
        width: 100% !important;
        order: 2 !important;
        margin: 4px 0 0 0 !important;
    }

    /* Profile + logout sit on the first row, right-aligned */
    .topbar .profile,
    .topbar .user-info,
    .topbar .topbar-actions,
    .topbar > div:last-child {
        order: 1 !important;
        display: flex !important;
        align-items: center !important;
        gap: 8px !important;
        margin-left: auto !important;
    }

    /* Make the logout button smaller on mobile */
    .topbar button,
    .topbar .logout-btn,
    .topbar a.btn {
        padding: 8px 14px !important;
        font-size: 13px !important;
        height: auto !important;
        white-space: nowrap !important;
    }

    /* Hide the profile text if it's making things cramped, keep the avatar */
    .topbar .profile span:not(.avatar),
    .topbar .user-info span:not(.avatar) {
        display: none !important;
    }
}

/* =====================================================
   MOBILE COMPACT — reduce overall page size
===================================================== */

@media (max-width: 500px) {

    /* Slightly smaller base text */
    html {
        font-size: 15px !important;
    }

    /* Tighter content padding */
    .dashboard,
    .routers-page,
    .subscribers-page,
    .mikrotik-page,
    .devices-page,
    .equipment-page,
    .fiber-page,
    .invoices-page,
    .payments-page,
    .vouchers-page,
    .agents-page,
    .analytics-page,
    .comm-page,
    .tickets-page,
    .expenses-page,
    .billing-page,
    .leads-page {
        padding: 14px !important;
    }

    /* Smaller cards */
    .card,
    .stat-card,
    .dashboard-card {
        padding: 16px !important;
        border-radius: 10px !important;
    }

    /* Smaller big numbers in stat cards */
    .card .number,
    .stat-card .number,
    .stat-value {
        font-size: 26px !important;
    }

    /* Smaller section headings */
    .dashboard h1,
    .routers-page h1,
    .subscribers-page h1,
    h1 {
        font-size: 22px !important;
    }

    /* Smaller buttons */
    button,
    .btn {
        font-size: 13px !important;
        padding: 10px 14px !important;
    }

    /* Stack action buttons vertically */
    .dashboard-actions,
    .page-actions {
        flex-direction: column !important;
        width: 100% !important;
    }

    .dashboard-actions button,
    .page-actions button {
        width: 100% !important;
    }

    /* Tables scroll sideways instead of overflowing */
    table {
        font-size: 12px !important;
    }

    .table-panel,
    .table-wrapper {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }
}
