* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 14px;
    color: #222;
    background: #f5f7fa;
    -webkit-text-size-adjust: 100%;
}

.app-header {
    --header-fg: #f4f8fc;
    --header-muted: rgba(244, 248, 252, 0.72);
    position: sticky;
    top: 0;
    z-index: 40;
    color: var(--header-fg);
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.08) 0%, transparent 42%),
        linear-gradient(120deg, #163a5c 0%, #1f4e79 48%, #2563a0 100%);
    border-bottom: 1px solid rgba(0, 0, 0, 0.18);
    box-shadow: 0 8px 24px rgba(22, 58, 92, 0.18);
    padding: 12px 20px;
    padding-top: max(12px, env(safe-area-inset-top));
}

.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    max-width: 1100px;
    margin: 0 auto;
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    color: inherit;
    text-decoration: none;
}

.header-brand:hover .header-title {
    opacity: 0.92;
}

.header-mark {
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    width: 40px;
    height: 40px;
    border-radius: 12px;
    color: #fff;
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.18);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18);
}

.header-brand-text {
    display: flex;
    flex-direction: column;
    gap: 1px;
    min-width: 0;
}

.header-title {
    margin: 0;
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.03em;
    line-height: 1.15;
}

.header-tagline {
    font-size: 11px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--header-muted);
    line-height: 1.2;
}

.header-meta {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 0 0 auto;
}

.header-user {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    max-width: 180px;
    padding: 4px 10px 4px 4px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.14);
}

.header-avatar {
    display: grid;
    place-items: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    flex: 0 0 auto;
    font-size: 12px;
    font-weight: 700;
    color: #163a5c;
    background: #e8f0f8;
}

.header-user-name {
    font-size: 13px;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.header-logout {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 14px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.28);
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    text-decoration: none;
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.header-logout:hover {
    background: rgba(255, 255, 255, 0.16);
    border-color: rgba(255, 255, 255, 0.42);
}

.header-logout:active {
    background: rgba(255, 255, 255, 0.22);
}

main {
    max-width: 1100px;
    margin: 20px auto;
    padding: 0 16px 40px;
}

.card {
    background: #fff;
    border: 1px solid #d8dee6;
    border-radius: 6px;
    padding: 16px;
    margin-bottom: 16px;
}

.alert {
    padding: 12px 14px;
    border-radius: 4px;
    margin-bottom: 16px;
}

.alert-error {
    background: #fdecea;
    border: 1px solid #f5c2c0;
    color: #8a1f17;
}

.alert-success {
    background: #e8f6ee;
    border: 1px solid #b7e0c5;
    color: #1f6b3b;
}

.alert-info {
    background: #eef4fb;
    border: 1px solid #c5d9f2;
    color: #1f4e79;
}

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

th,
td {
    border-bottom: 1px solid #e5e9ef;
    padding: 10px 8px;
    text-align: left;
}

th {
    background: #f0f4f8;
    font-size: 13px;
}

.form-grid {
    display: grid;
    grid-template-columns: 180px 1fr;
    gap: 10px 16px;
    max-width: 640px;
}

.form-grid label {
    align-self: center;
    font-weight: bold;
}

.form-grid input[readonly] {
    background: #f3f5f7;
}

input[type="text"],
input[type="password"] {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #c9d1da;
    border-radius: 4px;
    font-size: 16px; /* avoid iOS zoom */
}

.actions {
    margin-top: 16px;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

button,
.btn {
    display: inline-block;
    padding: 8px 14px;
    border: 1px solid #1f4e79;
    border-radius: 4px;
    background: #1f4e79;
    color: #fff;
    text-decoration: none;
    cursor: pointer;
    font-size: 14px;
    text-align: center;
}

button.secondary,
.btn.secondary {
    background: #fff;
    color: #1f4e79;
}

button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-block {
    display: block;
    width: 100%;
}

.steps {
    list-style: none;
    padding: 0;
    margin: 0;
}

.steps li {
    padding: 6px 0;
    border-bottom: 1px solid #edf1f5;
}

.steps .ok {
    color: #1f6b3b;
}

.steps .fail {
    color: #8a1f17;
}

.muted {
    color: #667788;
    font-size: 12px;
}

.profile-defaults {
    margin-top: 20px;
    padding: 14px 16px;
    background: #f0f4f8;
    border: 1px solid #d8e0ea;
    border-radius: 6px;
}

.profile-defaults h3 {
    margin: 0 0 10px;
    font-size: 14px;
}

.profile-defaults dl {
    margin: 0;
    display: grid;
    grid-template-columns: 220px 1fr;
    gap: 6px 12px;
}

.profile-defaults dt {
    margin: 0;
    color: #555;
    font-weight: 600;
}

.profile-defaults dd {
    margin: 0;
    font-family: Consolas, Monaco, monospace;
    word-break: break-word;
}

.input-with-btn {
    display: flex;
    gap: 8px;
    align-items: center;
}

.input-with-btn input {
    flex: 1;
}

.billing-status {
    grid-column: 2;
    min-height: 1.2em;
}

.billing-status.ok {
    color: #1b7a3d;
}

.billing-status.error {
    color: #8a1f17;
}

.row-actions {
    white-space: nowrap;
}

.row-actions .btn {
    margin-right: 4px;
}

.result-dl {
    display: grid;
    grid-template-columns: 180px 1fr;
    gap: 8px 16px;
    margin: 0 0 16px;
}

.result-dl dt {
    margin: 0;
    color: #555;
    font-weight: 600;
}

.result-dl dd {
    margin: 0;
    word-break: break-word;
}

.ont-sn-banner {
    margin: 0 0 12px;
}

.ont-sn-banner code {
    font-size: 15px;
    word-break: break-all;
}

/* Login */
.page-login {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    background:
        radial-gradient(ellipse at 20% 0%, #d6e4f5 0%, transparent 55%),
        radial-gradient(ellipse at 80% 100%, #c5d9ef 0%, transparent 50%),
        #e8eef5;
    padding: 24px 16px;
}

.login-wrap {
    width: 100%;
    max-width: 400px;
    margin: 0;
    padding: 0;
}

.login-card {
    background: #fff;
    border: 1px solid #d0dae6;
    border-radius: 10px;
    padding: 28px 24px 24px;
    box-shadow: 0 8px 28px rgba(31, 78, 121, 0.08);
}

.login-brand {
    font-size: 28px;
    font-weight: 700;
    color: #1f4e79;
    letter-spacing: -0.02em;
    margin-bottom: 4px;
}

.login-card h1 {
    margin: 0 0 4px;
    font-size: 18px;
    font-weight: 600;
}

.login-card .muted {
    margin: 0 0 18px;
}

.login-card label {
    display: block;
    font-weight: 600;
    margin: 0 0 6px;
}

.login-card input[type="text"],
.login-card input[type="password"] {
    margin-bottom: 14px;
    padding: 12px 12px;
}

.login-card .btn {
    margin-top: 6px;
    padding: 12px 14px;
    font-size: 16px;
}

.login-card .alert {
    margin-bottom: 14px;
}

/* Mobile ONT cards — hidden on desktop */
.mobile-only {
    display: none;
}

.ont-cards {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.ont-card {
    border: 1px solid #d8dee6;
    border-radius: 8px;
    padding: 14px;
    background: #fafbfc;
}

.ont-card-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    color: #667788;
    font-size: 13px;
}

.ont-card-fsp {
    font-family: Consolas, Monaco, monospace;
    font-weight: 600;
    color: #1f4e79;
}

.ont-card-sn {
    font-family: Consolas, Monaco, monospace;
    font-size: 15px;
    font-weight: 600;
    word-break: break-all;
    margin-bottom: 8px;
}

.ont-card-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 12px;
    font-size: 12px;
    color: #667788;
    margin-bottom: 12px;
}

.ont-card-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.ont-card-actions .btn {
    padding: 12px 14px;
    font-size: 15px;
}

@media (max-width: 720px) {
    .app-header {
        padding: 10px 12px;
        padding-top: max(10px, env(safe-area-inset-top));
    }

    .header-inner {
        gap: 10px;
    }

    .header-brand {
        gap: 10px;
    }

    .header-mark {
        width: 36px;
        height: 36px;
        border-radius: 10px;
    }

    .header-mark svg {
        width: 24px;
        height: 24px;
    }

    .header-title {
        font-size: 18px;
    }

    .header-tagline {
        font-size: 10px;
    }

    .header-meta {
        gap: 8px;
    }

    .header-user {
        max-width: none;
        padding: 3px;
        background: rgba(255, 255, 255, 0.12);
    }

    .header-user-name {
        display: none;
    }

    .header-avatar {
        width: 32px;
        height: 32px;
        font-size: 13px;
    }

    .header-logout {
        padding: 10px 12px;
        font-size: 13px;
        min-height: 40px;
    }

    main {
        margin: 12px auto;
        padding: 0 12px 32px;
    }

    .card {
        padding: 14px;
        border-radius: 8px;
    }

    .desktop-table {
        display: none;
    }

    .mobile-only {
        display: block;
    }

    .form-grid,
    .profile-defaults dl,
    .result-dl {
        grid-template-columns: 1fr;
    }

    .form-grid label {
        align-self: start;
        margin-top: 4px;
    }

    .billing-status {
        grid-column: 1;
    }

    .input-with-btn {
        flex-direction: column;
        align-items: stretch;
    }

    .input-with-btn .btn {
        width: 100%;
        padding: 12px 14px;
    }

    .actions {
        flex-direction: column;
    }

    .btn-block-mobile,
    .actions .btn,
    .actions button {
        display: block;
        width: 100%;
        padding: 12px 14px;
        font-size: 15px;
    }

    input[type="text"],
    input[type="password"] {
        padding: 12px;
    }
}
