/* Core layout */
:root {
    --color-bg: #ecfdf5;
    --color-surface: #ffffff;
    --color-primary: #10b981;
    --color-primary-dark: #059669;
    --color-accent: #34d399;
    --color-text: #111827;
    --color-muted: #4b5563;
    --color-border: #d1d5db;
    --radius: 16px;
    --shadow-sm: 0 4px 12px rgba(16, 185, 129, 0.12);
    --shadow-lg: 0 24px 48px rgba(16, 185, 129, 0.18);
    font-family: 'DM Sans', 'Poppins', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

body.app-body {
    margin: 0;
    background: linear-gradient(135deg, #ecfdf5 0%, #f9fafb 100%);
    color: var(--color-text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.container {
    width: min(1100px, 92vw);
    margin: 0 auto;
}

.app-header {
    position: sticky;
    top: 0;
    z-index: 20;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(226, 230, 240, 0.7);
}

.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 0;
    gap: 1.5rem;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-weight: 700;
    font-size: 1.25rem;
    color: var(--color-primary);
    text-decoration: none;
    letter-spacing: -0.01em;
}

.brand-logo {
    height: 100px;
    width: auto;
    object-fit: contain;
}

@media (max-width: 768px) {
    .brand-logo {
        height: 80px;
    }
}

.brand-text {
    display: inline-block;
}

.app-nav {
    display: flex;
}

.app-nav ul {
    list-style: none;
    display: flex;
    gap: 1rem;
    margin: 0;
    padding: 0;
    align-items: center;
}

.app-nav a {
    text-decoration: none;
    color: var(--color-muted);
    font-weight: 500;
    padding: 0.55rem 0.9rem;
    border-radius: 999px;
    transition: background 0.2s ease, color 0.2s ease;
}

.app-nav a:hover,
.app-nav a:focus-visible {
    background: rgba(16, 185, 129, 0.1);
    color: var(--color-primary);
}

/* Active navigation state */
.app-nav a.active,
.app-nav a.nav-link.active {
    background: rgba(16, 185, 129, 0.15);
    color: var(--color-primary);
    font-weight: 600;
}

/* Dropdown navigation */
.app-nav .dropdown {
    position: relative;
}

.app-nav .dropdown-toggle {
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.app-nav .dropdown-toggle::after {
    content: '';
    display: inline-block;
    width: 0;
    height: 0;
    margin-left: 0.2rem;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 5px solid currentColor;
    transition: transform 0.2s ease;
}

.app-nav .dropdown.is-open .dropdown-toggle::after {
    transform: rotate(180deg);
}

.app-nav .dropdown-menu {
    position: absolute;
    top: calc(100% + 0.5rem);
    right: 0;
    min-width: 220px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    padding: 0.5rem;
    list-style: none;
    margin: 0;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s ease;
    z-index: 100;
}

.app-nav .dropdown.is-open .dropdown-menu {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.app-nav .dropdown-menu li {
    margin: 0;
}

.app-nav .dropdown-menu a {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.7rem 1rem;
    border-radius: 8px;
    color: var(--color-text);
    font-weight: 500;
    transition: background 0.15s ease;
}

.app-nav .dropdown-menu a:hover {
    background: rgba(16, 185, 129, 0.1);
    color: var(--color-primary);
}

.app-nav .pill {
    background: var(--color-primary);
    color: #fff;
    box-shadow: var(--shadow-sm);
}

.app-nav .pill:hover,
.app-nav .pill:focus-visible {
    background: var(--color-primary-dark);
}

.nav-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--color-primary);
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

.app-main {
    flex: 1;
    padding: 3rem 0 4rem;
}

.app-footer {
    padding: 2rem 0;
    background: #1f2937;
    color: rgba(255, 255, 255, 0.7);
}

.footer-inner {
    text-align: center;
    font-size: 0.9rem;
}

.footer-inner .muted {
    color: rgba(255, 255, 255, 0.45);
    margin-top: 0.5rem;
}

/* Utility classes */
.grid {
    display: grid;
    gap: 1.5rem;
}

.grid.two {
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.grid.three {
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

.panel {
    background: var(--color-surface);
    border-radius: var(--radius);
    padding: 1.75rem;
    box-shadow: var(--shadow-sm);
}

.panel h2,
.panel h3 {
    margin-top: 0;
    margin-bottom: 0.75rem;
}

.hero {
    position: relative;
    overflow: hidden;
    background: radial-gradient(circle at top right, rgba(16, 185, 129, 0.15), transparent 45%),
                radial-gradient(circle at bottom left, rgba(16, 185, 129, 0.18), transparent 50%),
                var(--color-surface);
    border-radius: calc(var(--radius) * 1.4);
    padding: 3.5rem 3rem;
    box-shadow: var(--shadow-lg);
}

.hero h1 {
    font-size: clamp(2rem, 5vw, 3rem);
    line-height: 1.1;
    margin-bottom: 1rem;
}

.hero p.lead {
    font-size: 1.1rem;
    color: var(--color-muted);
    max-width: 540px;
}

.hero-buttons {
    margin-top: 2rem;
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.75rem 1.4rem;
    border-radius: 999px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    text-decoration: none;
}

.btn-primary {
    background: var(--color-primary);
    color: #fff;
    box-shadow: var(--shadow-sm);
}

.btn-primary:hover,
.btn-primary:focus-visible {
    background: var(--color-primary-dark);
    transform: translateY(-2px);
}

.btn-ghost {
    background: rgba(16, 185, 129, 0.1);
    color: var(--color-primary);
}

.btn-ghost:hover,
.btn-ghost:focus-visible {
    background: rgba(16, 185, 129, 0.2);
}

.btn-secondary {
    background: #1f2937;
    color: #fff;
}

.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    background: rgba(16, 185, 129, 0.12);
    color: var(--color-primary);
    padding: 0.35rem 0.8rem;
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: 600;
}

.flash-messages {
    margin-bottom: 1.5rem;
    display: grid;
    gap: 0.75rem;
}

.alert {
    padding: 1rem 1.2rem;
    border-radius: var(--radius);
    font-weight: 500;
    border: 1px solid transparent;
}

.alert-info {
    background: rgba(16, 185, 129, 0.12);
    color: var(--color-primary);
}

.alert-success {
    background: rgba(16, 190, 115, 0.12);
    color: #0b8457;
}

.alert-warning {
    background: rgba(255, 181, 70, 0.18);
    color: #9c6500;
}

.alert-error,
.alert-danger {
    background: rgba(236, 64, 122, 0.12);
    color: #bb154f;
}

.data-card {
    display: grid;
    gap: 0.3rem;
}

.data-card .value {
    font-size: 2rem;
    font-weight: 700;
}

.data-card .label {
    color: var(--color-muted);
    font-size: 0.9rem;
}

.table-wrap {
    overflow-x: auto;
    border-radius: calc(var(--radius) - 4px);
    box-shadow: var(--shadow-sm);
    background: var(--color-surface);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.95rem;
}

thead {
    background: rgba(0, 0, 0, 0.04);
}

th, td {
    padding: 0.85rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--color-border);
}

tbody tr:hover {
    background: rgba(16, 185, 129, 0.05);
}

form label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.35rem;
}

form .form-control,
form .form-select,
form select,
form input,
form textarea {
    width: 100%;
    padding: 0.7rem 0.9rem;
    border-radius: 12px;
    border: 1px solid rgba(0, 0, 0, 0.12);
    background: #fff;
    font-size: 1rem;
    transition: border 0.2s ease, box-shadow 0.2s ease;
}

form .form-control:focus,
form .form-select:focus,
form select:focus,
form input:focus,
form textarea:focus {
    border-color: var(--color-primary);
    outline: none;
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.15);
}

.form-actions {
    margin-top: 1.5rem;
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.muted {
    color: var(--color-muted);
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.45rem 0.75rem;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.06);
    color: var(--color-text);
    font-size: 0.85rem;
    font-weight: 600;
}

.status-online {
    color: #0b8457;
}

.status-slow {
    color: #cc8400;
}

.status-down {
    color: #cb1f45;
}

.status-maintenance {
    color: var(--color-primary);
}

.stats-strip {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.stat-pill {
    padding: 0.55rem 1rem;
    border-radius: 999px;
    background: rgba(16, 185, 129, 0.1);
    color: var(--color-primary);
    font-weight: 600;
    font-size: 0.9rem;
}

.copy-field {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.85rem 1rem;
    background: rgba(0, 0, 0, 0.04);
    border-radius: 14px;
    font-family: 'Inter', monospace;
}

.copy-field button {
    background: none;
    border: none;
    color: var(--color-primary);
    font-weight: 600;
    cursor: pointer;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.section-title {
    margin: 0;
    font-size: 1.4rem;
}

/* Breadcrumb navigation */
.breadcrumb {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    padding: 0.75rem 1rem;
    background: rgba(16, 185, 129, 0.05);
    border-radius: 12px;
    font-size: 0.9rem;
}

.breadcrumb a {
    color: var(--color-primary);
    text-decoration: none;
    font-weight: 500;
    transition: color 0.2s ease;
}

.breadcrumb a:hover {
    color: var(--color-primary-dark);
    text-decoration: underline;
}

.breadcrumb .separator {
    color: var(--color-muted);
    user-select: none;
}

.breadcrumb .current {
    color: var(--color-text);
    font-weight: 600;
}

.empty-state {
    padding: 3rem 2rem;
    text-align: center;
    color: var(--color-muted);
    border-radius: var(--radius);
    background: rgba(0, 0, 0, 0.05);
}

.empty-state i {
    font-size: 3rem;
    color: var(--color-border);
    margin-bottom: 1rem;
    display: block;
}

.empty-state h3 {
    margin: 0 0 0.5rem 0;
    color: var(--color-text);
    font-size: 1.25rem;
}

.empty-state p {
    margin-bottom: 1.5rem;
}

/* Loading states */
.btn.is-loading {
    position: relative;
    color: transparent;
    pointer-events: none;
}

.btn.is-loading::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    top: 50%;
    left: 50%;
    margin-left: -8px;
    margin-top: -8px;
    border: 2px solid transparent;
    border-top-color: currentColor;
    border-radius: 50%;
    animation: spinner 0.6s linear infinite;
}

.btn-primary.is-loading::after {
    border-top-color: white;
}

@keyframes spinner {
    to { transform: rotate(360deg); }
}

/* Form loading overlay */
form.is-submitting {
    position: relative;
    pointer-events: none;
    opacity: 0.6;
}

form.is-submitting::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.7);
    z-index: 10;
    border-radius: var(--radius);
}

.badge-success { background: rgba(8, 170, 120, 0.16); color: #056f4a; }
.badge-warning { background: rgba(255, 181, 70, 0.2); color: #915b00; }
.badge-danger { background: rgba(236, 64, 122, 0.18); color: #b61149; }
.badge-info { background: rgba(16, 185, 129, 0.16); color: var(--color-primary); }

.network-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.4rem 0.75rem;
    border-radius: 999px;
    font-weight: 600;
    font-size: 0.85rem;
    color: #1f2937;
}
.network-chip.mtn {
    background: rgba(255, 205, 0, 0.2);
    color: #a17800;
}
.network-chip.airteltigo {
    background: rgba(0, 102, 204, 0.2);
    color: #0b4f94;
}
.network-chip.telecel {
    background: rgba(220, 38, 38, 0.2);
    color: #9a1c1c;
}

/* Responsive Tables */
@media (max-width: 768px) {
    .table-wrap {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .table-wrap table {
        display: table;
        min-width: 560px;
    }

    .table-wrap .table-cards {
        display: none;
    }

    /* Optional card layout for views that opt in */
    .table-wrap.table-cards-enabled table {
        display: none;
    }

    .table-wrap.table-cards-enabled .table-cards {
        display: block;
    }

    .table-wrap.table-cards-enabled .table-card {
        background: white;
        border-radius: 12px;
        padding: 1rem;
        margin-bottom: 1rem;
        box-shadow: var(--shadow-sm);
        border-left: 4px solid var(--color-primary);
    }

    .table-wrap.table-cards-enabled .table-card-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 0.75rem;
        padding-bottom: 0.75rem;
        border-bottom: 1px solid var(--color-border);
    }

    .table-wrap.table-cards-enabled .table-card-header strong {
        font-size: 1.1rem;
        color: var(--color-text);
    }

    .table-wrap.table-cards-enabled .table-card-body {
        display: grid;
        gap: 0.5rem;
    }

    .table-wrap.table-cards-enabled .table-card-row {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0.4rem 0;
    }

    .table-wrap.table-cards-enabled .table-card-label {
        font-weight: 600;
        color: var(--color-muted);
        font-size: 0.875rem;
    }

    .table-wrap.table-cards-enabled .table-card-value {
        color: var(--color-text);
        font-weight: 500;
    }
}

/* Hide card layout on desktop */
@media (min-width: 769px) {
    .table-cards {
        display: none;
    }
}

/* Responsive */
@media (max-width: 900px) {
    .header-inner {
        flex-wrap: wrap;
    }

    .nav-toggle {
        display: block;
        cursor: pointer;
    }

    .app-nav {
        width: 100%;
        display: none;
    }

    .app-nav.is-open {
        display: block;
    }

    .app-nav ul {
        flex-direction: column;
        align-items: flex-start;
        padding: 1rem 0;
    }

    .app-nav .dropdown-menu {
        position: static;
        box-shadow: none;
        background: rgba(16, 185, 129, 0.05);
        margin-top: 0.5rem;
    }

    .app-nav .dropdown.is-open .dropdown-menu {
        display: block;
    }

    .hero {
        padding: 2.5rem 1.8rem;
    }

    th, td {
        white-space: nowrap;
    }

    .section-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .stats-strip {
        width: 100%;
    }

    .stat-pill {
        flex: 1 1 100%;
        min-width: 100%;
    }
}

@media (max-width: 600px) {
    .hero-buttons {
        flex-direction: column;
        align-items: stretch;
    }

    .hero-buttons .btn {
        width: 100%;
    }

    .copy-field {
        flex-direction: column;
        align-items: flex-start;
    }

    .copy-field span {
        font-size: 0.85rem;
        word-break: break-all;
    }

    .form-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .form-actions .btn {
        width: 100%;
    }

    .btn {
        padding: 0.85rem 1.2rem;
        font-size: 0.95rem;
    }

    .grid.two,
    .grid.three {
        grid-template-columns: 1fr;
    }

    .panel {
        padding: 1.25rem;
    }

    .data-card .value {
        font-size: 1.75rem;
    }
}
