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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: #0b0f19;
    color: #cbd5e1;
    line-height: 1.6;
}

/* ── Header ── */
header {
    background: linear-gradient(180deg, #111827 0%, #0f172a 100%);
    padding: 0.75rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #1e293b;
    position: sticky;
    top: 0;
    z-index: 10;
}

header h1 {
    font-size: 1.1rem;
    font-weight: 600;
    color: #f8fafc;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

header h1::before {
    content: "";
    display: inline-block;
    width: 8px;
    height: 8px;
    background: #22c55e;
    border-radius: 50%;
    box-shadow: 0 0 8px #22c55e66;
}

#user-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

#user-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid #334155;
}

#user-login {
    font-size: 0.8rem;
    color: #94a3b8;
    font-weight: 500;
}

/* ── Layout ── */
main {
    max-width: 1100px;
    margin: 1.5rem auto;
    padding: 0 1rem;
}

#dashboard-section {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 1rem;
}

@media (max-width: 768px) {
    main {
        margin: 0.75rem auto;
        padding: 0 0.5rem;
    }

    #dashboard-section {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }

    header {
        padding: 0.6rem 0.75rem;
    }

    header h1 {
        font-size: 1rem;
    }

    #user-login {
        display: none;
    }

    .card {
        padding: 1rem;
        border-radius: 10px;
    }

    .card h2 {
        font-size: 0.85rem;
        margin-bottom: 0.75rem;
    }

    .badge-list {
        gap: 0.35rem;
        margin-bottom: 0.75rem;
    }

    .badge {
        font-size: 0.75rem;
        padding: 0.25rem 0.5rem;
    }

    .form-row {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .form-row input[type="number"],
    .form-row select {
        flex: 1;
        min-width: 80px;
        width: auto;
    }

    .form-row input[type="text"] {
        width: 100%;
        flex: none;
    }

    .form-row .btn {
        flex: 1;
        min-width: 100px;
    }

    .btn {
        height: 36px;
        font-size: 0.8rem;
        padding: 0 0.75rem;
    }

    table {
        font-size: 0.8rem;
    }

    th, td {
        padding: 0.45rem 0.5rem;
    }

    #clients-table th:nth-child(2),
    #clients-table td:nth-child(2) {
        max-width: 90px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .center {
        margin: 3rem auto;
        padding: 1.5rem;
        max-width: 100%;
    }

    .center h2 {
        font-size: 1.1rem;
    }
}

.sidebar {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    align-items: flex-start;
}

.sidebar > .card {
    width: 100%;
}

.content {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* ── Cards ── */
.card {
    background: #111827;
    border: 1px solid #1e293b;
    border-radius: 12px;
    padding: 1.25rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.card:hover {
    border-color: #334155;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}

.card h2 {
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: #f8fafc;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.card h2::before {
    content: "";
    display: block;
    width: 3px;
    height: 16px;
    background: #3b82f6;
    border-radius: 2px;
}

/* ── Badges / Info Rows ── */
.badge-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.35rem 0.75rem;
    background: #0f172a;
    border: 1px solid #334155;
    border-radius: 6px;
    font-size: 0.8rem;
}

.badge .label {
    color: #94a3b8;
}

.badge .value {
    font-family: "SFMono-Regular", Consolas, monospace;
    color: #f8fafc;
    font-weight: 600;
}

/* ── Forms ── */
.form-row {
    display: flex;
    gap: 0.5rem;
    align-items: stretch;
}

.form-row input,
.form-row select {
    background: #0b0f19;
    border: 1px solid #334155;
    color: #e2e8f0;
    padding: 0.5rem 0.75rem;
    border-radius: 8px;
    font-size: 0.875rem;
    height: 38px;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.form-row input:focus,
.form-row select:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.form-row input[type="number"] {
    width: 100px;
    flex-shrink: 0;
}

.form-row input[type="text"] {
    flex: 1;
    min-width: 120px;
}

.port-row {
    gap: 0.5rem;
}

.port-row input[type="number"] {
    flex: 1;
    min-width: 120px;
    width: auto;
}

.port-protocol {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 0.75rem;
    height: 38px;
    background: #0f172a;
    border: 1px solid #334155;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 600;
    color: #3b82f6;
    font-family: "SFMono-Regular", Consolas, monospace;
    white-space: nowrap;
    user-select: none;
}

@media (max-width: 768px) {
    .port-protocol {
        height: 36px;
        font-size: 0.8rem;
    }

    .port-row input[type="number"] {
        min-width: 80px;
    }
}

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    padding: 0 1rem;
    border-radius: 8px;
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
    border: none;
    cursor: pointer;
    height: 38px;
    white-space: nowrap;
    transition: background 0.15s, transform 0.05s;
}

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

.btn-primary {
    background: #2563eb;
    color: #fff;
}

.btn-primary:hover {
    background: #1d4ed8;
}

.btn-secondary {
    background: #1e293b;
    color: #cbd5e1;
    border: 1px solid #334155;
}

.btn-secondary:hover {
    background: #334155;
}

.btn-danger {
    background: transparent;
    color: #f87171;
    border: 1px solid #7f1d1d;
    padding: 0 0.6rem;
    height: 28px;
    font-size: 0.75rem;
}

.btn-danger:hover {
    background: #7f1d1d;
    color: #fff;
}

/* ── Status ── */
.status {
    font-size: 0.8rem;
    margin-top: 0.5rem;
    min-height: 1.25rem;
}

.status.success {
    color: #4ade80;
}

.status.error {
    color: #f87171;
}

/* ── Tables ── */
.table-wrap {
    overflow-x: auto;
    border-radius: 8px;
    border: 1px solid #1e293b;
    margin-top: 0.75rem;
}

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

th, td {
    text-align: left;
    padding: 0.6rem 0.75rem;
    border-bottom: 1px solid #1e293b;
}

th {
    background: #0f172a;
    color: #94a3b8;
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    white-space: nowrap;
}

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

tr:hover td {
    background: #0f172a;
}

td:last-child {
    text-align: right;
}

/* ── Client List ── */
.client-list {
    max-height: 240px;
    overflow-y: auto;
    margin-top: 0.5rem;
}

.client-list .client-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0.25rem;
    border-bottom: 1px solid #1e293b;
    font-size: 0.85rem;
}

.client-list .client-item:last-child {
    border-bottom: none;
}

.client-list .client-item span:first-child {
    font-weight: 500;
    color: #e2e8f0;
}

.client-list .client-item span:last-child {
    color: #64748b;
    font-size: 0.75rem;
}

/* ── Login Section ── */
.login-card {
    max-width: 420px;
    margin: 6rem auto;
    background: #111827;
    border: 1px solid #1e293b;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 10px 40px rgba(0,0,0,0.4);
}

.login-accent {
    height: 4px;
    background: linear-gradient(90deg, #3b82f6 0%, #8b5cf6 50%, #22c55e 100%);
}

.login-body {
    padding: 2.5rem;
    text-align: center;
}

.login-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 64px;
    height: 64px;
    background: #0f172a;
    border: 1px solid #1e293b;
    border-radius: 16px;
    margin-bottom: 1.25rem;
    color: #3b82f6;
}

.login-title {
    font-size: 1.35rem;
    font-weight: 600;
    color: #f8fafc;
    margin-bottom: 0.25rem;
}

.login-subtitle {
    font-size: 0.9rem;
    color: #64748b;
    margin-bottom: 1.75rem;
}

.login-buttons {
    display: flex;
    flex-direction: row;
    gap: 0.75rem;
    justify-content: center;
}

.btn-login {
    flex: 1;
    height: 44px;
    font-size: 0.875rem;
    font-weight: 500;
    gap: 0.5rem;
    border-radius: 10px;
}

.login-btn-icon {
    flex-shrink: 0;
}

.btn-login-github {
    background: #24292f;
    color: #fff;
}

.btn-login-github:hover {
    background: #1a1e22;
}

.btn-login-feishu {
    background: #3370ff;
    color: #fff;
}

.btn-login-feishu:hover {
    background: #2965f1;
}

@media (max-width: 768px) {
    .login-card {
        margin: 2.5rem 0.5rem;
        border-radius: 12px;
    }

    .login-body {
        padding: 1.75rem;
    }

    .login-icon {
        width: 52px;
        height: 52px;
        border-radius: 12px;
    }

    .login-title {
        font-size: 1.15rem;
    }

    .login-subtitle {
        font-size: 0.85rem;
        margin-bottom: 1.25rem;
    }

    .login-buttons {
        flex-direction: column;
    }

    .btn-login {
        width: 100%;
        height: 40px;
        font-size: 0.8rem;
    }
}

/* ── Status Dots ── */
.status-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 0.4rem;
    vertical-align: middle;
}

.status-dot.online {
    background: #22c55e;
    box-shadow: 0 0 6px #22c55e66;
}

.status-dot.offline {
    background: #475569;
}

.muted {
    color: #64748b;
    font-size: 0.8rem;
}

/* ── Helpers ── */
.empty {
    color: #64748b;
    font-size: 0.85rem;
    font-style: italic;
    text-align: center;
    padding: 1.5rem 0;
}

.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }

.hidden {
    display: none !important;
}

form.admin-only {
    display: none;
}

.is-admin form.admin-only {
    display: block;
}
