:root {
    --bg-color: #f4f7f6;
    --text-color: #1f2937;
    --topbar-bg: #ffffff;
    --sidebar-bg: #16212d;
    --sidebar-text: #edf2f7;
    --card-bg: #ffffff;
    --border-color: #e5e7eb;
    --input-bg: #ffffff;
    --primary-btn: #2563eb;
    --primary-btn-hover: #1d4ed8;
    --muted: #6b7280;
    --success: #10b981;
    --warning: #f59e0b;
    --shadow: rgba(15, 23, 42, 0.08);
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    min-height: 100%;
    font-family: Arial, sans-serif;
    background: var(--bg-color);
    color: var(--text-color);
}

img {
    max-width: 100%;
    display: block;
}

a {
    color: inherit;
    text-decoration: none;
}

button,
input,
select {
    font: inherit;
}

button {
    cursor: pointer;
}

.top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    background: var(--topbar-bg);
    border-bottom: 1px solid var(--border-color);
    padding: 10px 20px;
    height: 64px;
    position: sticky;
    top: 0;
    z-index: 5;
}

.logo-area {
    display: flex;
    align-items: center;
    margin-right: 18px;
    flex: 0 0 auto;
}

.logo-area img {
    height: 40px;
    object-fit: contain;
}

.menu-toggle {
    border: none;
    background: transparent;
    padding: 0;
    cursor: pointer;
}

.menu-toggle img {
    height: 40px;
    object-fit: contain;
}

.search-bar {
    flex: 1;
    display: flex;
    justify-content: flex-start;
    min-width: 0;
}

.search-bar input {
    width: 100%;
    background: var(--input-bg);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 10px 14px;
}

.main-container {
    display: flex;
    min-height: calc(100vh - 64px);
}

.sidebar {
    width: 72px;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    transition: width 0.2s ease;
    display: flex;
    flex-direction: column;
    border-right: 1px solid rgba(255, 255, 255, 0.05);
}

.sidebar.is-open {
    width: 250px;
}

@media (min-width: 901px) {
    .sidebar:hover {
        width: 250px;
    }
}

.sidebar-menu-items {
    list-style: none;
    padding: 0;
    margin: 0;
    flex: 1;
    overflow-y: auto;
}

.nav-item {
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.sidebar-link {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    min-height: 48px;
    padding: 14px 18px;
    color: var(--sidebar-text);
    transition: background 0.2s ease;
}

@media (min-width: 901px) {
    .sidebar:not(.is-open):not(:hover) .sidebar-link,
    .sidebar:not(.is-open):not(:hover) .sidebar-user-link {
        justify-content: center;
    }
}

.sidebar.is-open .sidebar-link,
.sidebar:hover .sidebar-link,
.sidebar.is-open .sidebar-user-link,
.sidebar:hover .sidebar-user-link {
    justify-content: flex-start;
}

.sidebar-link:hover,
.nav-item.active .sidebar-link {
    background: rgba(255, 255, 255, 0.08);
}

.menu-icon {
    width: 20px;
    height: 20px;
    display: inline-flex;
    justify-content: center;
    align-items: center;
    font-size: 18px;
    line-height: 1;
    flex: 0 0 20px;
}

.menu-icon img {
    display: block;
    width: 20px;
    height: 20px;
    object-fit: contain;
}

.menu-text {
    white-space: nowrap;
    overflow: hidden;
}

.sidebar .menu-text {
    display: none;
}

.sidebar.is-open .menu-text,
.sidebar:hover .menu-text {
    display: inline;
}

.sidebar-user {
    display: flex;
    align-items: center;
    min-height: 48px;
    padding: 12px 18px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-user.active {
    background: rgba(255, 255, 255, 0.08);
}

.sidebar-user-link {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    width: 100%;
    min-height: 24px;
    color: var(--sidebar-text);
}

.sidebar-user .menu-text {
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-bottom-actions {
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    padding: 12px 0 0;
}

.sidebar-copyright {
    display: none;
    font-size: 11px;
    color: rgba(255, 255, 255, 0.7);
    padding: 12px 18px 18px;
    text-align: center;
}

.sidebar.is-open .sidebar-copyright,
.sidebar:hover .sidebar-copyright,
.sidebar.is-open .sidebar-version {
    display: block;
}

.sidebar:hover .sidebar-version {
    display: block;
}

.sidebar-version {
    display: none;
    color: rgba(255, 255, 255, 0.7);
    font-size: 11px;
    padding: 8px 18px 0;
    text-align: center;
}

.content {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin-bottom: 24px;
}

.eyebrow {
    color: var(--muted);
    margin: 0 0 6px;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.page-header h1,
.page-header h2 {
    margin: 0;
    font-size: clamp(1.6rem, 2vw, 2.1rem);
}

.status-pill {
    background: rgba(16, 185, 129, 0.14);
    color: var(--success);
    border: 1px solid rgba(16, 185, 129, 0.25);
    border-radius: 999px;
    padding: 8px 12px;
    font-size: 12px;
    font-weight: 700;
}

.status-pill.unavailable {
    background: rgba(245, 158, 11, 0.14);
    color: #b45309;
    border-color: rgba(245, 158, 11, 0.25);
}

.service-unavailable {
    border-left: 4px solid #f59e0b;
}

.dashboard-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 20px;
    margin-bottom: 20px;
    min-width: 0;
}

.stat-card,
.panel-card,
.chart-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 4px 10px var(--shadow);
}

.stat-card {
    padding: 20px;
}

.stat-card p {
    margin: 0 0 10px;
    color: var(--muted);
    font-size: 14px;
}

.stat-card strong {
    font-size: 2rem;
    line-height: 1.2;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(260px, 1fr));
    gap: 20px;
    min-width: 0;
}

.chart-card {
    padding: 20px;
    min-width: 0;
}

.chart-card h3,
.panel-card h3 {
    margin: 0 0 16px;
}

.chart-card.wide {
    grid-column: span 2;
}

.mini-chart {
    display: flex;
    align-items: end;
    gap: 12px;
    min-height: 180px;
    padding-top: 12px;
    min-width: 0;
}

.mini-bar-group {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    height: 100%;
    min-width: 0;
}

.mini-bar {
    width: 100%;
    border-radius: 10px 10px 0 0;
    min-height: 18px;
    display: block;
}

.mini-bar-group small {
    color: var(--muted);
    font-size: 11px;
}

.module-page {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.module-grid,
.search-result-grid,
.summary-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 20px;
}

.panel-card {
    padding: 20px;
}

.search-result-link {
    color: var(--primary-btn);
    font-weight: 700;
    text-decoration: none;
    margin-top: 14px;
    display: inline-block;
}

.search-result-link:hover {
    text-decoration: underline;
}

.search-inline {
    margin-bottom: 16px;
}

.search-inline input {
    width: min(440px, 100%);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 10px 12px;
    background: var(--input-bg);
    color: var(--text-color);
}

.customer-row {
    cursor: pointer;
}

.customer-row:hover {
    background: rgba(37, 99, 235, 0.04);
}

.detail-modal {
    position: fixed;
    inset: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 30;
}

.detail-modal.hidden {
    display: none;
}

.detail-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.4);
}

.detail-modal-content {
    position: relative;
    z-index: 1;
    width: min(820px, calc(100vw - 32px));
    max-height: 80vh;
    overflow-y: auto;
    background: var(--card-bg);
    border-radius: 16px;
    border: 1px solid var(--border-color);
    box-shadow: 0 22px 60px rgba(15, 23, 42, 0.2);
    padding: 24px;
}

.close-modal {
    position: absolute;
    top: 16px;
    right: 16px;
    border: none;
    background: transparent;
    color: var(--text-color);
    font-size: 26px;
    line-height: 1;
}

.customer-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin-bottom: 20px;
}

.detail-section {
    margin-bottom: 22px;
}

.detail-section h4 {
    margin: 0 0 12px;
}

.device-group {
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 16px;
    background: rgba(148, 163, 184, 0.04);
    margin-top: 12px;
}

.device-group h5 {
    margin: 0 0 8px;
}

.detail-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.detail-list li {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border-color);
}

.detail-list li:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.detail-list span {
    color: var(--muted);
}

.detail-list a {
    color: var(--primary-btn);
    text-decoration: none;
    text-align: right;
}

.detail-list a:hover {
    text-decoration: underline;
}

.info-list,
.task-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.info-list li,
.task-list li {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border-color);
}

.info-list li:last-child,
.task-list li:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.info-list span,
.task-list span {
    color: var(--muted);
}

.primary-btn {
    border: none;
    border-radius: 8px;
    background: var(--primary-btn);
    color: white;
    padding: 10px 14px;
}

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

.table-wrap {
    overflow-x: auto;
}

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

.data-table th,
.data-table td {
    text-align: left;
    padding: 12px 14px;
    border-bottom: 1px solid var(--border-color);
}

.data-table th {
    color: var(--muted);
    font-size: 12px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.login-layout {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #0f172a, #1d4ed8);
}

.login-container {
    width: min(360px, calc(100vw - 32px));
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    box-shadow: 0 18px 50px rgba(15, 23, 42, 0.25);
    padding: 32px 24px;
}

.login-logo {
    text-align: center;
    margin-bottom: 20px;
}

.login-logo img {
    display: inline-block;
    max-width: 160px;
}

.login-container select,
.login-container input,
.login-container button {
    width: 100%;
    margin-bottom: 14px;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    padding: 11px 12px;
    background: var(--input-bg);
    color: var(--text-color);
}

.login-container button {
    background: var(--primary-btn);
    border: none;
    color: white;
    font-weight: 700;
    cursor: pointer;
}

.login-container button:hover {
    background: var(--primary-btn-hover);
}

.login-footer,
.login-footer-text {
    margin-top: 24px;
    color: #696969;
    font-family: Arial, sans-serif;
    font-size: 10px;
    font-weight: 400;
    line-height: 1.4;
    text-align: center;
    opacity: 0.9;
}

.login-footer-text {
    margin: 0;
    width: 100%;
}

.error-msg {
    color: #dc2626;
    background: rgba(220, 38, 38, 0.08);
    border: 1px solid rgba(220, 38, 38, 0.14);
    border-radius: 8px;
    padding: 10px 12px;
    margin-bottom: 14px;
    font-size: 14px;
}

.portal-footer {
    border-top: 1px solid var(--border-color);
    background: var(--topbar-bg);
    color: var(--muted);
    padding: 12px 20px;
    text-align: center;
    font-size: 12px;
}

@media (max-width: 900px) {
    .top-bar {
        height: 64px;
    }

    .main-container {
        display: block;
        min-height: calc(100vh - 64px);
    }

    .sidebar {
        position: fixed;
        top: 112px;
        bottom: 0;
        left: 0;
        width: min(250px, 82vw);
        z-index: 10;
        transform: translateX(-100%);
        transition: transform 0.2s ease;
    }

    .sidebar.is-open {
        width: min(250px, 82vw);
    }

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

    .sidebar .menu-text,
    .sidebar .sidebar-version,
    .sidebar .sidebar-copyright {
        display: block;
    }

    .sidebar {
        top: 64px;
    }

    .sidebar:hover {
        width: min(250px, 82vw);
    }

    .search-bar input {
        width: 100%;
    }

    .dashboard-stats {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .dashboard-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .chart-card.wide {
        grid-column: span 2;
    }

    .mobile-layout .dashboard-stats,
    .mobile-layout .dashboard-grid {
        grid-template-columns: 1fr;
    }

    .mobile-layout .chart-card.wide {
        grid-column: auto;
    }

    .content {
        min-height: calc(100vh - 64px);
    }
}

@media (min-width: 901px) and (max-width: 1100px) {
    .dashboard-stats {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .dashboard-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 900px) {
    .login-layout {
        width: 100%;
        height: 100dvh;
        min-height: 100dvh;
        overflow: hidden;
        padding: 16px;
    }

    .login-container {
        margin: 0 auto;
        max-height: calc(100dvh - 32px);
        overflow-y: auto;
    }
}
